CodeForces616:Educational Round 5

前言

比较简单的一场比赛。
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 条巷子组成。在每一条街道和小巷的交叉口都有一家餐馆。街道用 111nnn 的整数来编号,巷子用从 111mmm 的整数来编号。在第 iii 街和第 jjj 巷交叉口的餐馆里吃饭的费用是 Ci,jC_{i,j}Ci,j

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

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,m1000

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 个整数的序列aaa0≤ai≤1060\le a_i \le 10^60ai106 ,询问不重复数字个数 ≤k\le kk 的最长区间的左右端点。如果有多解输出任意一组。
n≤5×105n\le 5\times10^5n5×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,m1013

Solution\text{Solution}Solution

式子可以写成:
∑i=1mn−⌊ni⌋×i\sum_{i=1}^mn-\lfloor\frac{n}{i}\rfloor\times ii=1mnin×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=1ncips,isps,ip_{s,i}ps,issstit_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+1minrheighti)×sumrsuml1
因为贪心的考虑一定使这个串最长。
那么我们悬线法求出每个 heightheightheight 作为最小值的有效区间,扫一遍取最大值即可。
但这样是无法考虑这个串只出现一遍的情况的,这个串一定就是某个串本身,map 暴力判一下即可。

updata on 2022.1.1

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

2
od
iod
2 -1
ans:2

原因是之前 map 判整串判的过于草率了,正确的做法应该是记录每个串开头的位置 plplpl,然后看看 heightplheight_{pl}heightplheightpl+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 */

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/317212.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

CF1534F2-Falling Sand (Hard Version)

正题 题目链接:https://www.luogu.com.cn/problem/CF1534F2 题目大意 有一个n∗mn*mn∗m个网格&#xff0c;有的网格上有沙子&#xff0c;一个沙子被刷新后会下落到底并且刷新沿途中四周四连通的沙子&#xff0c;你可以选择一些沙子手动刷新。 现在要求第iii列至少有aia_iai…

数据结构二之线段树Ⅱ——KiKi‘s K-Number,ball,The Child and Sequence,「雅礼集训 2017 Day1」市场,Atlantis

值域线段树势能线段树扫描线KiKis K-NumberballThe Child and Sequence「雅礼集训 2017 Day1」市场AtlantisKiKi’s K-Number HDU-2852 权值线段树维护插入删除很简单 对于查询大于xxx的第kkk个&#xff0c;可以不用二分&#xff0c;转化一下 先查小于等于xxx的个数cntcntc…

Codeforces Round #721 (Div. 2)

Codeforces Round #721 (Div. 2) 题号题目难度知识点AAnd Then There Were KBPalindrome Game (easy version)CPalindrome Game (hard version)DSequence Pair WeightEMEX TreeFPartition Game

解决Azure DevOps部署到Azure后.NET Core网站无法启动的问题

点击上方蓝字关注“汪宇杰博客”最近我遭遇了一个奇怪的问题。使用Azure DevOps配置CI/CD管线&#xff0c;自动部署到Azure App Service以后&#xff0c;.NET Core的网站竟然会启动失败。我们来看看如何解决这个问题。查找问题首先&#xff0c;幸好&#xff0c;这是个staging环…

CF1286E-Fedya the Potter Strikes Back【KMP,RMQ】

正题 题目链接:https://www.luogu.com.cn/problem/CF1286E 题目大意 定义一个字符串sss的权值为对于每个sL∼Rs1∼R−L1s_{L\sim R}s_{1\sim R-L1}sL∼R​s1∼R−L1​的区间&#xff0c;会产生min⁡iLRwi\min_{iL}^Rw_iminiLR​wi​的贡献。 现在开始时sss为空串&#xff0c…

模板:二维凸包(计算几何)

所谓凸包&#xff0c;就是一个凸出来的包 &#xff08;逃&#xff09; 前言 计算集合的第一课。 关键特征&#xff1a;周长最小。此时一定是凸包。 解析 定义 凸包&#xff1a;在平面上能包含所有给定点的最小凸多边形叫做凸包。 性质&#xff1a;凸包的周长是所有能包含给…

[AtCoder Beginner Contest 215] A-G题解

文章目录A - Your First JudgeB - log2(N)C - One More aab aba baaD - Coprime 2E - Chain ContestantF - Dist Max 2G - Colorful Candies 2atcoder题目链接 A - Your First Judge 签到题 #include <cstdio> #include <iostream> using namespace std; string…

Acwing 135 最大子序和

Acwing 135 最大子序和 题目&#xff1a; 输入一个长度为 n 的整数序列&#xff0c;从中找出一段长度不超过 m 的连续子序列&#xff0c;使得子序列中所有数的和最大。 题解&#xff1a; 我们把这个问题的集合分成n份&#xff0c;第k份表示以A[k]结尾的最大连续子序列是多少…

.net core自定义高性能的Web API服务网关

网关对于服务起到一个统一控制处理的作用&#xff0c;也便于客户端更好的调用&#xff1b;通过网关可以灵活地控制服务应用接口负载&#xff0c;故障迁移&#xff0c;安全控制&#xff0c;监控跟踪和日志处理等。由于网关在性能和可靠性上都要求非常严格&#xff0c;所以针对业…

微软宣布 Visual Studio 2019 将于4月2日正式发布

微软于去年发布了 Visual Studio 2019 预览版。今天&#xff0c;该公司宣布 Visual Studio 2019 正式版将于4月2日发布。微软在公告中表示&#xff1a;“欢迎加入我们在4月2号当天举办的 VS 2019 线上发布活动&#xff0c;这是一款更加现代化、创新且实用的生产力工具”。据悉&…

CF1427F-Boring Card Game【贪心】

正题 题目链接:https://www.luogu.com.cn/problem/CF1427F 题目大意 有一个1∼6n1\sim 6n1∼6n的序列&#xff0c;两个人轮流操作&#xff0c;每次取走连续的三个数字。 现在给出先手取走的数字集合&#xff0c;要求构造方案。 保证有解 1≤n≤2001\leq n\leq 2001≤n≤200…

模板:旋转卡壳(计算几何)

所谓旋转卡壳&#xff0c;就是旋转起来的卡壳 &#xff08;逃&#xff09; 前言 前置知识&#xff1a;凸包 个人感觉很像 two-pointers 算法。 能够在优秀的线性时间复杂度内完成总多求最值&#xff08;周长、面积…&#xff09;的神奇操作。 解析 给出情境&#xff1a; 给…

Acwing 1088.旅行问题

Acwing 1088.旅行问题 题目&#xff1a; 一个环形公路&#xff0c;由n个车站&#xff0c;每个站有若干升汽油&#xff08;有的站可能油量为零&#xff09;&#xff0c;每升油可以让汽车行驶一千米。 从某个车站出发&#xff0c;一直按顺时针&#xff08;或逆时针&#xff09;…

[AtCoder Regular Contest 125] A-F全题解

文章目录A - Dial UpB - SquaresC - LIS to Original SequenceD - Unique SubsequenceE - SnackF - Tree Degree Subset Sum网址链接A - Dial Up 签到题 特判一下有没有0/1在目标串中出现而没在原串出现 除了第一次0/1数字互换时&#xff0c;需要从a1a_1a1​左右找距离最近的…

DotNetty 实现 Modbus TCP 系列 (三) Codecs Handler

DotNetty 实现 Modbus TCP 系列 (一) 报文类DotNetty 实现 Modbus TCP 系列 (二) ModbusFunction 类图及继承举例DotNetty 作为一个半成品&#xff0c;我们不需要关注细节的实现&#xff0c;只需要关注自己的业务即可&#xff0c;所以最主要的就是处理 Codecs 和 Handler。所有…

loj#2788-「CEOI2015 Day1」管道【树上差分】

正题 题目链接:https://loj.ac/p/2788 题目大意 给出nnn个点mmm条边的一张图&#xff0c;求它的所有割边。 1≤n≤105,1≤m≤61061\leq n\leq 10^5,1\leq m\leq 6\times 10^61≤n≤105,1≤m≤6106&#xff0c;内存限制16MB 解题思路 我们存不下所有的边&#xff0c;但是nnn很…

Acwing -- 单调队列优化的DP问题

文章目录引入acwing154 滑动窗口应用135 最大子序和1088.旅行问题AcWing 1087. 修剪草坪28AcWing 1089. 烽火传递AcWing 1090. 绿色通道AcWing 1091. 理想的正方形引入 acwing154 滑动窗口 题目链接 题解 应用 闫氏最优化问题分析法 135 最大子序和 题目&#xff1a; 输入…

模板:半平面交(计算几何)

所谓半平面交&#xff0c;就是和“半平先生”当面交谈。顾名思义&#xff0c;这是一个源于日本的算法。 &#xff08;逃&#xff09; 前言 感觉应用很灵活的一个算法&#xff0c;一切有两个变量的线性规划问题都可以转化为半平面交。 有时可能要注意取等问题&#xff08;指射…

Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine)) A-F全题解

Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine)) 文章目录A. Simply Strange SortB. Charmed by the GameC. Deep Down BelowD1/D2. Up the StripE. Bottom-Tier ReversalsF. Top-Notch InsertionsA. Simply Strange Sort 签到题&#xff0c;暴力做 …

[小技巧]C#中如何为枚举类型添加描述方法

背景在我们的日常开发中&#xff0c;我们会经常使用枚举类型。有时我们只需要显示枚举的值或者枚举值对应名称&#xff0c; 但是在某些场景下&#xff0c;我们可能需要将枚举值显示为不同的字符串。例&#xff1a; 当前我们有如下枚举Level这个枚举有4个可选值B, N, G, VG。 现…