补题(2016-2017区域赛)

写在前面:
有些事很艰难,但必须去做。
比如模拟以前经历过的困境,尝试再次置身其中。
假如连过去的问题都无法解决,又凭什么让自己相信,当全新的问题出现时,能做得更好呢?
2016 ICPC Dalian, by Avalon
Board: http://board.acmicpc.info/icpc2016/dlmu_onsite.php
Solved Now: 10/11
【补题(2016-2017区域赛)】Problem B
http://acm.hdu.edu.cn/showproblem.php?pid=5972
Code:

#include using namespace std; int n; bitset<1003>b[10]; char s[5000003]; int main(){ while(~scanf("%d",&n)){ for(int i=0; i<10; i++)b[i].reset(); for(int i=0; ians; for(int i=0; i

Key: BITSET Shift-And FastIO
Problem K
http://acm.hdu.edu.cn/showproblem.php?pid=5981
Code:
#include using namespace std; const int mod=100000073; typedef long long ll; ll dp[5000003]; ll sum[5000003]; int main(){ dp[1]=1; dp[2]=2; sum[1]=1; sum[2]=3; int l=1,r=1; for(int i=3; i<=5000000; i++){ while(dp[l+1]+l+1<=i-1)l++; dp[i]=i-l; while(dp[r+1]<=dp[i]-1)r++; sum[i]=sum[r]-sum[l-1]+sum[i-1]+mod; while(sum[i]>mod)sum[i]-=mod; } int x,y; while(~scanf("%d%d",&x,&y)){ x=y-x+1; printf("%lld %lld\n",dp[x],(sum[x]-sum[x-1]+mod)%mod); } }

Key: DP 2-Pointer
2016 ICPC Qingdao, by Avalon
No Official Board
Replay Board: https://vjudge.net/contest/142308#rank
Solved Now: 6/13
Problem K
http://acm.hdu.edu.cn/showproblem.php?pid=5992
Code:
#include using namespace std; typedef long long ll; const ll INF=1ll<<60; struct node{ int d[3],ma[3],mi[3],l,r,id; }T[200003]; int rt,n,m,cmp_d; inline bool cmp(node a,node b){ return a.d[cmp_d]>1; cmp_d=D; nth_element(T+l,T+mid,T+r+1,cmp); T[mid].ma[0]=T[mid].mi[0]=T[mid].d[0]; T[mid].ma[1]=T[mid].mi[1]=T[mid].d[1]; T[mid].ma[2]=T[mid].mi[2]=T[mid].d[2]; if(l!=mid){ T[mid].l=build(l,mid-1,(D+1)%3); up(mid,T[mid].l); } if(r!=mid){ T[mid].r=build(mid+1,r,(D+1)%3); up(mid,T[mid].r); } return mid; }ll dis; int ans; int x,y,c; //估计范围 inline ll getdis(int p){ ll ret=0; if(T[p].mi[2]>c)return INF; if(x>T[p].ma[0])ret+=1ll*(x-T[p].ma[0])*(x-T[p].ma[0]); if(xT[p].ma[1])ret+=1ll*(y-T[p].ma[1])*(y-T[p].ma[1]); if(yc)d0=INF; if(d0

Key: KD-Tree
Referred to:
https://blog.csdn.net/jiangshibiao/article/details/34144829
2016 ICPC China-Final, by Avalon
Board: http://codeforces.com/gym/101194/standings
Solved Now: 8/13
Problem G
http://codeforces.com/gym/101194/attachments/download/5009/20162017-acmicpc-china-final-en.pdf
Code:
#include using namespace std; int n,m,q; int a[200003]; int f[200003]; int siz[200003]; int fa[200003][20]; int fal[200003][20]; int ms[200003]; int tot; int tim[200003]; int mx; setst[100003]; int tmp; int ans[200003]; bool vis[200003]; struct edge{ int u,v,w; }rec[200003]; bool cmp(edge a,edge b){ return a.wmx){ mx=p; tmp=a[u]; } else if(p==mx){ tmp=min(tmp,a[u]); } } void del(int u){ if(a[u]==-1)return ; int p=--tim[a[u]]; if(p==0){ st[p+1].erase(a[u]); } else { st[p+1].erase(a[u]); st[p].insert(a[u]); } if(st[mx].empty()){ --mx; if(mx==0)tmp=0; else tmp=*(st[mx].begin()); } } void addtree(int u){ add(u); for(int i=head[u]; ~i; i=e[i].next){ int v=e[i].to; addtree(v); } } void deltree(int u){ del(u); for(int i=head[u]; ~i; i=e[i].next){ int v=e[i].to; deltree(v); } } void dfs2(int u){ vis[u]=true; if(ms[u]==-1){ add(u); ans[u]=tmp; return; } for(int i=head[u]; ~i; i=e[i].next){ int v=e[i].to; if(v==ms[u])continue; dfs2(v); deltree(v); } dfs2(ms[u]); for(int i=head[u]; ~i; i=e[i].next){ int v=e[i].to; if(v==ms[u])continue; addtree(v); } add(u); ans[u]=tmp; } void init(){ memset(a,-1,sizeof(a)); memset(f,0,sizeof(f)); tot=n; cnt=0; memset(head,-1,sizeof(head)); memset(fa,0,sizeof(fa)); mx=0; for(int i=1; i<=n; i++)st[i].clear(); } void printtree(){ for(int i=1; i<=tot; i++)printf("%d%c",a[i],i==tot?'\n':' '); for(int u=1; u<=tot; u++){ for(int i=head[u]; ~i; i=e[i].next){ int v=e[i].to; cout<=1; i--){ if(!vis[i]){ dfs(i); } } memset(vis,false,sizeof(vis)); for(int i=tot; i>=1; i--){ if(!vis[i]){ dfs2(i); deltree(i); } } memset(vis,false,sizeof(vis)); for(int j=1; j<=18; j++){ for(int i=1; i<=tot; i++){ fa[i][j]=fa[fa[i][j-1]][j-1]; fal[i][j]=fal[fa[i][j-1]][j-1]; } } int q; scanf("%d",&q); printf("Case #%d:\n",tt); int last=0; while(q--){ int x,y; scanf("%d%d",&x,&y); x^=last; y^=last; for(int j=18; j>=0; j--){ if(fa[x][j]==0)continue; if(fal[x][j]<=y)x=fa[x][j]; } last=ans[x]; printf("%d\n",last); } } }

Key: MST 启发式合并 树上倍增
只有补了题才知道自己有多菜
Problem F
http://codeforces.com/gym/101194/attachments/download/5009/20162017-acmicpc-china-final-en.pdf
Code:
#include #include #include using namespace std; const int maxn=305000; char str[maxn]; int s[maxn]; int sa[maxn], t[maxn], t2[maxn], c[maxn], n; int Rank[maxn], height[maxn]; int u[maxn], d[maxn]; void build_sa(int m, int n){ int i, *x=t, *y=t2; for(i=0; i=0; i--)sa[--c[x[i]]]=i; for(int k=1; k<=n; k<<=1){ int p=0; for(i=n-k; i=k)y[p++]=sa[i]-k; for(i=0; i=0; i--)sa[--c[x[y[i]]]]=y[i]; swap(x, y); p=1; x[sa[0]]=0; for(i=1; i=n)break; m=p; } } void geth(int n){ int i, j, k=0; for(i=0; i=f1)continue; l=i, r=i; while(sa[r]=l; j--)d[j]=min(height[j+1], d[j+1]); for(int j=l; j

Key: SA

    推荐阅读