蒟蒻刚刚学习OI一秒, 求大佬给调一下代码,我是真的崩溃了
查看原帖
蒟蒻刚刚学习OI一秒, 求大佬给调一下代码,我是真的崩溃了
435312
Security_Guard楼主2021/9/10 19:24

自己造的数据and样例都能过,但是一交就全WA掉.

#include <iostream>
#include <cstdio>

using namespace std;
const int N = 2e5 + 5;

int n, m, p;

struct bal {
	int sum;
	int lazy;
	int l, r;
};
bal t[N<<2];

int re() {
	int x = 0, f = 1;
	char ch = getchar();
	while(ch < '0'||ch > '9') {
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while (ch <= '9'&&ch >= '0') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}

void update(int p) {
	t[p].sum = t[p << 1].sum | t[p << 1 | 1].sum;
}

void pushdown(int p) {
	if(t[p].lazy) {
		t[p << 1].sum = (1 << t[p].lazy);
		t[p << 1 | 1].sum = (1 << t[p].lazy);
		t[p << 1].lazy = t[p].lazy;
		t[p << 1 | 1].lazy = t[p].lazy;
		t[p].lazy = 0;
	}
}

void build(int p, int l, int r) {
	if(l <= 0||r > n) return ;
	t[p].l = l, t[p].r = r;
	if(l == r) {
		t[p].sum = 1;
		return ;
	}
	int mid = (l + r) >> 1;
	build(p << 1, l, mid);
	build(p << 1 | 1, mid + 1, r);
	update(p);
}

void change(int p, int l, int r, int val) {
	if(t[p].l > r ||t[p].r < l)
		return ;
	if(t[p].l >= l&&t[p].r <= r) {
		t[p].sum = (1 << val);
		t[p].lazy = val;
		return ;
	}
	pushdown(p);
	int mid = (t[p].l + t[p].r) >> 1;
	if(mid >= l) change(p << 1, l, r, val);
	if(mid < r) change(p << 1 | 1, l, r, val);
	update(p);
}

int query(int p, int l, int r) {
	if(t[p].l > r||t[p].r < l)
		return 0;
	if(t[p].l >= l&&t[p].r <= r)
		return t[p].sum;
	pushdown(p);
	int ans = 0;
	int mid = (t[p].l + t[p].r) >> 1;
	if(mid >= l) ans |= query(p << 1, l, r);
	if(mid < r) ans |= query(p << 1 | 1, l, r);
	return ans;
}

int main() {
	char op;
	int a, b, c;
	n = re(); p = re(); m = re();
	build(1, 1, n);
	while(m --) {
		cin >> op;
		while (op < 'A'||op > 'Z') op = getchar();
		if(op == 'C') {
			a = re(); b = re(); c = re();
			change(1, a, b, c);	
		}
		else {
			int ans = 0;
			a = re(); b = re();
			if(a > b) swap(a, b);
			int s = query(1, a, b);
			for(int i = 1; i <= p; i++) {
				if(s & (1 << i))
					ans ++ ;
			}
			printf("%d\n",ans);
		}
	}
	return 0;
}

/*
5 4 8
C 1 3 4
P 2 4
C 2 5 2
P 1 2
C 2 3 3
C 3 5 1
P 1 5
P 2 4 
*/
2021/9/10 19:24
加载中...