求助:电脑和 IDE 上测评正常,但洛谷提交却 RE
查看原帖
求助:电脑和 IDE 上测评正常,但洛谷提交却 RE
159548
Zachary_Cloud楼主2021/5/29 13:29

代码:

#include <bits/stdc++.h>
using namespace std;

#define F(i,a,b) for(register int i=a;i<=b;++i)

typedef long long ll;
/*
static char buf[100000],*p1=buf,*p2=buf;
#define gc p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
ll read() {ll res=0,w=0;char c=gc;while (!isdigit(c)) w|=c=='-',c=gc;while (isdigit(c)) res=(res<<1)+(res<<3)+(c^48),c=gc;if (w) res=-res;return res;}
void write(ll x) {static int sta[50],top=0;if (x<0) putchar('-'),x=-x;do {sta[top++]=x%10,x/=10;}while (x);while (top) putchar(sta[--top]+48);}
*/
inline ll read() {ll res = 0, w = 0; char ch = 0;while (!isdigit(ch)) w |= ch == '-', ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return w ? -res : res;}
inline void write(ll x) {if (x < 0) putchar('-'), x = -x;if (x > 9) write(x / 10);putchar(x % 10 + '0');}

const int N = 140000;
int n, m, size, cnt_q, cnt_t, now, l = 1, r, t;
int a[N], blo[N], cnt[N], ans[N];
struct node {
	int l, r, id, t;
} q[N];
struct query {
	int id, col;
} c[N];

inline bool cmp(node a, node b) {
	return blo[a.l] ^ blo[b.l] ? blo[a.l] < blo[b.l] : blo[a.r] ^ blo[b.r] ? blo[a.r] < blo[b.r] : a.t < b.t;
}
inline void add(int x) {
	if (!cnt[x]) ++now;
	cnt[x]++;
}
inline void del(int x) {
	cnt[x]--;
	if (!cnt[x]) --now;
}
inline void update(int l, int r, int t) {
	if (c[t].id >= l && c[t].id <= r) {
		del(a[c[t].id]);
		add(c[t].col);
	}
	swap(a[c[t].id], c[t].col);
}

signed main() {
	n = read(), m = read(); size = pow(n, 2.0 / 3);
	F(i, 1, n) a[i] = read(), blo[i] = (i - 1) / size + 1;
	F(i, 1, m) {
		char op = getchar();
		while (op != 'Q' && op != 'R') op = getchar();
		if (op == 'Q') {
			cnt_q++;
			q[cnt_q].l = read(), q[cnt_q].r = read();
			q[cnt_q].id = cnt_q, q[cnt_q].t = cnt_t;
		} else {
			cnt_t++;
			c[cnt_t].id = read(), c[cnt_t].col = read();
		}
	}
	sort(q + 1, q + cnt_q + 1, cmp);
	F(i, 1, cnt_q) {
		while (l < q[i].l) del(a[l++]);
		while (l > q[i].l) add(a[--l]);
		while (r < q[i].r) add(a[++r]);
		while (r > q[i].r) del(a[r--]);
		while (t < q[i].t) update(q[i].l, q[i].r, ++t);
		while (t > q[i].t) update(q[i].l, q[i].r, t--);
		ans[q[i].id] = now;
	}
	F(i, 1, cnt_q) write(ans[i]), putchar('\n');
	return 0;
}
2021/5/29 13:29
加载中...