-
个人简介
世上最难题a+b题解:(新oj有效)
#include<iostream> #include<cstring> #include<cstdio> #include<cstring> using namespace std; struct node { int data,rev,sum; node *son[2],*pre; bool judge(); bool isroot(); void pushdown(); void update(); void setson(node *child,int lr); }lct[233]; int top,a,b; node *getnew(int x) { node *now=lct+ ++top; now->data=x; now->pre=now->son[1]=now->son[0]=lct; now->sum=0; now->rev=0; return now; } bool node::judge(){return pre->son[1]==this;} bool node::isroot() { if(pre==lct)return true; return !(pre->son[1]==this||pre->son[0]==this); } void node::pushdown() { if(this==lct||!rev)return; swap(son[0],son[1]); son[0]->rev^=1; son[1]->rev^=1; rev=0; } void node::update(){sum=son[1]->sum+son[0]->sum+data;} void node::setson(node *child,int lr) { this->pushdown(); child->pre=this; son[lr]=child; this->update(); } void rotate(node *now) { node *father=now->pre,*grandfa=father->pre; if(!father->isroot()) grandfa->pushdown(); father->pushdown();now->pushdown(); int lr=now->judge(); father->setson(now->son[lr^1],lr); if(father->isroot()) now->pre=grandfa; else grandfa->setson(now,father->judge()); now->setson(father,lr^1); father->update();now->update(); if(grandfa!=lct) grandfa->update(); } void splay(node *now) { if(now->isroot())return; for(;!now->isroot();rotate(now)) if(!now->pre->isroot()) now->judge()==now->pre->judge()?rotate(now->pre):rotate(now); } node *access(node *now) { node *last=lct; for(;now!=lct;last=now,now=now->pre) { splay(now); now->setson(last,1); } return last; } void changeroot(node *now) { access(now)->rev^=1; splay(now); } void connect(node *x,node *y) { changeroot(x); x->pre=y; access(x); } void cut(node *x,node *y) { changeroot(x); access(y); splay(x); x->pushdown(); x->son[1]=y->pre=lct; x->update(); } int query(node *x,node *y) { changeroot(x); node *now=access(y); return now->sum; } int main() { scanf("%d%d",&a,&b); node *A=getnew(a); node *B=getnew(b); //连边 Link connect(A,B); //断边 Cut cut(A,B); //再连边orz Link again connect(A,B); printf("%d\n",query(A,B)); return 0; } -
通过的题目
- 1268
- JX3009
- J1019
- 1350
- 1354
- 1355
- 1427
- 1429
- 1452
- 1531
- 1651
- 1704
- 1768
- J1829
- 2048
- 2328
- JX3008
- 2416
- 2423
- 2593
- 2623
- J1010
- J1011
- 2703
- J1012
- 2718
- 2719
- 2721
- SC2024SD7T1
- SC2024SD7T2
- SC2024SD7T3
- SC2024SD7T4
- SC2024SD7T5
- SC2024SD7T6
- SC2024SD7T7
- SC2024SD7T8
- SC2024SD7T9
- SC2024SD7T10
- SC2024SD7T11
- SC2024SD7T12
- SC2024SD7T13
- SC2024SD7T14
- JX2007
- 2960
- 2973
- 2975
- 2978
- jx202506
- jx202503
- JXGQ2pt024
- JXGQ2pt021
- JX3007
- 3132
- 3151
- 3159
- JXGQ2pt007
- JXGQ2pt017
- 3301
- J1002
- J1004
- J1006
- JX3006
- J1021
- J1023
- JX3001
- JX4001
- JX2029
- J1033
- J1034
- J1035
- J1036
- 3523
- J1040
- J1041
- J1042
- J1043
- J1045
- J1049
- JX6001
- JX4800
- ABC002B
- JX4804
- JX8888
- P2395
- ABC003A
- ABC002A
- ABC005A
- ABC004A
- ABC006A
- ABC007A
- ABC001A
-
最近活动
- 提高组 Week 29 - 数论杂题选讲 作业
- 乔斯2025集训队第二十一次周赛 IOI
- 乔斯2025预备队第二十一次周赛 IOI
- 乔斯2025预备队第十九次周赛 IOI
- 乔斯2025集训队第十五次周赛 IOI
- 乔斯2025预备队第十五次周赛 IOI
- 乔斯2025集训队第十四次周赛 IOI
- CSP-S2 2020 ACM/ICPC
- 2024国庆线下复赛集训模拟赛(五) ACM/ICPC
- 提高组国庆 Day2 - 数据结构 作业
- 综合测试比赛 IOI
- 全真模拟赛(七) OI
- 全真模拟赛(一) OI
- 北京线下营入营分班测3(第三期) IOI
- 北京线下营入营分班测2(第三期) IOI
- 北京线下营入营分班测1(第三期) IOI
- 线上第2期--D5 深搜广搜 作业
- 2025C++暑期集训营入营测试 IOI
题目标签
- 入门
- 136
- 语法基础
- 86
- 基础
- 60
- 基本运算
- 53
- 循环
- 45
- 分支
- 42
- 数学
- 17
- 普及-
- 13
- 字符串
- 9
- 进阶
- 6
- 算法基础
- 5
- 模拟算法
- 4
- T1
- 3
- 一维数组
- 3
- 枚举
- 3
- 排序
- 2
- 思维题
- 2
- 二维数组
- 2
- 思维
- 2
- 拓扑排序
- 1