文章目录

  • 前言
  • A Comparing Two Long Integers\text{A Comparing Two Long Integers}A Comparing Two Long Integers
    • Description\text{Description}Description
    • Solution\text{Solution}Solution
    • Code\text{Code}Code
  • B Dinner with Emma\text{B Dinner with Emma}B Dinner with Emma
    • Descripion\text{Descripion}Descripion
    • Solution\text{Solution}Solution
    • Code\text{Code}Code
  • C The Labyrinth\text{C The Labyrinth}C The Labyrinth
    • Descripion\text{Descripion}Descripion
    • Solution\text{Solution}Solution
    • Code\text{Code}Code
  • D Longest k-Good Segment\text{D Longest k-Good Segment}D Longest k-Good Segment
    • Descripion\text{Descripion}Descripion
    • Solution\text{Solution}Solution
    • Code\text{Code}Code
  • E Sum of Remainders\text{E Sum of Remainders}E Sum of Remainders
    • Descripion\text{Descripion}Descripion
    • Solution\text{Solution}Solution
    • Code\text{Code}Code
  • F Expensive Strings\text{F Expensive Strings}F Expensive Strings
    • Descripion\text{Descripion}Descripion
    • Solution\text{Solution}Solution
      • updata on 2022.1.1
    • Code\text{Code}Code

前言

比较简单的一场比赛。
ABC是水题。
D简单双指针。
E整除分块板子题。
F广义SAM板子,但是由于我太蒻不会,所以只能拿SA硬做qwq

A Comparing Two Long Integers\text{A Comparing Two Long Integers}A Comparing Two Long Integers

Description\text{Description}Description

比较两个不超过 100000010000001000000 位的正整数的大小。正整数可能有前导零。前面那个比后面那个大输出 >,比后面那个小输出 <,两个一样大输出 =

Solution\text{Solution}Solution

python爪把
读进来后去掉前导零再判断即可。

Code\text{Code}Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define debug(...) fprintf(stderr,__VA_ARGS__)
inline ll read(){ll x(0),f(1);char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}while(isdigit(c)){x=(x<<1)+(x<<3)+c-'0';c=getchar();}return x*f;
}const int N=1e6+100;
const int M=505;char a[N],b[N];
int n,m,q,tim;signed main(){#ifndef ONLINE_JUDGEfreopen("a.in","r",stdin);freopen("a.out","w",stdout);
#endifscanf(" %s %s",a+1,b+1);n=strlen(a+1);m=strlen(b+1);int pa=1,pb=1;while(pa<=n&&a[pa]=='0') pa++;while(pb<=m&&b[pb]=='0') pb++;if(n-pa+1!=m-pb+1){if(n-pa+1<m-pb+1) putchar('<');else putchar('>');return 0;}while(pa<=n){if(a[pa]!=b[pb]){if(a[pa]<b[pb]) putchar('<');else putchar('>');return 0;}++pa;++pb;}putchar('=');return 0;
}
/**/

B Dinner with Emma\text{B Dinner with Emma}B Dinner with Emma

Descripion\text{Descripion}Descripion

杰克决定邀请艾玛出去吃饭。杰克是个谦虚的学生,他不想去昂贵的餐馆。可艾玛是个品味很高的女孩,她更喜欢高端的餐馆。

Munhatan由 nnn 条街道和 mmm 条巷子组成。在每一条街道和小巷的交叉口都有一家餐馆。街道用 111 到 nnn 的整数来编号,巷子用从 111 到 mmm 的整数来编号。在第 iii 街和第 jjj 巷交叉口的餐馆里吃饭的费用是 Ci,jC_{i,j}Ci,j​。

杰克和艾玛决定按以下方式选择餐馆。先是艾玛选了在哪条街上吃饭,然后杰克选了巷子。艾玛和杰克做出了最佳的选择:艾玛想最大限度地提高晚餐的成本,杰克想把它降到最低。而艾玛知道杰克的想法。告诉这对恋人晚餐最终的费用。
n,m≤100n,m\le 100n,m≤100

Solution\text{Solution}Solution

tag:min-max 容斥。
找到每一行最小值的最大值即可。

Code\text{Code}Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define debug(...) fprintf(stderr,__VA_ARGS__)
inline ll read(){ll x(0),f(1);char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}while(isdigit(c)){x=(x<<1)+(x<<3)+c-'0';c=getchar();}return x*f;
}const int N=1e6+100;
const int M=505;int n,m;
int a[105][105];signed main(){#ifndef ONLINE_JUDGEfreopen("a.in","r",stdin);freopen("a.out","w",stdout);
#endifn=read();m=read();int ans=0;for(int i=1;i<=n;i++){int mn(2e9);for(int j=1;j<=m;j++) a[i][j]=read(),mn=min(mn,a[i][j]);ans=max(ans,mn);}printf("%d\n",ans);return 0;
}
/**/

C The Labyrinth\text{C The Labyrinth}C The Labyrinth

Descripion\text{Descripion}Descripion

给你一张图,* 表示墙,.表示空地,问每个 * 周围的联通快中 . 的数量和模 101010 的结果,属于同一个联通快的只计算一次。
n,m≤1000n,m\le 1000n,m≤1000

Solution\text{Solution}Solution

bfs 一遍求出每个连通块的大小,求出每个点四周的大小之和即可。
可以利用 set 方便去重。

Code\text{Code}Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define debug(...) fprintf(stderr,__VA_ARGS__)
inline ll read(){ll x(0),f(1);char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}while(isdigit(c)){x=(x<<1)+(x<<3)+c-'0';c=getchar();}return x*f;
}const int N=1050;int n,m;
int a[N][N],bel[N][N],siz[N*N],tot,vis[N][N];
int dx[5]={0,0,-1,0,1},dy[5]={0,-1,0,1,0};
inline bool exi(int x,int y){return x>=1&&x<=n&&y>=1&&y<=m;}
void bfs(int x,int y,int f){vis[x][y]=1;bel[x][y]=f;siz[f]++;for(int i=1;i<=4;i++){int xx=x+dx[i],yy=y+dy[i];if(vis[xx][yy]||a[xx][yy]||!exi(xx,yy)) continue;bfs(xx,yy,f);}return;
}
set<int>s;signed main(){#ifndef ONLINE_JUDGEfreopen("a.in","r",stdin);freopen("a.out","w",stdout);
#endifn=read();m=read();for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){char c;scanf(" %c",&c);a[i][j]=(c=='*');}}for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){if(a[i][j]||vis[i][j]) continue;++tot;bfs(i,j,tot);}}for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){if(!a[i][j]){putchar('.');continue;}for(int k=1;k<=4;k++){int x=i+dx[k],y=j+dy[k];if(a[x][y]||!exi(x,y)) continue;s.insert(bel[x][y]);}int ans(1);for(int x:s) ans+=siz[x];printf("%d",ans%10);s.clear();}putchar('\n');}return 0;
}
/**/

D Longest k-Good Segment\text{D Longest k-Good Segment}D Longest k-Good Segment

Descripion\text{Descripion}Descripion

给定一个包含 nnn 个整数的序列aaa,0≤ai≤1060\le a_i \le 10^60≤ai​≤106 ,询问不重复数字个数 ≤k\le k≤k 的最长区间的左右端点。如果有多解输出任意一组。
n≤5×105n\le 5\times10^5n≤5×105

Solution\text{Solution}Solution

开一个桶维护各种数字的数量维护当前区间不重复数字个数,双指针取区间最大值即可。

Code\text{Code}Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define debug(...) fprintf(stderr,__VA_ARGS__)
inline ll read(){ll x(0),f(1);char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}while(isdigit(c)){x=(x<<1)+(x<<3)+c-'0';c=getchar();}return x*f;
}const int N=1e6+100;int n,m;
int a[N],bac[N],now,ans,L,R;signed main(){#ifndef ONLINE_JUDGEfreopen("a.in","r",stdin);freopen("a.out","w",stdout);
#endifn=read();m=read();for(int i=1;i<=n;i++) a[i]=read();int l=1,r=0;while(r<n){now+=(++bac[a[++r]]==1);while(now>m) now-=(--bac[a[l++]]==0);if(r-l+1>ans){ans=r-l+1;L=l;R=r;}}printf("%d %d\n",L,R);return 0;
}
/**/

E Sum of Remainders\text{E Sum of Remainders}E Sum of Remainders

Descripion\text{Descripion}Descripion

计算以下式子的和:nmod1+nmod2+nmod3+⋯+nmodmn \bmod 1 + n \bmod 2 + n \bmod 3 + \dots + n \bmod mnmod1+nmod2+nmod3+⋯+nmodm。由于结果可能很大,你需要输出其对 109+710^9+7109+7 取模的结果。
n,m≤1013n,m\le 10^13n,m≤1013

Solution\text{Solution}Solution

式子可以写成:
∑i=1mn−⌊ni⌋×i\sum_{i=1}^mn-\lfloor\frac{n}{i}\rfloor\times ii=1∑m​n−⌊in​⌋×i
直接上整除分块即可。

Code\text{Code}Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define debug(...) fprintf(stderr,__VA_ARGS__)
inline ll read(){ll x(0),f(1);char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}while(isdigit(c)){x=(x<<1)+(x<<3)+c-'0';c=getchar();}return x*f;
}const int N=1e6+100;
const int mod=1e9+7;ll n,m,ans;
ll ksm(ll x,ll k){ll res(1);while(k){if(k&1) res=res*x%mod;x=x*x%mod;k>>=1;}return res;
}inline ll calc(ll l,ll r){return ((l+r)%mod)*((r-l+1)%mod)%mod*500000004%mod;}
signed main(){#ifndef ONLINE_JUDGEfreopen("a.in","r",stdin);freopen("a.out","w",stdout);
#endifn=read();m=read();ans=(m%mod)*(n%mod)%mod;for(ll l=1,r;l<=min(n,m);l=r+1){r=min(m,n/(n/l));ll o=n/l%mod;ans=(ans+mod-o*calc(l,r)%mod)%mod;//printf("(%lld %lld) o=%lld\n",l,r,o);}printf("%lld\n",ans);return 0;
}
/**/

F Expensive Strings\text{F Expensive Strings}F Expensive Strings

Descripion\text{Descripion}Descripion

给你nnn个字符串。每个字符串的成本都是cic_ici​。
定义字符串的函数,其中f(s)=∑i=1nci⋅ps,i⋅∣s∣f(s)=\sum_{i=1}^n c_i \cdot p_{s,i} \cdot |s|f(s)=∑i=1n​ci​⋅ps,i​⋅∣s∣,ps,ip_{s,i}ps,i​是sss在tit_iti​中出现的次数,∣s∣|s|∣s∣是字符串sss的长度。求所有字符串函数f(s)f(s)f(s)的最大值

注意字符串sss不一定是ttt中的某个字符串。

Solution\text{Solution}Solution

据说用广义 SAM 的话就是板子了。
但是我并不会qwq。
考虑使用 SA。

先把所有串连起来,中间夹一些泥巴。
后缀排序后先求出 height⁡\operatorname{height}height。
每个后缀的价值定义为其所属串的价值,并求出价值的前缀和。
然后如果选择区间 [l,r][l,r][l,r] 的所有字符串,那么选择的价值就是:
(min⁡i=l+1rheight⁡i)×sumr−suml−1(\min_{i=l+1}^{r}\operatorname{height}_i )\times sum_r-sum_{l-1}(i=l+1minr​heighti​)×sumr​−suml−1​
因为贪心的考虑一定使这个串最长。
那么我们悬线法求出每个 heightheightheight 作为最小值的有效区间,扫一遍取最大值即可。
但这样是无法考虑这个串只出现一遍的情况的,这个串一定就是某个串本身,map 暴力判一下即可。

updata on 2022.1.1

感谢 @望月Asta 提供的hack,上面的算法会在下面这个数据出错:

2
od
iod
2 -1
ans:2

原因是之前 map 判整串判的过于草率了,正确的做法应该是记录每个串开头的位置 plplpl,然后看看 heightplheight_{pl}heightpl​ 和 heightpl+1height_{pl+1}heightpl+1​ 是否都小于该串长度。

但是我代码不想改了,哈哈。

Code\text{Code}Code

# include <bits/stdc++.h>
# include <bits/extc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define debug(...) fprintf(stderr,__VA_ARGS__)
inline ll read(){ll x(0),f(1);char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}while(isdigit(c)){x=(x<<1)+(x<<3)+c-'0';c=getchar();}return x*f;
}const int N=1e6+100;
const int mod=1e9+7;int n,m,tot;
int sa[N],rk[N],id[N],oldrk[N],bel[N],len[N],p,cnt[1234567],a[N],l[N],r[N];
ll h[N],c[N];
void calc(){for(int k=0,i=1;i<=n;i++){if(k) --k;while(a[i+k]==a[sa[rk[i]-1]+k]) ++k;h[rk[i]]=k;}return;
}
bool jd[N];
ll ans,sum[N];
string s[N];
map<string,int>mp;signed main(){#ifndef ONLINE_JUDGEfreopen("a.in","r",stdin);freopen("a.out","w",stdout);
#endifm=read();for(int i=1;i<=m;i++){cin>>s[i];n=s[i].size();for(int j=0;j<n;j++) a[++tot]=s[i][j]-'a'+1,bel[tot]=i;a[++tot]=i+26;bel[tot]=i;jd[tot]=1;len[i]=n;mp[s[i]]++;}for(int i=1;i<=m;i++) c[i]=read();//ans=max(ans,c[i]*len[i]);for(int i=1;i<=m;i++) if(mp[s[i]]==1) ans=max(ans,c[i]*len[i]);n=tot;m+=26;for(int i=1;i<=n;i++) ++cnt[rk[i]=a[i]];for(int i=1;i<=m;i++) cnt[i]+=cnt[i-1];for(int i=n;i>=1;i--) sa[cnt[rk[i]]--]=i;for(int w=1;;w<<=1){p=0;for(int i=n;i>n-w;i--) id[++p]=i;for(int i=1;i<=n;i++){if(sa[i]>w) id[++p]=sa[i]-w;}memset(cnt,0,sizeof(cnt));memcpy(oldrk,rk,sizeof(rk));//for(int i=1;i<=n;i++) printf("%d ",id[i]);//putchar('\n');for(int i=n;i>=1;i--) ++cnt[rk[id[i]]];for(int i=1;i<=m;i++) cnt[i]+=cnt[i-1];for(int i=n;i>=1;i--) sa[cnt[rk[id[i]]]--]=id[i];p=0;for(int i=1;i<=n;i++){if(oldrk[sa[i]]==oldrk[sa[i-1]]&&oldrk[sa[i]+w]==oldrk[sa[i-1]+w]) rk[sa[i]]=p;else rk[sa[i]]=++p;}m=p;//for(int i=1;i<=n;i++) printf("%d ",sa[i]);//putchar('\n');if(m==n) break;}calc();for(int i=1;i<=n;i++) sum[i]=sum[i-1]+c[bel[sa[i]]];  for(int i=1;i<=n;i++){l[i]=i;//printf("i=%d\n",i);while(l[i]>1&&h[l[i]-1]>=h[i]) l[i]=l[l[i]-1];}for(int i=n;i>=1;i--){r[i]=i;while(r[i]<n&&h[r[i]+1]>=h[i]) r[i]=r[r[i]+1];}//for(int i=1;i<=n;i++){//printf("i=%d pl=%d h=%lld l=%d r=%d sum=%lld tmp=%lld\n",//    i,sa[i],h[i],l[i],r[i],sum[i],h[i]*(sum[r[i]]-sum[max(0,l[i]-2)]));//}for(int i=2;i<=n;i++){   ans=max(ans,h[i]*(sum[r[i]]-sum[max(0,l[i]-2)]));}printf("%lld\n",ans);return 0;
}
/*
5
bbbab
bbaab
bbbaa
bbabb
babba
3 -9 8 -3 9 */

CodeForces616:Educational Round 5相关推荐

  1. [Educational Round 5][Codeforces 616F. Expensive Strings]

    这题调得我心疲力竭...Educational Round 5就过一段时间再发了_(:з」∠)_ 先后找了三份AC代码对拍,结果有两份都会在某些数据上出点问题...这场的数据有点水啊_(:з」∠)_[ ...

  2. Codeforces Educational Round 5

    Codeforces Educational Round 5 通过数: 4 Standing: 196/4176 题目链接: http://codeforces.com/contest/616 A: ...

  3. Educational Round 66 题解

    作为橙名来水了一发-- 这次题目就比上次良心多了.7题有5题会做. 然而风格仍然很怪异--还是练少了? A 水题.不过一开始没注意细节挂了几发,罚时罚的真痛-- 明显是能除以 $k$ 就除以 $k$, ...

  4. Codeforces Educational round 58

    Ediv2 58 随手AK.jpg D 裸的虚树,在这里就不写了 E 傻逼贪心?这个题过的比$B$都多.jpg #include <cstdio> #include <algorit ...

  5. CF Educational Round 23 F.MEX Queries

    写了3小时 = =.这两天堕落了,昨天也刷了一晚上hihocoder比赛,还爆了零.之后得节制点了,好好准备考研.. 首先很容易想到 压缩数据 + 线段树 然后对于Pushdown真很难写..需要牵涉 ...

  6. educational round 前缀和_总结分析634个以re为前缀的单词得出了re为前缀组合单词意思规律

    学英语需要有耐心.恒心!本文稍长!本文的目的所在是让读者在一篇文章里可以理解634个re前缀的单词,更重要的是可以复习到对应的634个常见的基础单词. 看下面的动图,小球从高点回到底部,从底部回到高点 ...

  7. Educational Round 64 题解

    前言: 这场太难了--我一个紫名只打出两题--(虽说感觉的确发挥不够好) 一群蓝绿名的dalao好像只打了两题都能升分的样子-- 庆幸的是最后A出锅然后unr了>///< 写一波题解纪念这 ...

  8. Educational Round 26 C. Two Seals

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  9. CF Educational Round 57(1096) 比赛记录

    这里是链接 本来想带学弟飞的,结果自己先gg了... 外校高一大佬太强了orz,在我前面溜的飞起,还切了 F 哎,差一点就可以上紫名的,现在寄希望于 Good Bye 2018 了qwq 老年选手的手 ...

最新文章

  1. 究竟该不该“勃”!!!
  2. Matlab中pickic_法语「野餐」怎么写?不是picnic哦
  3. 【区块链基础知识系列】 第9课 一文诠释什么是DAG
  4. 大话数据结构:平衡二叉排序树
  5. Objective-C组合模式(Composite)
  6. vue动态切换css文件_vue实现样式之间的切换及vue动态样式的实现方法
  7. 年龄是计数还是计量_电子皮带秤是静态称重还是动态称重?
  8. Flex 3快速入门: 构建高级用户界面 添加拖放支持
  9. php 去掉后导字符,PHP去除字符串最后一个字符的三种方法实例
  10. [Jobdu] 题目1037:Powerful Calculator
  11. redis 入门笔记(一)
  12. Android ListView优化总结
  13. 《微观经济学》第一章经济学十大原理
  14. 无线桥接dns服务器未响应,小米路由器AX3600恢复出厂设置的方法
  15. 耗时5小时用纯HTML和CSS写成的博学谷
  16. Android Studio 如何查看Sqlite数据文件
  17. 校赛热身赛 Problem D. Unsolved Mystery
  18. CRYPTO进阶版:banana-princess
  19. 11.4 使用Markdown和Flask-PageDown:没有文本编辑框的问题
  20. 禁用键盘快捷键_如何在Windows中使用键盘快捷键临时禁用键盘

热门文章

  1. 视觉开发需要什么程度的数学_角度的概念在视觉上非常直观,但其数学定义并不是那么简单...
  2. flex布局_Flex布局,真香
  3. 计算机控制系统期末判断题,计算机控制系统期末试题.doc
  4. 蓝桥杯-长草-代码(BFS)
  5. 满汉楼(德鲁伊连接池+DBUtils+DAO+Mysql)保姆级别分析+代码实现
  6. oracle计算最大与最小之间数,oracle 分析函数
  7. ciclop读音,购机必备,15种 3D扫描 设备 优缺点汇总
  8. [Java基础]Lambda表达式练习
  9. [剑指offer]面试题1:赋值运算符函数
  10. LeetCode 617合并二叉树-简单