传送门
Snuke and Spells
答案等于 n n n条线段 [ i − c n t i + 1 , i ] [i-cnt_i+1,i] [i−cnti+1,i]覆盖不到 1 ∼ n 1sim n 1∼n的位置,每次只修改一个地方可以 O ( 1 ) O(1) O(1)维护。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#include <bits/stdc++.h> using namespace std; const int RLEN=1<<18|1; inline char nc() { static char ibuf[RLEN],*ib,*ob; (ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin)); return (ib==ob) ? -1 : *ib++; } inline int rd() { char ch=nc(); int i=0,f=1; while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();} while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();} return i*f; } const int N=2e5+50; int n,m,a[N],b[N],c[N]; inline bool add(int p) {return (p>=1) ? (!b[p]++) : 0;} inline bool dec(int p) {return (p>=1) ? (!--b[p]) : 0;} int main() { n=rd(),m=rd(); int step=n; for(int i=1;i<=n;i++) a[i]=rd(), c[a[i]]++; for(int i=1;i<=n;i++) for(int j=i-c[i]+1;j<=i;j++) if(add(j)) --step; for(int i=1;i<=m;i++) { int p=rd(), v=rd(); if(dec(a[p]-c[a[p]]+1)) ++step; --c[a[p]]; a[p]=v; ++c[v]; if(add(v-c[v]+1)) --step; printf("%dn",step); } }
Game on Tree
s g i = ⊕ j ( s g j + 1 ) sg_i = oplus_j (sg_j+1) sgi=⊕j(sgj+1)。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#include <bits/stdc++.h> using namespace std; const int RLEN=1<<18|1; inline char nc() { static char ibuf[RLEN],*ib,*ob; (ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin)); return (ib==ob) ? -1 : *ib++; } inline int rd() { char ch=nc(); int i=0,f=1; while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();} while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();} return i*f; } const int N=1e5+50; int n; vector <int> edge[N]; inline int sg(int x,int f) { int sum=0; for(auto v:edge[x]) if(v^f) sum^=(sg(v,x)+1); return sum; } int main() { n=rd(); for(int i=1;i<n;i++) { int x=rd(), y=rd(); edge[x].push_back(y); edge[y].push_back(x); } puts(sg(1,0) ? "Alice" : "Bob"); }
Jigsaw
用一条边来表示一个块,两端点跟两边的高度有关。
然后就是用若干条从 1 1 1类点到 2 2 2类点的路径覆盖所有边,可以用类似欧拉路径的方法做。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46#include <bits/stdc++.h> using namespace std; const int RLEN=1<<18|1; inline char nc() { static char ibuf[RLEN],*ib,*ob; (ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin)); return (ib==ob) ? -1 : *ib++; } inline int rd() { char ch=nc(); int i=0,f=1; while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();} while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();} return i*f; } const int N=4e2+50, H=201; int n,d[N],vis[N],ok[N]; vector <int> edge[N]; inline void add(int x,int y) { x+=H; y+=H; ok[x]=ok[y]=1; --d[x]; ++d[y]; edge[x].push_back(y); edge[y].push_back(x); } int tag; inline bool dfs(int x) { if(x<=H && d[x]>0) return false; if(x>H && d[x]<0) return false; vis[x]=1; tag|=(d[x]!=0); for(auto v:edge[x]) if(!vis[v]) if(!dfs(v)) return false; return true; } int main() { n=rd(); rd(); for(int i=1;i<=n;i++) { int a=rd(), b=rd(), c=rd(), d=rd(); add(c?c:-a,d?-d:b); } for(int i=1;i<=2*H;i++) if(ok[i] && !vis[i]) { tag=0; if((!dfs(i)) || (!tag)) return puts("NO"),0; } puts("YES"); }
Zigzag
考虑压一下前面一条路径的方案,这样是 O ( m ∗ 3 n ) O(m*3^n) O(m∗3n)的。
改成轮廓线DP就可以优化到 O ( n m ∗ n 2 ) O(nm*n^2) O(nm∗n2)了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58#include <bits/stdc++.h> using namespace std; const int RLEN=1<<18|1; inline char nc() { static char ibuf[RLEN],*ib,*ob; (ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin)); return (ib==ob) ? -1 : *ib++; } inline int rd() { char ch=nc(); int i=0,f=1; while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();} while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();} return i*f; } const int N=20, mod=1e9+7; inline int add(int x,int y) {return (x+y>=mod) ? (x+y-mod) : (x+y);} inline void up(int &x,int y) {x=add(x,y);} int n,m,k,lim[N+20][N+20]; int bin[N+20],y,f[2][(1<<(N-1))+50],nxt[(1<<(N-1))+50][N]; inline int trans(int sta,int pos) { int p=nxt[sta][pos]; sta^=bin[pos]; if(p<n-1) sta^=bin[p]; return sta; } inline void trans(int id) { for(int i=0;i<n-1;i++) { y^=1; memset(f[y],0,sizeof(f[y])); for(int pre=0;pre<bin[n-1];++pre) if(f[y^1][pre]) { if(!(pre&bin[i]) && (lim[id][i]!=2)) up(f[y][pre],f[y^1][pre]); if(lim[id][i]!=1) up(f[y][trans(pre,i)],f[y^1][pre]); } } } int main() { n=rd(), m=rd(), k=rd(); if(n==1) return puts("1"),0; for(int i=0;i<=n;i++) bin[i]=1<<i; for(int i=0;i<bin[n-1];i++) for(int j=0,z=0;j<n-1;j++) { while(z<n-1 && (z<j || (!(i&bin[z])))) ++z; nxt[i][j]=z; } for(int i=1;i<=k;i++) { int x=rd(), y=rd()-1; lim[x][y]=rd()+1; } f[y][0]=1; for(int i=1;i<=m;i++) trans(i); int ans=0; for(int i=0;i<bin[n-1];i++) up(ans,f[y][i]); cout<<ans<<'n'; }
最后
以上就是友好长颈鹿最近收集整理的关于Atcoder AGC017 简要题解的全部内容,更多相关Atcoder内容请搜索靠谱客的其他文章。
发表评论 取消回复