传送门

又是权限题= =,过了NOIp我就要去当一只权限狗!

LCT裸题,get到了两个小姿势。

1.LCA操作应该在access中随时updata

2.Link操作可以更简单

void Link(int noda,int nodb){Reverse(noda);t[noda].fa=nodb;}
 //BZOJ 3282
 //by Cydiater
 //2016.9.16
 #include <iostream>
 #include <cstdio>
 #include <cstring>
 #include <algorithm>
 #include <queue>
 #include <map>
 #include <ctime>
 #include <cmath>
 #include <iomanip>
 #include <cstdlib>
 #include <string>
 using namespace std;
 #define ll long long
 #define up(i,j,n)        for(int i=j;i<=n;i++)
 #define down(i,j,n)        for(int i=j;i>=n;i--)
 ;
 const int oo=0x3f3f3f3f;
 inline int read(){
     ,f=;
     ;ch=getchar();}
     +ch-';ch=getchar();}
     return x*f;
 }
 ;
 struct Tree{
     ],v,Xor,fa,tag;
 }t[MAXN];
 namespace solution{
     inline ]==node;}
     inline ]!=node&&t[t[node].fa].son[]!=node;}
     inline void updata(int node){
         if(node){
             t[node].Xor=t[node].v;
             ])t[node].Xor^=t[t[node].son[]].Xor;
             ])t[node].Xor^=t[t[node].son[]].Xor;
         }
     }
     inline void downit(int node){
         if(t[node].tag){
             t[t[node].son[]].tag^=;t[t[node].son[]].tag^=;
             swap(t[node].son[],t[node].son[]);
             t[node].tag=;
         }
     }
     void rotate(int node){
         int old=t[node].fa,oldf=t[old].fa,which=get(node);
         ]==old]=node;
         t[old].son[which]=t[node].son[which^];t[t[old].son[which]].fa=old;
         t[node].son[which^]=old;t[old].fa=node;t[node].fa=oldf;
         updata(old);updata(node);
     }
     void splay(int node){
         top=;q[++top]=node;
         for(int i=node;!isroot(i);i=t[i].fa)q[++top]=t[i].fa;
         down(i,top,)downit(q[i]);
         while(!isroot(node)){
             int old=t[node].fa,oldf=t[old].fa;
             if(!isroot(old))rotate(get(node)==get(old)?old:node);
             rotate(node);
         }
     }
     void access(int node){
         ;
         while(node){
             splay(node);
             t[node].son[]=tmp;
             updata(node);tmp=node;
             node=t[node].fa;
         }
     }
     ;}
     void Link(int noda,int nodb){Reverse(noda);t[noda].fa=nodb;}
     ]==nodea)t[nodb].son[]=t[noda].fa=;}
     void LCA(int noda,int nodb){Reverse(nodb);access(noda);splay(noda);}
     int find(int node){
         access(node);splay(node);
         int tmp=node;
         ])tmp=t[tmp].son[];
         return tmp;
     }
     void change(int node,int num){
         access(node);splay(node);//down lazy_tag
         t[node].v=num;updata(node);
     }
     //Link-Cut-Tree
     void init(){
         N=read();M=read();
         up(i,,N){
             t[i].v=read();
             t[i].son[]=t[i].son[]=;
             t[i].Xor=t[i].v;t[i].fa=;
         }
     }
     void slove(){
         while(M--){
             op=read();
             ){
                 nodea=read();nodeb=read();
                 LCA(nodea,nodeb);printf("%d\n",t[nodea].Xor);
             }
             ){
                 nodea=read();nodeb=read();
                 if(find(nodea)==find(nodeb))continue;
                 Link(nodea,nodeb);
             }
             ){
                 nodea=read();nodeb=read();
                 if(find(nodea)!=find(nodeb))continue;
                 Cut(nodea,nodeb);
             }
             ){
                 node=read();num=read();
                 change(node,num);
             }
         }
     }
 }
 int main(){
     //freopen("input.in","r",stdin);
     using namespace solution;
     init();
     slove();
     ;
 }

BZOJ3282: Tree的更多相关文章

  1. BZOJ3282——Tree

    1.题目大意:动态树问题,点修改,链查询xor和 裸题一道.. #include <stack> #include <cstdio> #include <cstdlib& ...

  2. BZOJ-3282 Tree Link-Cut-Tree(似乎树链剖分亦可)

    蛋蛋用链剖A的,我写的LCT 3282: Tree Time Limit: 30 Sec Memory Limit: 512 MB Submit: 1241 Solved: 542 [Submit][ ...

  3. [bzoj3282]Tree (lct)

    昨天看了一天的lct..当然幸好最后看懂了(也许吧..) 论善良学长的重要性T_T,老司机带带我! 这题主要是删边的时候还要判断一下..蒟蒻一开始天真的以为存在的边才能删结果吃了一发wa... 事实是 ...

  4. BZOJ3282: Tree (LCT模板)

    Description 给定N个点以及每个点的权值,要你处理接下来的M个操作. 操作有4种.操作从0到3编号.点从1到N编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor和 ...

  5. 【学习心得】Link-cut Tree

    Link-cut Tree是一种支持改变树(森林)的形态(link和cut),同时维护树的路径上节点信息的数据结构.lct通过splay来维护每次的perferred path,说白了就是一个动态的树 ...

  6. AHOI2018训练日程(3.10~4.12)

    (总计:共90题) 3.10~3.16:17题 3.17~3.23:6题 3.24~3.30:17题 3.31~4.6:21题 4.7~4.12:29题 ZJOI&&FJOI(6题) ...

  7. 【BZOJ3282】Tree (Link-Cut Tree)

    [BZOJ3282]Tree (Link-Cut Tree) 题面 BZOJ权限题呀,良心luogu上有 题解 Link-Cut Tree班子提 最近因为NOIP考炸了 学科也炸了 时间显然没有 以后 ...

  8. 【BZOJ3282】Tree LCT

    1A爽,感觉又对指针重怀信心了呢= =,模板题,注意单点修改时splay就好,其实按吾本意是没写的也A了,不过应该加上能更好维护平衡性. ..还是得加上好= = #include <iostre ...

  9. 【bzoj3282】Tree

    LCT模板题: 话说xor和的意思是所有数xor一下: #include<iostream> #include<cstdio> #include<cstring> ...

随机推荐

  1. C#操作Excel时的格式设定(转)

    Excel报表打印的格式设定 1.     表头的设置 Excel._Worksheet myWorksheet; myWorksheet.PageSetup.Orientation = Excel. ...

  2. Log4net使用(二)

    日志记录到根目录Log文件夹,文件夹中分LogError与LogInfo文件夹 web.config配置: <configSections> <section name=" ...

  3. 【JavaEE企业应用实战学习记录】struts国际化

    <%-- Created by IntelliJ IDEA. User: Administrator Date: 2016/10/6 Time: 16:26 To change this tem ...

  4. Beta版本冲刺Day2

    会议讨论 628:       和建平同学一起合作解决了如何获取勾选事件,将勾选的课程信息存入select表格中.但是当运行更新后的项目遇到了无法连接数据库的问题了,目前还在解决中. 因为碰到了这样的 ...

  5. jq实现登陆页面的拖拽功能

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <script src ...

  6. iSCSI 与 ceph

    SCSI  小型计算机系统接口(SCSI,Small Computer System Interface)是一种用于计算机及其周边设备之间(硬盘.软驱.光驱.打印机.扫描仪等)系统级接口的独立处理器标 ...

  7. python 登陆接口

    #!/usr/bin/env pythonimport sysname = ''pw=''name_num = 0pw_num = 0#black_list = []with open('a.txt' ...

  8. 【BZOJ 1455】罗马游戏

    左偏树模板 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ...

  9. Entity Framework Code First (一)Conventions

    Entity Framework 简言之就是一个ORM(Object-Relational Mapper)框架. Code First 使得你能够通过C#的类来描述一个模型,模型如何被发现/检测就是通 ...

  10. C#-数据库访问技术 ado.net——创建 数据库连接类 与 数据库操作方法 以及简单的数据的添加、删除、修改、查看

    数据库访问技术 ado.net 将数据库中的数据,提取到内存中,展示给用户看还可以将内存中的数据写入数据库中去 并不是唯一的数据库访问技术,但是它是最底层的数据库访问技术 1.创建数据库,并设置主外键 ...