# Codeforces Round #439 (Div. 2)

A:传送门

B:传送门

C:传送门

D:传送门

E:传送门

A:

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 2005

int n,m,ans;
int a[maxn],b[maxn];
bool fuck[10000005];

int x=0,f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
return x*f;
}

inline void print(int x){
if (x<0){putchar('-'); x=-x;}
if (x>=10) print(x/10);
putchar(x%10+'0');
}

int main(){
for (int i=1;i<=n;i++) a[i]=read(),fuck[a[i]]=1;
for (int i=1;i<=n;i++) b[i]=read(),fuck[b[i]]=1;
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
if (fuck[a[i]^b[j]]) ans++;
puts((ans&1)?"Koyomi":"Karen");
return 0;
}


B:

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int n,m;

int x=0,f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
return x*f;
}

inline void print(int x){
if (x<0){putchar('-'); x=-x;}
if (x>=10) print(x/10);
putchar(x%10+'0');
}

long long a,b;

int main(){
scanf("%lld%lld",&a,&b);
if (b-a>20){puts("0"); return 0;}
int ans=1;
for (long long i=a+1;i<=b;i++) ans=ans*(i%10)%10;
printf("%d\n",ans);
return 0;
}


C:

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 5005
const int mod=998244353;

int n,m,k,ans;
int inv[maxn],fac[maxn];
int C[maxn][maxn];

int x=0,f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
return x*f;
}

inline void print(int x){
if (x<0){putchar('-'); x=-x;}
if (x>=10) print(x/10);
putchar(x%10+'0');
}

int solve(int n,int m){
int ret=0; if (n>m) swap(n,m);
for (int i=0;i<=n;i++) ret=(ret+1ll*C[n][i]*fac[m]%mod*inv[m-i])%mod;
return ret;
}

int main(){
fac[0]=1; for (int i=1;i<=5000;i++) fac[i]=1ll*fac[i-1]*i%mod;
inv[0]=inv[1]=1; for (int i=2;i<=5000;i++) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
for (int i=1;i<=5000;i++) inv[i]=1ll*inv[i-1]*inv[i]%mod;
for (int i=0;i<=5000;i++){
C[i][0]=1;
for (int j=1;j<=i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
}
ans=1ll*solve(n,m)*solve(m,k)%mod*solve(n,k)%mod;
printf("%d\n",ans);
return 0;
}


D:

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 100005
const int mod=1e9+7;

int n,m,pps,tot;
int size[maxn],now[maxn],pre[maxn],son[maxn],num[40];
bool vis[maxn];

int x=0,f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
return x*f;
}

int calc(int x){
int d1=1,d2=1,t1,t2;
for (t1=x;t1<=n;t1<<=1,d1++); t1>>=1,d1--;
for (t2=x;t2<=n;t2=t2<<1|1,d2++); t2>>=1,d2--;
return num[min(d1,d2)]+(d1==d2?0:(n-t1+1));
}

struct hash_table{
static const int mod=(1<<20);
int tot,now[mod+10],pre[maxn],son[maxn];
void insert(int x){
int tmp=x&(mod-1);
son[++tot]=x,pre[tot]=now[tmp],now[tmp]=tot,size[tot]=calc(x);
}
int find(int x){
int tmp=x&(mod-1);
for (int p=now[tmp];p;p=pre[p]) if (son[p]==x) return p;
return 0;
}
}h;

struct edge{int x,y;}e[maxn];

void add(int a,int b){son[++tot]=b,pre[tot]=now[a],now[a]=tot;}

void get_size(int x,int fa){
for (int p=now[x];p;p=pre[p])
if (son[p]!=fa) size[x]-=size[son[p]],get_size(son[p],x);
}

void dfs(int x,int &ret){
vis[x]=1,ret=(ret+size[x])%mod;
for (int p=now[x];p;p=pre[p])
if (!vis[son[p]]) dfs(son[p],ret);
vis[x]=0;
}

int solve(int x){
int ret=0;
dfs(x,ret);
return ret;
}

int main(){
for (int i=1;i<=30;i++) num[i]=2*num[i-1]+1;
h.insert(1);
for (int i=1;i<=m;i++){
for (int t=x;t;t>>=1) if (!h.find(t)) h.insert(t);
for (int t=y;t;t>>=1) if (!h.find(t)) h.insert(t);
}
for (int i=2;i<=h.tot;i++) link(i,h.find(h.son[i]>>1));
get_size(1,0);
for (int i=1;i<=m;i++) link(h.find(e[i].x),h.find(e[i].y));
int ans=0;
for (int i=1;i<=h.tot;i++) ans=(ans+1ll*solve(i)*size[i])%mod;
printf("%d\n",ans);
return 0;
}


E:

#include<map>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 2505

int n,m,cnt,q;
long long c[maxn][maxn];

struct node{
int a,b,c,d; node(){} node (int _a,int _b,int _c,int _d){a=_a,b=_b,c=_c,d=_c;}
bool operator <(const node &x)const{
if (a!=x.a) return a<x.a;
if (b!=x.b) return b<x.b;
if (c!=x.c) return c<x.c;
if (d!=x.d) return d<x.d;
return 0;
}
};

map<node,int> mp;

int x=0,f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
return x*f;
}

inline void print(int x){
if (x<0){putchar('-'); x=-x;}
if (x>=10) print(x/10);
putchar(x%10+'0');
}

void change(int x,int y,int v){
for (int i=x;i<=n;i+=i&(-i))
for (int j=y;j<=m;j+=j&(-j))
c[i][j]+=v;
}

long long query(int x,int y){
long long ret=0;
for (int i=x;i;i-=i&(-i))
for (int j=y;j;j-=j&(-j))
ret+=c[i][j];
return ret;
}

int get_rand(int x){
return 1ll*rand()*rand()%1000000000+x;
}

int main(){
for (int i=1;i<=q;i++){
if (type==3){
long long x=query(x1,y1),y=query(x2,y2);
puts(x==y?"Yes":"No");
}
if (x1>x2) swap(x1,x2); if (y1>y2) swap(y1,y2);
if (type==1){
int pps=0;
if (mp.find(node(x1,y1,x2,y2))==mp.end()) pps=get_rand(i);
else pps=mp[node(x1,y1,x2,y2)];
change(x1,y1,pps);
change(x2+1,y1,-pps);
change(x1,y2+1,-pps);
change(x2+1,y2+1,pps);
mp[node(x1,y1,x2,y2)]=pps;
}
if (type==2){
int pps=mp[node(x1,y1,x2,y2)];
change(x1,y1,-pps);
change(x2+1,y1,pps);
change(x1,y2+1,pps);
change(x2+1,y2+1,-pps);
}
}
return 0;
}

posted @ 2017-10-07 16:34  DUXT  阅读(268)  评论(0编辑  收藏  举报