Ejemplo n.º 1
0
int main() {
	int i;
	int RES;
	int L, T, O;
	int A, B, C;
	char str[5];
	scanf("%d%d%d", &L, &T, &O);
	build_tree(1, L, 1);
	while(O--) {
		scanf("%s", str);
		if(str[0] == 'C') {
			scanf("%d%d%d", &A, &B, &C);
			if (A <= B)
				change_tree(A, B, 1, L, C, 1);
			else
				change_tree(B, A, 1, L, C, 1);
		}
		else {
			scanf("%d%d", &A, &B);
			RES = num = 0;
			if (A <= B)
				search_tree(A, B, 1, L, 1);
			else 
				search_tree(B, A, 1, L, 1);
			for(i = 0; i < T; i++) {
				if(num & 1)
					RES++;
				num >>= 1;
			}
			printf("%d\n", RES);
		}
	}
	return 0;
}
Ejemplo n.º 2
0
void change_tree (BiTree * root)
{
	BiTree * tmp;

	tmp = (BiTree *)malloc(sizeof(BiTree));

	if (root == NULL)
	{
		return ;
	}

	if (root != NULL)
	{
		tmp = root->Lchild;
		root->Lchild = root->Rchild;
		root->Rchild = tmp;
	}

	change_tree(root->Lchild);
	change_tree(root->Rchild);
}
Ejemplo n.º 3
0
void change_tree(int left, int right, int tleft, int tright, int col, int i) {
	if(left == tleft && right == tright) {
		result[i][0] = 1 << (col - 1);
		result[i][1] = col;
		return ;
	}
	if(result[i][1]) {
		result[i << 1][1] = result[i << 1 | 1][1] = result[i][1];
		result[i << 1][0] = 1 << (result[i << 1][1] - 1);
		result[i << 1 | 1][0] = 1 << (result[i << 1 | 1][1] - 1);
		result[i][1] = 0;
	}
	int mid = (tleft + tright) >> 1;
	if(right <= mid)
		change_tree(left, right, tleft, mid, col, i << 1);
	else if(left >= mid + 1)
		change_tree(left, right, mid + 1, tright, col, i << 1 | 1);
	else {
		change_tree(left, mid, tleft, mid, col, i << 1);
		change_tree(mid + 1, right, mid + 1, tright, col, i << 1 | 1);
	}
	result[i][0] = result[i << 1][0] | result[i << 1 | 1][0];
}