似乎有些人类似30个线段树的做法可以通过,但是我这个为什么会MLE呢?实在是搞不明白了,请求大佬帮助
#include<iostream>
#include<algorithm>
#define lc p<<1
#define rc p<<1|1
using namespace std;
const int maxn = 31;
const int N = 1E5 + 3;
struct Node {
int l, r, s, one, zero;
}t[maxn][N << 2];
void pushdown(int p, int i) {
if (t[i][p].one) {
t[i][lc].s = 1;
t[i][rc].s = 1;
t[i][lc].one = 1; t[i][rc].one = 1;
t[i][p].one = 0;
t[i][lc].zero = 0; t[i][rc].zero = 0;
t[i][p].zero = 0;
}
if (t[i][p].zero) {
t[i][lc].s = 0;
t[i][rc].s = 0;
t[i][lc].zero = 1; t[i][rc].zero = 1;
t[i][p].zero = 0;
t[i][lc].one = 0; t[i][rc].one = 0;
t[i][p].one = 0;
}
}
void pushup(int p, int i) {
if (t[i][lc].s || t[i][rc].s) {
t[i][p].s = 1;
}
else t[i][p].s = 0;
}
void build(int p, int i, int l, int r) {
if (i == 1) {
t[i][p] = { l,r,1,0,0 };
}
else {
t[i][p] = { l,r,0,0,0 };
}
if (l == r)return;
int mid = l + r >> 1;
build(lc, i, l, mid);
build(rc, i, mid + 1, r);
pushup(p, i);
}
void update(int p, int i, int l, int r, int k) {
if (l > t[i][p].r || r < t[i][p].l) return;
if (l <= t[i][p].l && t[i][p].r <= r) {
if (k) {//1
t[i][p].s = k;
t[i][p].one = 1;
t[i][p].zero = 0;
}
else {
t[i][p].s = k;
t[i][p].one = 0;
t[i][p].zero = 1;
}
return;
}
pushdown(p, i);
update(lc, i, l, r, k);
update(rc, i, l, r, k);
pushup(p, i);
}
int query(int p, int i, int l, int r) {
if (l > t[i][p].r || r < t[i][p].l) return 0;
if (l <= t[i][p].l && t[i][p].r <= r) {
return t[i][p].s;
}
pushdown(p, i);
if (query(lc, i, l, r) || query(rc, i, l, r)) {
return 1;
}
else return 0;
}
void solve() {
int n, cnt, m;
cin >> n >> cnt >> m;
for (int i = 1; i <= cnt; i++) {
build(1, i, 1, n);
}
for (int i = 1; i <= m; i++) {
char s; cin >> s;
if (s == 'C') {
int a, b, c; cin >> a >> b >> c;
if (a > b)swap(a, b);
update(1, c, a, b, 1);
for (int j = 1; j <= cnt; j++) {
if (j != c) {
update(1, j, a, b, 0);
}
}
}
else {
int a, b; cin >> a >> b;
if (a > b)swap(a, b);
int ans = 0;
for (int j = 1; j <= cnt; j++) {
ans += query(1, j, a, b);
}cout << ans << endl;
}
}
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
return 0;
}