已知:全WA
求:为啥
解:代码如下:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 133333 + 10;
int B;
struct Q {
int l, r, t, id;
bool operator < (const Q &b) const {
if (l / B == b.l / B) {
if (r / B == b.r / B) return t < b.t;
else return r / B < b.r / B;
} else return l / B < b.l / B;
}
} q[MAXN];
struct M {
int p, x, y;
} md[MAXN];
int a[MAXN], n, m, k, tim;
int tans, ans[MAXN], cnt[MAXN], b[MAXN], fint[MAXN];
int l = 1, r = 0, t = 0;
inline void update(int x, int f) {
cnt[x] += f;
if (cnt[x] == 0 && f == -1) tans--;
if (cnt[x] == 1 && f == 1) tans++;
}
inline void updateTime(int t, int f) {
if (f == 1) {
if (l <= md[t].p && md[t].p <= r) {
update(md[t].x, -1);
update(md[t].y, 1);
}
a[md[t].p] = md[t].y;
} else {
if (l <= md[t].p && md[t].p <= r) {
update(md[t].y, -1);
update(md[t].x, 1);
}
a[md[t].p] = md[t].x;
}
}
inline int read() {
register int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int main() {
n = read(); m = read();
B = (int)(pow(n, 2.0 / 3));
for (int i = 1; i <= n; i++) {
a[i] = read();
b[i] = a[i];
}
for (int i = 1; i <= m; i++) {
scanf("\n");
if (getchar() == 'Q') {
int l = read(), r = read();
q[++k] = {l, r, tim, k};
} else {
int l = read(), r = read();
md[++tim] = {l, b[l], r};
b[l] = r;
}
}
sort(q + 1, q + k + 1);
for (int i = 1; i <= k; i++) {
while (t < q[i].t) updateTime(++t, 1);
while (t > q[i].t) updateTime(t--, -1);
while (l < q[i].l) update(a[l++], -1);
while (l > q[i].l) update(a[--l], 1);
while (r < q[i].r) update(a[++r], 1);
while (r > q[i].r) update(a[r--], -1);
ans[q[i].id] = tans;
}
for (int i = 1; i <= k; i++) printf("%d\n", ans[i]);
return 0;
}
答:有巨佬能够解答吗?