2002: [hnoi2010] bounce time limit: 10 sec memory limit: 259 MB
Submit: 4055 solved: 2172
[Submit] [Status] Description
One day, lostmonkey invented a super elastic device. He invited little sheep to play a game in order to show it in front of his friends. At the beginning of the game, lostmonkey placed n devices along a straight line on the ground, each of which sets the initial elasticity factor Ki. When the sheep reach the I device, it will play the ki step back, reaches the I + Ki device. If the I + Ki device does not exist, the sheep will fly. The sheep wanted to know that when it started from the I device, it would fly after several rounds. To make the game more interesting, lostmonkey can modify the elasticity coefficient of a certain stretch device. The elasticity coefficient is a positive integer at any time.
Input
The first line contains an integer N, indicating that there are n devices on the ground. The device number ranges from 0 to n-1, And the next line contains n positive integers, the initial elasticity coefficient of the N devices in turn. The third row has a positive integer m, and the next row of M has at least two numbers I and J. If I = 1, you need to output the data to be played several times from J and then fly, if I = 2, a positive integer k is input, indicating that the coefficient of the J-step elastic device is changed to K. For 20% of Data n, m <= 10000, for 100% of Data n <= 200000, m <= 100000
Output
For each I = 1, you need to output a required number of steps, occupying one row.
Sample input4
1 2 1 1
3
1 1
2 1 1
1 1
Sample output2
3
The first time the hint executes LCT, it mainly follows the standards on the Internet. The main idea of LCT is to create a splay for each other, the clever thing is that splay's PNT [] refers to the kernel. For the corresponding root nodes on the current kernel, PNT refers to the kernel equivalent to the top finger in the segmentation, in this way, the relationship between each shard in the splay forest can be cleverly reflected. This LCT supports linear regression and regression.
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<ctime>#include<cmath>#include<algorithm>#include<set>#include<map>#include<vector>#include<string>#include<queue>using namespace std;#ifdef WIN32#define LL "%I64d"#else#define LL "%lld"#endif#define MAXN 310000#define MAXV MAXN*2#define MAXE MAXV*2#define INF 0x3f3f3f3f#define INFL 0x3f3f3f3f3f3f3f3fLL//ACtypedef long long qword;inline int nextInt(){ char ch; int x=0; bool flag=false; do ch=(char)getchar(),flag=(ch==‘-‘)?true:flag; while(ch<‘0‘||ch>‘9‘); do x=x*10+ch-‘0‘; while (ch=(char)getchar(),ch<=‘9‘ && ch>=‘0‘); return x*(flag?-1:1);}int n,m;int ch[MAXN][2],pnt[MAXN];int siz[MAXN];bool rt[MAXN];bool is_root(int cur){ return pnt[cur]==0 || (cur!=ch[pnt[cur]][0] && cur!=ch[pnt[cur]][1]);}void push_up(int cur){ siz[cur]=siz[ch[cur][0]]+siz[ch[cur][1]]+1;}void rotate(int cur){ int p=pnt[cur],anc=pnt[p]; int dir=ch[p][0]==cur; if (!is_root(p)) ch[anc][ch[anc][1]==p]=cur; pnt[cur]=anc; pnt[ch[cur][dir]]=p; ch[p][1-dir]=ch[cur][dir]; ch[cur][dir]=p; pnt[p]=cur; push_up(p); push_up(cur);}//int stack[MAXN];void splay(int cur){ int now; /* int tops=-1; now=cur; while (pnt[now]) stack[++tops]=now; int i; for (i=tops;i>=0;i--) push_down(i); *///本題不用打標記 while (!is_root(cur)) { int p=pnt[cur],anc=pnt[p]; if (is_root(pnt[cur])) rotate(cur); else if ( (ch[p][1]==cur) == (ch[anc][1]==p) ) rotate(p),rotate(cur);//Attention! else rotate(cur),rotate(cur); } push_up(cur);}void Access(int cur){ int son=0; for (;cur;cur=pnt[son=cur]) { splay(cur); ch[cur][1]=son; push_up(cur); }}int a[MAXN];int main(){ freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int i,j,k; int x,y,z; scanf("%d",&n); for (i=1;i<=n;i++) { scanf("%d",&a[i]); } for (i=1;i<=n;i++) siz[i]=1; siz[n+1]=1; for (i=1;i<=n;i++) { int t=i+a[i]; if (t>n+1)t=n+1; pnt[i]=t;//初始化時不存在重鏈 } scanf("%d",&m); int opt; while (m--) { scanf("%d",&opt); if (opt==1) { scanf("%d",&x); x++;//編號從0開始 Access(x); splay(x);//保證siz[x]包含整棵子樹 printf("%d\n",siz[x]-1); //printf("%d\n",siz[ch[x][0]]); 二者等價 }else { scanf("%d%d",&x,&y); x++; Access(x); splay(x);//意味着ch[x][1]==null //此時pnt[x]不在這顆splay上 pnt[ch[x][0]]=pnt[x]; pnt[x]=0; ch[x][0]=0; push_up(x);//對於x即其子節點有所改動時使用 int t=x+y;; if (t>n+1)t=n+1; pnt[x]=t; } } return 0;}
Bzoj 2002: [hnoi2010] bounce