RE,求调
查看原帖
RE,求调
289436
LZX_ssfd楼主2021/11/14 20:23

RT,全部RE

code:

#include<bits/stdc++.h>
using namespace std;
const int N=1.4e5;
int n,m;
int a[N];
int block;//分块
int cnt[N],ans[N],sum;//cnt[i]记录i的个数;
int asked,changed;
struct node {
	int l,r,t;
	int w;
	bool operator <(const node x)const {
return (l/block)==(x.l/block)? (r/block)==(x.r/block)? t<x.t: r<x.r:l<x.l ;
	}
} q[N],exch[N];
inline void upd(int x,int t) {
	if(q[x].l<=exch[t].l&&q[x].r>=exch[t].l) {
		sum-=!--cnt[a[exch[t].l]];
		sum+=!cnt[exch[t].r]++;
	}
	swap(a[exch[t].l],exch[t].r);
}
int main() {
	scanf("%d%d",&n,&m);
	block=pow(n,2.0/3.0);
	for(int i=1; i<=n; i++)scanf("%d",&a[i]);
	for(int i=1; i<=m; i++) {
		char c;
		int l_,r_;
		scanf("%s%d%d",&c,&l_,&r_);
		if(c=='Q')
			++asked,q[asked].w=asked,q[asked].l=l_,q[asked].r=r_,q[asked].t=changed;
		else exch[++changed].l=l_,exch[changed].r=r_;
	}
	sort(q+1,q+1+asked);
	int l=1,r=0,t=0;
	for(int i=1; i<=asked; i++) {

		while(l<q[i].l)sum+=!cnt[a[--l]]++;
		while(l>q[i].l)sum-=!--cnt[a[l++]];
		while(r<q[i].r)sum+=!cnt[a[++r]]++;
		while(r>q[i].r)sum-=!--cnt[a[r--]];
		while(t>q[i].t)upd(i,t--);
		while(t<q[i].t)upd(i,++t);
		ans[q[i].w]=sum;
		printf("-->%d : %d( %d )\n",i,ans[q[i].w],q[i].w);
	}
	for(int i=1; i<=asked; i++)printf("%d\n",ans[i]);
	return 0;
}
2021/11/14 20:23
加载中...