# Codeforces global round 2 solution

## 毫无区分度的手速场

Posted by yjjr's blog on April 6, 2019

# A. Ilya and a Colorful Walk

## Code

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=3e5+6;
int n,a[maxn],ans=0;
int main(){
int p=1,q=n;
while(p<=q){
if(a[p]!=a[q]){ans=q-p;break;}
if(a[p+1]!=a[q]){p++;continue;}
if(a[q-1]!=a[p]){q--;continue;}
p++,q--;
}
rep(i,1,n-1)if(a[i]!=a[n])ans=max(ans,n-i);
dep(i,n,2)if(a[i]!=a[1])ans=max(ans,i-1);
cout<<ans<<endl;
return 0;
}


# B. Alyona and a Narrow Fridge

## Code

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
#define mid ((L+R)>>1)
const int maxn=1e3+6;
int a[maxn],b[maxn],n;
ll K;
inline bool check(int x){
ll sum=0;
rep(i,1,x)b[i]=a[i];
sort(b+1,b+1+x);
for(int i=x;i>=1;i-=2)sum+=b[i];
if(sum>K)return 0;else return 1;
}
int main(){
int L=1,R=n,ans=0;
while(L<=R){
if(check(mid))ans=mid,L=mid+1;else R=mid-1;
}
cout<<ans<<endl;
return 0;
}


# C. Ramesses and Corner Inversion

## Code

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=1e3+6;
int n,m,s1[maxn],s2[maxn],s3[maxn],s4[maxn],a[maxn][maxn],b[maxn][maxn];
int main(){
rep(i,1,n)rep(j,1,m)cin>>a[i][j];
rep(i,1,n)rep(j,1,m)cin>>b[i][j];
rep(i,1,n){
rep(j,1,m)s1[i]=s1[i]^a[i][j],s3[i]=s3[i]^b[i][j];
}
rep(j,1,m){
rep(i,1,n)s2[j]=s2[j]^a[i][j],s4[j]=s4[j]^b[i][j];
}
rep(i,1,n)if(s1[i]!=s3[i]){puts("No");return 0;}
rep(i,1,m)if(s2[i]!=s4[i]){puts("No");return 0;}
puts("Yes");
return 0;
}


# D. Frets On Fire

## Code

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=2e5+6;
int n,Q,cnt=0;
ll a[maxn],b[maxn],c[maxn],d[maxn];
int main(){
sort(a+1,a+1+n);
a[0]=-1;
rep(i,1,n)if(a[i]!=a[i-1])b[++cnt]=a[i];
sort(b+1,b+1+cnt);
rep(i,1,cnt-1)c[i]=b[i+1]-b[i];
sort(c+1,c+cnt);
//rep(i,1,cnt-1)cout<<c[i]<<' ';cout<<endl;
rep(i,1,cnt-1)d[i]=d[i-1]+c[i];
while(Q--){