• BZOJ 2819 Nim 树链剖分+树状数组


    这题真没什么意思.

    不过就是将普通的求Min,Max,求和等东西换成Xor,偏偏Xor还有很多性质.

    算是刷道水题吧.

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<cmath>
    #include<ctime>
    #include<string>
    #include<iomanip>
    #include<algorithm>
    #include<map>
    using namespace std;
    #define LL long long
    #define FILE "dealing"
    #define up(i,j,n) for(int i=j;i<=n;++i)
    #define db double
    #define uint unsigned int
    #define eps 1e-12
    #define pii pair<int,int>
    int read(){
    	int x=0,f=1,ch=getchar();
    	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    	return f*x;
    }
    const int maxn=505000,maxm=5050*5050,limit=1e6,mod=(int)(7+1e9+0.1);
    const db inf=(1e18);
    template<class T>bool cmax(T& a,T b){return a<b?a=b,true:false;}
    template<class T>bool cmin(T& a,T b){return a>b?a=b,true:false;}
    template<class T>T min(T& a,T& b){return a<b?a:b;}
    template<class T>T max(T& a,T& b){return a>b?a:b;}
    int n,m;
    struct node{
    	int y,next;
    }e[maxn<<1];
    int len=0,linkk[maxn],siz[maxn],top[maxn],son[maxn],dfs_clock,dep[maxn],fa[maxn],v[maxn],id[maxn],pre[maxn];
    void insert(int x,int y){
    	e[++len].y=y;
    	e[len].next=linkk[x];
    	linkk[x]=len;
    }
    void dfs1(int x){
    	siz[x]=1;
    	for(int i=linkk[x];i;i=e[i].next){
    		if(e[i].y==fa[x])continue;
    		fa[e[i].y]=x;
    		dep[e[i].y]=dep[x]+1;
    		dfs1(e[i].y);
    		siz[x]+=siz[e[i].y];
    		if(siz[e[i].y]>siz[son[x]])son[x]=e[i].y;
    	}
    }
    void dfs2(int x){
    	pre[x]=++dfs_clock;
    	if(son[x]){
    		top[son[x]]=top[x];
    		dfs2(son[x]);
    	}
    	for(int i=linkk[x];i;i=e[i].next){
    		if(e[i].y==fa[x]||e[i].y==son[x])continue;
    		top[e[i].y]=e[i].y;
    		dfs2(e[i].y);
    	}
    }
    int c[maxn];
    int lowbit(int x){return x&-x;}
    void add(int x,int d){
    	while(x<=n)c[x]^=d,x+=lowbit(x);
    }
    int getxor(int x){
    	int ans=0;
    	while(x)ans^=c[x],x-=lowbit(x);
    	return ans;
    }
    void query(int x,int y){
    	int d=0;
    	while(true){
    		if(dep[x]>dep[y])swap(x,y);
    		int f1=top[x],f2=top[y];
    		if(f1==f2){
    			d^=getxor(pre[x]-1)^getxor(pre[y]);
    			break;
    		}
    		if(dep[f1]>dep[f2])swap(f1,f2),swap(x,y);
    		d^=getxor(pre[f2]-1)^getxor(pre[y]);
    		y=fa[f2];
    	}
    	if(d==0)printf("No
    ");
    	else printf("Yes
    ");
    }
    void change(int x,int y){
    	add(pre[x],v[x]);
    	add(pre[x],y);
    	v[x]=y;
    }
    int main(){
    	freopen(FILE".in","r",stdin);
    	freopen(FILE".out","w",stdout);
    	n=read();
    	up(i,1,n)v[i]=read();
    	up(i,2,n){
    		int x=read(),y=read();
    		insert(x,y);
    		insert(y,x);
    	}
    	dfs1(1);
    	top[1]=1;
    	dfs2(1);
    	up(i,1,n)add(pre[i],v[i]);
    	m=read();
    	up(i,1,m){
    		char ch;
    		scanf(" %c",&ch);
    		int x=read(),y=read();
    		if(ch=='Q')query(x,y);
    		else change(x,y);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    单例模式
    简单的WPS二次开发脚本
    使用DevExpress改变WinForm皮肤(VS)
    步入DevExpress的使用(VS)
    设置PdfPTable与标题间的距离
    tar: Removing leading `/’ from member names
    MySQL关闭过程详解和安全关闭MySQL的方法
    Nikto是一款Web安全扫描工具,可以扫描指定主机的web类型,主机名,特定目录,cookie,特定CGI漏洞,XSS漏洞,SQL注入漏洞等,非常强大滴说。。。
    解决Centos关闭You have new mail in /var/spool/mail/root提示
    hping3命令
  • 原文地址:https://www.cnblogs.com/chadinblog/p/6543015.html
Copyright © 2020-2023  润新知