勉强算是结了个大坑吧或者才开始

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); (a) <= (c); ++(a))
#define nR(a,b,c) for(register int a = (b); (a) >= (c); --(a))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Swap(a,b) ((a) ^= (b) ^= (a) ^= (b))
#define ll long long
#define u32 unsigned int
#define u64 unsigned long long #define ON_DEBUGG #ifdef ON_DEBUGG #define D_e_Line printf("\n----------\n")
#define D_e(x) cout << (#x) << " : " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt", "r", stdin)
#define FileSave() freopen("out.txt", "w", stdout)
#include <ctime>
#define TIME() fprintf(stderr, "\ntime: %.3fms\n", clock() * 1000.0 / CLOCKS_PER_SEC) #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ;
#define FileSave() ;
#define TIME() ;
//char buf[1 << 21], *p1 = buf, *p2 = buf;
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++) #endif using namespace std;
struct ios{
template<typename ATP>inline ios& operator >> (ATP &x){
x = 0; int f = 1; char ch;
for(ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
while(ch >= '0' && ch <= '9') x = x * 10 + (ch ^ '0'), ch = getchar();
x *= f;
return *this;
}
}io; template<typename ATP>inline ATP Max(ATP a, ATP b){
return a > b ? a : b;
}
template<typename ATP>inline ATP Min(ATP a, ATP b){
return a < b ? a : b;
}
template<typename ATP>inline ATP Abs(ATP a){
return a < 0 ? -a : a;
} const int N = 300007; struct node {
int ch[2], fa, val, sum;
bool rev;
}t[N];
#define ls t[u].ch[0]
#define rs t[u].ch[1] inline bool Ident(int u) {
return t[t[u].fa].ch[1] == u;
} inline bool IsRoot(int u) {
return t[t[u].fa].ch[0] != u && t[t[u].fa].ch[1] != u;
} inline void Pushup(int u) {
t[u].sum = t[u].val ^ t[ls].sum ^ t[rs].sum;
} inline void Pushrev(int u) {
Swap(t[u].ch[0], t[u].ch[1]);
t[u].rev ^= 1;
} inline void Pushdown(int u) {
if(!t[u].rev) return;
if(t[u].ch[0]) Pushrev(t[u].ch[0]);
if(t[u].ch[1]) Pushrev(t[u].ch[1]);
t[u].rev = 0;
} int sta[N], top; inline void Rotate(int x) {
int y = t[x].fa, z = t[y].fa, k = Ident(x);
t[x].fa = z; if(!IsRoot(y)) t[z].ch[Ident(y)] = x;
t[y].ch[k] = t[x].ch[k ^ 1], t[t[x].ch[k ^ 1]].fa = y;
t[x].ch[k ^ 1] = y, t[y].fa = x;
Pushup(y), Pushup(x);
} inline void Splay(int u) {
int x = u;
top = 0;
while(!IsRoot(u)) {
sta[++top] = u;
u = t[u].fa;
}
sta[++top] = u;
nR(i,top,1){
Pushdown(sta[i]);
}
while(!IsRoot(x)) {
int y = t[x].fa;
if(!IsRoot(y)){
Ident(x) == Ident(y) ? Rotate(y) : Rotate(x);
}
Rotate(x);
}
Pushup(x);
} inline void Access(int u) {
for(int v = 0; u; v = u, u = t[u].fa){
Splay(u);
t[u].ch[1] = v;
Pushup(u);
}
} inline void MakeRoot(int u) {
Access(u);
Splay(u);
Pushrev(u);
} inline int FindRoot(int u) {
Access(u);
Splay(u);
while(ls) u = ls;
Splay(u);
return u;
} inline void Split(int u, int v) {
MakeRoot(u);
Access(v);
Splay(v);
} inline void Link(int u, int v) {
Split(u, v);
t[u].fa = v;
} inline void Cut(int u, int v){
MakeRoot(u);
if(FindRoot(v) == u && t[v].fa == u && !t[v].ch[0]){
t[v].fa = t[u].ch[1] = 0;
Pushup(u);
}
} inline void Modify(int u, int w) {
// Access(u);
Splay(u);
t[u].val = w;
Pushup(u);
} int main() {
//FileOpen();
//FileSave();
int n, m;
io >> n >> m;
R(i,1,n){
io >> t[i].val;
t[i].sum = t[i].val;
}
while(m--){
int opt, x, y;
io >> opt >> x >> y;
switch(opt){
case 0:
Split(x, y);
printf("%d\n", t[y].sum);
break;
case 1:
Link(x, y);
break;
case 2:
Cut(x, y);
break;
case 3:
Modify(x, y);
break;
}
}
return 0;
}

最新文章

  1. SQL日期相关的操作
  2. 序列化悍将Protobuf-Net,入门动手实录
  3. focus 、blur和focusin,focusout的区别
  4. 【py分析网页】可能有用的-re去除网页上的杂碎
  5. [资源] Resources on Self-Driving Car
  6. Java基础—异常处理总结
  7. hdu1159 LCS模板题
  8. Myeclipse8.5开发-安装一:Myeclipse8.5注册码生成程序
  9. EXCEL文本字符串转日期
  10. 【HNOI2016】树
  11. ORA-00600: internal error code, arguments: [2662]
  12. mysql官方驱动jar
  13. nrm 安装与npm镜像切换
  14. Weex小笔记(自己理解,有错请指正)
  15. 初学CSS-3-文字的属性
  16. Docker for windows 入门三(PowerShell命令使用)
  17. Web Scraping with Python
  18. LSTM(长短期记忆网络)及其tensorflow代码应用
  19. [原创]H5前端性能测试工具介绍
  20. MapReduce 找出共同好友

热门文章

  1. 从零搭建Pytorch模型教程(四)编写训练过程--参数解析
  2. MVC - Request对象的主要方法
  3. 运筹学笔记12 大M法
  4. 这个Spring Security登录插件牛啊,验证码、小程序、OAuth2都能快速接入
  5. Bika LIMS 开源LIMS集——实验室检验流程概述及主页、面板
  6. 想写个小说,关于C#的,名字就叫《原Csharp》吧 (第一回 买书未成炁自生 惶惶回屋遇老翁)
  7. 红包雨中:Redis 和 Lua 的邂逅
  8. RPA跨系统自动生成采购订单
  9. 关于nginx 和 uwsgi
  10. .NET程序配置文件操作(ini,cfg,config)