好难受啊掉\(rating\)了……
\(A\ Ilya\ and\ a\ Colorful\ Walk\)
找到最后一个与第一个颜色不同的,比一下距离,然后再找到最左边和最右边与第一个颜色不同的,再和所有与第一个颜色相同的比较一下距离
//minamoto#include#define R register#define fp(i,a,b) for(R int i=(a),I=(b)+1;i I;--i)#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)template inline bool cmax(T&a,const T&b){return a '9'||ch<'0')(ch=='-')&&(f=-1); for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0'); return res*f;}char sr[1<<21],z[20];int C=-1,Z=0;inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}void print(R int x){ if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x; while(z[++Z]=x%10+48,x/=10); while(sr[++C]=z[Z],--Z);sr[++C]='\n';}const int N=3e5+5;int a[N],n,mx,bg;int main(){// freopen("testdata.in","r",stdin); n=read(); fp(i,1,n)a[i]=read(); fp(i,1,n)if(a[i]!=a[1]){ cmax(mx,i-1); if(!bg)bg=i; } fp(i,1,n)if(a[i]==a[1])cmax(mx,abs(bg-i)); bg=0; fd(i,n,1)if(a[i]!=a[1]&&!bg){bg=i;break;} fp(i,1,n)if(a[i]==a[1])cmax(mx,abs(bg-i)); printf("%d\n",mx); return 0;}
\(B\ Alyona\ and\ a\ Narrow\ Fridge\)
首先二分答案。对于一种情况显然是\(sort\)之后从右往左两两分组最优,判一下就好了
//minamoto#include#define R register#define fp(i,a,b) for(R int i=(a),I=(b)+1;i I;--i)#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)template inline bool cmax(T&a,const T&b){return a '9'||ch<'0')(ch=='-')&&(f=-1); for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0'); return res*f;}char sr[1<<21],z[20];int C=-1,Z=0;inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}void print(R int x){ if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x; while(z[++Z]=x%10+48,x/=10); while(sr[++C]=z[Z],--Z);sr[++C]='\n';}const int N=1005;int a[N],st[N],top,n,h,l,r,mid,ans;bool ck(){ top=0; fp(i,1,mid)st[++top]=a[i]; sort(st+1,st+1+top); int res=0; for(R int i=mid;i>=2;i-=2){ res+=max(st[i],st[i-1]); if(res>h)return false; } if(mid&1)res+=st[1]; return res<=h;}int main(){// freopen("testdata.in","r",stdin); n=read(),h=read(); fp(i,1,n)a[i]=read(); l=1,r=n,ans=1; while(l<=r){ mid=(l+r)>>1; ck()?(ans=mid,l=mid+1):r=mid-1; } printf("%d\n",ans); return 0;}
\(C\ Ramesses\ and\ Corner\ Inversion\)
发现操作之后最多只会使一行或一列的偶数个格子发生变化,那么只有在\(A\)和\(B\)的行列每行每列不同格子个数都是偶数时才可行
//minamoto#include#define R register#define fp(i,a,b) for(R int i=(a),I=(b)+1;i I;--i)#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)template inline bool cmax(T&a,const T&b){return a '9'||ch<'0')(ch=='-')&&(f=-1); for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0'); return res*f;}char sr[1<<21],z[20];int C=-1,Z=0;inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}void print(R int x){ if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x; while(z[++Z]=x%10+48,x/=10); while(sr[++C]=z[Z],--Z);sr[++C]='\n';}const int N=505;int A[N][N],B[N][N],r[N],c[N],n,m;int main(){// freopen("testdata.in","r",stdin); n=read(),m=read(); fp(i,1,n)fp(j,1,m)A[i][j]=read(); fp(i,1,n)fp(j,1,m)B[i][j]=read(); fp(i,1,n)fp(j,1,m)if(A[i][j]!=B[i][j])++r[i],++c[j]; fp(i,1,n)if(r[i]&1)return puts("No"),0; fp(j,1,m)if(c[j]&1)return puts("No"),0; puts("Yes"); return 0;}
\(D\ Frets\ On\ Fire\)
先把所有\(s_i\)升序排序,那么一行里有贡献的元素个数是\(\min\{s_{i+1}-s_i,r-l+1\}\),对于\(s_n\)来说贡献就是\(r-l+1\),所以我们记\(d_i=s_{i+1}-s_i\),\(d_n=inf\),然后\(sort\)一下,二分找到第一个\(\geq r-l+1\)的位置,前面的贡献是前缀和,后面的贡献是元素个数乘上\(r-l+1\)
//minamoto#include#define R register#define ll long long#define inf 2e18#define fp(i,a,b) for(R int i=(a),I=(b)+1;i I;--i)#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)using namespace std;char buf[1<<21],*p1=buf,*p2=buf;inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}ll read(){ R ll res,f=1;R char ch; while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1); for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0'); return res*f;}char sr[1<<21],z[20];int C=-1,Z=0;inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}void print(R ll x){ if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x; while(z[++Z]=x%10+48,x/=10); while(sr[++C]=z[Z],--Z);sr[++C]=' ';}const int N=1e5+5;ll s[N],sum[N],l,r,w;int n,q,p;int main(){// freopen("testdata.in","r",stdin); n=read(); fp(i,1,n)s[i]=read(); sort(s+1,s+1+n); fp(i,1,n-1)s[i]=s[i+1]-s[i];s[n]=inf; sort(s+1,s+1+n); fp(i,1,n)sum[i]=sum[i-1]+s[i]; q=read(); while(q--){ l=read(),r=read(),w=r-l+1; p=lower_bound(s+1,s+1+n,w)-s-1; print(sum[p]+w*(n-p)); } return Ot(),0;}
\(E\ Pavel\ and\ Triangles\)
首先三角形只能是形如\((i,i,i)\)或者\((i,j,j)(i<j)\)
然后有个贪心,从小到大考虑,首先看看能不能和前面剩余的拼成形如\((i,j,j)\)的,然后再把所有能拼成\((i,i,i)\)的都拼了。证明并不会
//minamoto#include#define R register#define ll long long#define fp(i,a,b) for(R int i=(a),I=(b)+1;i I;--i)#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)using namespace std;char buf[1<<21],*p1=buf,*p2=buf;inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}int read(){ R int res,f=1;R char ch; while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1); for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0'); return res*f;}int n,x,las,mn;ll res;int main(){// freopen("testdata.in","r",stdin); n=read(); fp(i,1,n){ x=read(),mn=min(las,x>>1),x-=(mn<<1),res+=mn,las-=mn; res+=x/3,x%=3,las+=x; } printf("%I64d\n",res); return 0;}
剩下先咕了