【块状树】【博弈论】bzoj3729 Gty的游戏
块状树,每个块的根记录一下当前块内距块根为奇数距离的异或和和偶数距离的异或和,询问的时候讨论一下即可。
总的节点数可能超过50000。
#include<cstdio>
#include<cmath>
using namespace std;
#define N 100001
int n,m,L,a[N];
int en,v[N<<1],next[N<<1],first[N];
int e2,v2[N<<1],nex2[N<<1],firs2[N];
int sz,top[N],siz[N],fa[N],xorv[2][N],meiz,dep[N];
void AddEdge(int U,int V)
{
v[++en]=V;
next[en]=first[U];
first[U]=en;
}
void AddEdg2(int U,int V)
{
v2[++e2]=V;
nex2[e2]=firs2[U];
firs2[U]=e2;
}
void makeblock(int U)
{
for(int i=first[U];i;i=next[i])
if(v[i]!=fa[U])
{
fa[v[i]]=U;
dep[v[i]]=dep[U]+1;
if(siz[top[U]]<sz)
{
++siz[top[U]];
top[v[i]]=top[U];
}
makeblock(v[i]);
}
}
void makeGoto(int U)
{
for(int i=first[U];i;i=next[i])
if(v[i]!=fa[U])
{
if(top[v[i]]!=top[U])
AddEdg2(top[U],v[i]);
makeGoto(v[i]);
}
}
void dfs_init(int U,bool d)
{
xorv[d][top[U]]^=a[U];
for(int i=first[U];i;i=next[i])
if(v[i]!=fa[U]&&top[v[i]]==top[U])
dfs_init(v[i],d^1);
}
int ans;
void dfs_Goto(int U,bool d)
{
ans^=xorv[d][top[U]];
for(int i=firs2[U];i;i=nex2[i])
dfs_Goto(v2[i],d^((dep[v2[i]]-dep[U])&1));
}
void dfs_block(int U,bool d)
{
if(d) ans^=a[U];
for(int i=first[U];i;i=next[i])
if(v[i]!=fa[U])
{
if(top[v[i]]==top[U])
dfs_block(v[i],d^1);
else
dfs_Goto(v[i],d);
}
}
void query(int U)
{
ans=0;
if(U==top[U]) dfs_Goto(U,1);
else dfs_block(U,0);
}
void Update(int U,int x)
{
xorv[0][top[U]]=xorv[1][top[U]]=0;
a[U]=x%(L+1);
dfs_init(top[U],0);
}
void AddNode(int U,int V,int x)
{
++n;
fa[V]=U;
dep[V]=dep[U]+1;
if(siz[top[U]]<sz)
{
top[V]=top[U];
++siz[top[V]];
}
else
{
top[V]=V;
siz[V]++;
AddEdg2(top[U],V);
}
AddEdge(U,V);
a[V]=x%(L+1);
xorv[(dep[V]-dep[top[V]])&1][top[V]]^=a[V];
}
int main()
{
int x,y,c,op;
scanf("%d%d",&n,&L);
for(int i=1;i<=n;++i)
{
scanf("%d",&a[i]);
top[i]=i;
siz[i]=1;
a[i]%=(L+1);
}
for(int i=1;i<n;++i)
{
scanf("%d%d",&x,&y);
AddEdge(x,y);
AddEdge(y,x);
}
sz=sqrt(n);
makeblock(1);
makeGoto(1);
for(int i=1;i<=n;++i)
if(top[i]==i)
dfs_init(i,0);
scanf("%d",&m);
for(;m;--m)
{
scanf("%d%d",&op,&x); x^=meiz;
if(op==1)
{
query(x);
if(ans)
{
++meiz;
puts("MeiZ");
}
else puts("GTY");
}
else if(op==2)
{
scanf("%d",&c); c^=meiz;
Update(x,c);
}
else
{
scanf("%d%d",&y,&c); y^=meiz; c^=meiz;
AddNode(x,y,c);
}
}
return 0;
}
【块状树】【博弈论】bzoj3729 Gty的游戏的更多相关文章
- [BZOJ3729]Gty的游戏
[BZOJ3729]Gty的游戏 试题描述 某一天gty在与他的妹子玩游戏.妹子提出一个游戏,给定一棵有根树,每个节点有一些石子,每次可以将不多于L的石子移动到父节点,询问将某个节点的子树中的石子移动 ...
- 【块状树】bzoj3731 Gty的超级妹子树
带 加点 删边的块状树. 加点在 bzoj3720 说过. 删边其实就是块顶打标记,记录其属于哪棵树,防止在dfs搜集答案时跑到别的树上. 然后暴力把所在块拆开. 好像用邻接表存图,直接在vector ...
- 【块状树】bzoj3720 Gty的妹子树
块状树.教程见:http://z55250825.blog.163.com/blog/static/1502308092014163413858/将树按一定大小分块,分成许多子树,在每个子树的根节点记 ...
- BZOJ3729: Gty的游戏(伪ETT)
题面 传送门 前置芝士 巴什博奕 \(Nim\)游戏的改版,我们现在每次最多只能取走\(k\)个石子,那么\(SG\)函数很容易写出来 \[SG(x)=mex_{i=1}^{\min(x,k)}SG( ...
- bzoj 3720: Gty的妹子树 块状树
3720: Gty的妹子树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 412 Solved: 153[Submit][Status] Descr ...
- 【BZOJ 3729】3729: Gty的游戏 (Splay维护dfs序+博弈)
未经博主同意不得转载 3729: Gty的游戏 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 448 Solved: 150 Description ...
- 【kruscal】【最小生成树】【块状树】bzoj3732 Network
跟去年NOIP某题基本一样. 最小生成树之后,就变成了询问连接两点的路径上的权值最大的边. 倍增LCA.链剖什么的随便搞. 块状树其实也是很简单的,只不过每个点的点权要记录成“连接其与其父节点的边的权 ...
- 【块状树】【树链剖分】bzoj1036 [ZJOI2008]树的统计Count
很早之前用树链剖分写过,但是代码太长太难写,省选现场就写错了. #include<cstdio> #include<algorithm> #include<cstring ...
- 【块状树】【树链剖分】【线段树】bzoj3531 [Sdoi2014]旅行
离线后以宗教为第一关键字,操作时间为第二关键字排序. <法一>块状树,线下ac,线上tle…… #include<cstdio> #include<cmath> # ...
随机推荐
- git使用笔记(七)版本回退和撤销
By francis_hao Nov 21,2016 从版本库初始化开始,每一步的撤销操作 添加第一个文件 在空的版本库中创建了一个文件并git add到了缓存区,这时候怎么撤销呢? 撤销单个文 ...
- codeforces 1015E1&&E2
E1. Stars Drawing (Easy Edition) time limit per test 3 seconds memory limit per test 256 megabytes i ...
- linux之scp命令
linux之cp/scp命令+scp命令详解 名称:cp 使用权限:所有使用者 使用方式: cp [options] source dest cp [options] source... dire ...
- Kafka自我学习1-Multi-broker cluster
====================================Testing environment =========================================== ...
- [POJ2187][BZOJ1069]旋转卡壳
旋转卡壳 到现在依然不确定要怎么读... 以最远点对问题为例,枚举凸包上的两个点是最简单的想法,时间复杂度O(n2) 我们想象用两条平行线卡着这个凸包,当其中一个向某个方向旋转的时候另一个显然也是朝同 ...
- NOIP2016提高组D1T2 天天爱跑步
n<=300000个点的树,每个点有个人于第Ti秒观测,有m<=300000个人于时间0开始从Sj跑到Tj,速度1个点每秒,输出每个点上的人观察到的跑步的人的数量. 前25分:直接模拟每条 ...
- npm install 报node-sass错误
Node Sass could not -bit with Node.js .x Found bindings for the following environments: - OS X -bit ...
- DDCTF - evil 一个伪装成docx的exe
0x01 题目描述 题目比较简单,不过这种题感觉比单纯的逆向算法来有意思的多,所以记录一下~ 0x02 脱壳 先拖到IDA瞅一眼,发现加壳了 用PEID查一下是什么壳,但是没有查出来.使用String ...
- LeetCode 4 Median of Two Sorted Array
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted ...
- SpringMvc基础知识(一)
目录: springmvc框架原理(掌握) 前端控制器.处理器映射器.处理器适配器.视图解析器 springmvc入门程序 目的:对前端控制器.处理器映射器.处理器适配器.视图解析器学习 非注解的处理 ...