求助qaq 对拍全都一样的 样历过了 交上去全wa
查看原帖
求助qaq 对拍全都一样的 样历过了 交上去全wa
264821
ningexe楼主2021/5/11 02:02
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200001;
int n, q, a[maxn], aa[maxn], ba, l = 1, r = 0, ti = 0, lc[maxn], rc[maxn], x, xx, cnt, cnt1, su, an[maxn], b[maxn * 5];
char o[2];
struct p {
	int l, r, n, xl, xr, t;
}e[maxn];
struct pp {
	int n, x, y;
}c[maxn];
bool cmp(const p& i, const p& j) {
	return i.xl == j.xl ? (i.xr != j.xr ? (i.xl & 1 ? i.r > j.r : i.r < j.r) : i.t < j.t) : i.xl < j.xl;
}
void add(int x) {
	su += !b[a[x]]++;
}
void del(int x) {
	su -= !--b[a[x]];
}
void adt(int l, int r, int t) {
	int x = c[t].n;
	if (l <= x && x <= r)
		su -= !--b[a[x]];
	a[x] = c[t].y;
	if (l <= x && x <= r)
		su += !b[a[x]]++;
}
void det(int l, int r, int t) {
	int x = c[t].n;
	if (l <= x && x <= r)
		su -= !--b[a[x]];
	a[x] = c[t].x;
	if (l <= x && x <= r)
		su += !b[a[x]]++;
}
signed main() {
	scanf("%d%d", &n, &q);
	ba = pow(n + 0.1, 2.0 / 3);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]), aa[i] = a[i];
	for (int i = 1; i <= q; i++) {
		scanf("%s %d %d", o, &lc[cnt], &rc[cnt]);
		if (o[0] == 'Q') {
			e[cnt++] = { lc[cnt],rc[cnt],cnt,lc[cnt] / ba,rc[cnt] / ba,cnt1 };
		}
		else
			x=lc[cnt], xx=rc[cnt],c[++cnt1] = { x,aa[x],xx }, aa[x] = xx;
	}
	sort(e, e + cnt, cmp);
	for (int i = 0; i < cnt; i++) {
		while (r < e[i].r)
			add(++r);
		while (r > e[i].r)
			del(r--);
		while (l < e[i].l)
			del(l++);
		while (l > e[i].l)
			add(--l);
		while (ti < e[i].t)
			adt(l, r, ++ti);
		while (ti > e[i].t)
			det(l, r, ti--);
		an[e[i].n] = su;
	}
	for (int i = 0; i < cnt; i++)
		printf("%d\n", an[i]);
}
2021/5/11 02:02
加载中...