BZOJ 3729 splay维护DFS序+博弈论
来源:互联网 发布:java类加载器有哪些 编辑:程序博客网 时间:2024/05/17 03:28
思路:
这像是 阶梯Nim之类的东西
我们 直接把sg函数 设成mod(L+1)的
一棵子树 向下的奇数层上的石子xor起来 就是答案
有加点和改值的操作 就splay维护一下
//By SiriusRen#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N=1000050,inf=0x3f3f3f3f,NULLL=N-1;int n,m,l,op,xx,yy,zz,cnt;int sg[N],sg_odd[N],sg_even[N];int first[N],next[N*2],v[N*2],tot;int root,fa[N],ch[N][2],deep[N],d[N];void add(int x,int y){v[tot]=y,next[tot]=first[x],first[x]=tot++;}void push_up(int x){ int lson=ch[x][0],rson=ch[x][1]; d[x]=min(deep[x],min(d[lson],d[rson])); sg_odd[x]=sg_odd[lson]^sg_odd[rson]; sg_even[x]=sg_even[lson]^sg_even[rson]; if(deep[x]&1)sg_odd[x]^=sg[x]; else sg_even[x]^=sg[x];}void rotate(int p){ int q=fa[p],y=fa[q],x=(ch[q][1]==p); ch[q][x]=ch[p][!x],fa[ch[q][x]]=q; ch[p][!x]=q,fa[q]=p,fa[p]=y; if(y)ch[y][ch[y][1]==q]=p; push_up(q);}void splay(int x,int tp){ for(int y;y=fa[x];rotate(x)){ if(y==tp)break; if(fa[y]!=tp){ if((ch[y][0]==x)^(ch[fa[y]][0]==y))rotate(x); else rotate(y); } }push_up(x); if(!tp)root=x;}void dfs(int x,int y){ if(y)deep[x]=deep[y]+1; if(root)fa[x]=root,ch[root][1]=x; splay(x,0); for(int i=first[x];~i;i=next[i]){ if(v[i]!=y)dfs(v[i],x); }}int find(int x,int y){ if(d[ch[x][0]]<=y)return find(ch[x][0],y); if(deep[x]<=y)return x; return find(ch[x][1],y);}int main(){ memset(first,-1,sizeof(first)); scanf("%d%d",&n,&l),l++; for(int i=1;i<=n;i++)scanf("%d",&sg[i]),sg[i]%=l; for(int i=1;i<n;i++)scanf("%d%d",&xx,&yy),add(xx,yy),add(yy,xx); d[0]=deep[0]=inf,deep[1]=1,dfs(1,0); fa[NULLL]=root,ch[root][1]=NULLL,splay(NULLL,0); scanf("%d",&m); for(int i=1;i<=m;i++){ scanf("%d",&op); if(op==1){ scanf("%d",&xx),xx^=cnt; splay(xx,0);int temp=find(ch[xx][1],deep[xx]),ans=sg[xx]; splay(temp,xx); if(deep[xx]&1)ans=sg_even[ch[temp][0]]; else ans=sg_odd[ch[temp][0]]; if(!ans)puts("GTY"); else puts("MeiZ"),cnt++; } else if(op==2){ scanf("%d%d",&xx,&yy),xx^=cnt,yy^=cnt; splay(xx,0);sg[xx]=yy%l;push_up(xx); } else{ scanf("%d%d%d",&xx,&yy,&zz); xx^=cnt,yy^=cnt,zz^=cnt;zz%=l; sg[yy]=zz,deep[yy]=deep[xx]+1; splay(xx,0),fa[ch[xx][1]]=yy,fa[yy]=xx; ch[yy][1]=ch[xx][1],ch[xx][1]=yy; push_up(yy),push_up(xx); } }}
0 0
- BZOJ 3729 splay维护DFS序+博弈论
- BZOJ 3786 星系探索 Splay维护DFS序
- BZOJ 3786 星系探索 splay维护dfs序
- 【BZOJ 3786】星系探索 splay维护dfs序
- splay 动态维护dfs序
- Bzoj3786星系探索:splay维护dfs序
- BZOJ3786: 星系探索 splay维护dfs序
- bzoj 3729: Gty的游戏 splay+dfs序+阶梯博弈
- BZOJ 3786 星系探索 DFS序+Splay
- bzoj 3786: 星系探索 dfs序+splay
- BZOJ 1251 Splay维护序列
- BZOJ 3323 splay维护序列
- [博弈 && Splay维护DFS序]BZOJ3729 .Gty的游戏
- BZOJ 3991 set维护dfs序
- bzoj 3786: 星系探索(splay+dfs序)
- BZOJ 3779 重组病毒 LCT+线段树维护DFS序
- 【bzoj 1103】[POI2007]大都市meg 树状数组维护dfs序
- BZOJ 1500([NOI2005]维修数列-Splay的数列维护)
- java线程池
- [PC样本分析] 对于PC硬盘逻辑锁的简单分析
- 当你输入在浏览器输入网址发生了什么
- 367. Valid Perfect Square
- 2016蓝桥杯第二题答案
- BZOJ 3729 splay维护DFS序+博弈论
- 一位资深程序员大牛给予Java初学者的学习建议
- SVM支持向量机
- 105. Construct Binary Tree from Preorder and Inorder Traversal\106. Construct Binary Tree from Inor
- 当FragmentTransaction在add和replace时,它们之间的区别
- 物联网操作系统HelloX V1.81发布公告
- 原型模式
- IPC机制--概述
- Flume 1.7 源码分析(一)源码编译