Esempio n. 1
0
void pushdown(int x) {
	if (!x) return;
	if (rev[x]) {
		std::swap(c[x][0], c[x][1]);
		rev[c[x][0]] ^= 1;
		rev[c[x][1]] ^= 1;
		rev[x] = 0;
	}
	if (flag[x]) {
		if (c[x][0]) makesame(c[x][0]);
		if (c[x][1]) makesame(c[x][1]);
		flag[x] = 0;
	}
}
Esempio n. 2
0
void solve(){
	char order[10];
	int k,i,j,x;
	scanf("%d",&q);
	for(; q; --q){
		scanf("%s",order);
		switch(order[0]){
			case 'R':
				scanf("%d",&k);
				rotate(k,n);
				break;
			case 'F':	
				flip(n);
				break;
			case 'S':
				scanf("%d%d",&i,&j);
				listswap(i-1,j-1);
				break;
			case 'P':
				scanf("%d%d%d",&i,&j,&x);
				if(j>=i)makesame(i-1, j-i+1, x);
				else{
					makesame(0, j, x);
					makesame(i-1, n-i+1, x);
				}
				break;
			case 'C':
				if(order[1]=='S'){
					scanf("%d%d",&i,&j);
					if(j>=i)printf("%d\n",countsegment(i-1, j-i+1));
					else{
						int res=countsegment(i-1, n-i+1);
						res+=countsegment(0,j);
						if(same_head_tail())--res;
						printf("%d\n",res);
					}
				}else	printf("%d\n",countcircle());
		}
	}
	fclose(stdin);
	fclose(stdout);
}
	void cover(int &rt, int l, int r, int x, int y) {
		if (r < x || l > y) return;
		alloc(rt);
		if (x <= l && r <= y) {
			makesame(rt, l, r);
			return;
		}
		pushdown(rt, l, r);
		cover(t[rt].l, l, l + r >> 1, x, y);
		cover(t[rt].r, (l + r >> 1) + 1, r, x, y);
		t[rt].d = t[t[rt].l].d + t[t[rt].r].d;
	}
Esempio n. 4
0
void connect(int x, int y) {
	if (getfa(x) == getfa(y)) {
		setroot(x);
		access(y);
		splay(y);
		makesame(y);
	}
	else{
		size++;
		d[size] = 1;
		link(x, size);
		link(y, size);
	}
}