#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define loop(n,i) for(register int i=1;i<=(n);++i)
#define zxc(x) cout<<(#x)<<'='<<(x)<<'\n'
#define zxcv(x) cout<<(#x)<<'='<<(x)<<','
#define MAX 3
using namespace std;
inline int icin() {
int s=0;bool sign=0;char c=getchar();
while(!isdigit(c)&&c^'-')c=getchar();
if(c=='-')c=getchar();
while(isdigit(c))s=(s<<1)+(s<<3)+c-'0',c=getchar();
return sign?-s:s;
}
int c[MAX][2],f[MAX],rev[MAX],sum[MAX],val[MAX];
struct LCT{
inline bool IsRoot(int x){return (c[f[x]][0]^x)&&(c[f[x]][1]^x);}
inline void upload(int x){
sum[x]=sum[c[x][0]]+sum[c[x][1]]+val[x];
}
inline void download(int x){
if(rev[x]){
rev[c[x][0]]^=1,rev[c[x][1]]^=1;rev[x]^=1;
swap(c[x][0],c[x][1]);
}
}
inline void Rot(int x){
int fa=f[x],gf=f[fa],s=c[fa][1]==x,sn=c[x][s^1];
if(!IsRoot(fa)) c[gf][c[gf][1]==fa]=x;f[x]=gf;
f[c[fa][s]=sn]=fa,f[c[x][s^1]=fa]=x;
upload(fa);
}
inline void Splay(int x){
download(x);
while(!IsRoot(x)){
int fa=f[x],gf=f[fa];
download(gf),download(fa),download(x);
if(!IsRoot(fa)) (c[gf][1]==fa)==(c[fa][1]==x)?Rot(fa):Rot(x);
Rot(x);
}
upload(x);
}
inline void Access(int x){
int y=0;
while(x){
Splay(x);
c[x][1]=y;
upload(x);
y=x,x=f[x];
}
}
inline void MakeRoot(int x){Access(x),Splay(x),rev[x]^=1;}
inline void Link(int x,int y){MakeRoot(x),f[x]=y;}
inline void GetChain(int x,int y){MakeRoot(x),Access(y),Splay(y);}
}L;
int plus(int a, int b)
{
val[1]=icin(),val[2]=icin();
L.Link(1,2);
L.GetChain(1,2);
return sum[2];
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 10 us | 32 KB | Time Limit Exceeded | Score: 0 | 显示更多 |