萌新刚学OI,带修莫队0pts求助
查看原帖
萌新刚学OI,带修莫队0pts求助
344847
Rubi_sama楼主2023/4/29 10:12
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10,M=1e5+10;
#define fo1(l,r) for(register int i=l;i<=r;i++)
#define fo2(l,r) for(register int j=l;j<=r;j++)
#define fo3(l,r) for(register int k=l;k<=r;k++)
#define fo4(l,r) for(register int tt=l;tt<=r;tt++)
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		x=x*10+ch-48;
		ch=getchar();
	}
	return x*f;
}
int n,m,nn,t,l,r,ans,ll,rr,tt;
int len;
int ls1,ls2,ls3;
int now1,now2,now3;
int cnt;
int lisan[N+M];//多个数组要离散化,用一个数组即可 
int a[N],de[M][2];
string ty;
int ANS[M],sum[N+M];
struct node
{
	int l,r,t,k,bh;
	node(int a=0,int b=0,int c=0,int d=0,int e=0);
}x[M];
node::node(int a,int b,int c,int d,int e)
{
	l=a;r=b;t=c;k=d;bh=e;
}
#define pos(x) ((x-1)/len+1)
inline bool cmp(node xx,node yy)
{
	return pos(xx.l)==pos(yy.l)?(pos(xx.r)==pos(yy.r)?(xx.t<yy.t):(xx.r<yy.r)):(xx.l<yy.l);
}
inline void yswap(int &xx,int &yy)
{
	xx^=yy;
	yy^=xx;
	xx^=yy;
	return;
}
inline void yadd(int p)
{
	sum[a[p]]++;
	return ;
}
inline void ydel(int p)
{
	sum[a[p]]--;
	return ;
}
inline void yt(int p)
{
	if(de[p][0]>=l && de[p][0]<=r)
	{
		sum[a[de[p][0]]]--;
		sum[de[p][1]]++;
	}
	yswap(a[de[p][0]],de[p][1]);
	return ;
}
int main()
{
	n=read();len=sqrt(n);m=read();
	fo1(1,n)
	{
		a[i]=read();
		lisan[++cnt]=a[i];
	}
	fo1(1,m)
	{
		cin>>ty;
		if(ty[0]=='C')
		{
			ls1=read();
			ls2=read();
			de[++now1][0]=ls1;
			de[now1][1]=ls2;
			lisan[++cnt]=ls2;
		}
		else
		{
			ls1=read();
			ls2=read();
			ls3=read();
			lisan[++cnt]=ls3;
			x[++now2]=node(ls1,ls2,now1,ls3,now2);
		}
	}
	sort(lisan+1,lisan+1+cnt);
	nn=unique(lisan+1,lisan+1+cnt)-lisan-1;
	fo1(1,n)
		a[i]=lower_bound(lisan+1,lisan+1+nn,a[i])-lisan;
	fo1(1,now1)
		de[i][1]=lower_bound(lisan+1,lisan+1+nn,de[i][1])-lisan;
	fo1(1,now2)
		x[i].k=lower_bound(lisan+1,lisan+1+nn,x[i].k)-lisan;
	sort(x+1,x+1+now2,cmp);
	l=1;r=0;t=0;ans=0;
	fo1(1,now2)
	{
		ll=x[i].l;
		rr=x[i].r;
		tt=x[i].t;
		//cout<<ll<<"---"<<rr<<"---"<<tt<<endl;
		while(l<ll)
		{
			ydel(l);
			l++;
		}
		while(l>ll)
		{
			l--;
			yadd(l);
		}
		while(r<rr)
		{
			r++;
			yadd(r);
		}
		while(r>rr)
		{
			ydel(r);
			r--;
		}
		while(t<tt)
		{
			t++;
			yt(t);
		}
		while(t>tt)
		{
			yt(t);
			t--;
		}
		ANS[x[i].bh]=sum[x[i].k];
	}
	fo1(1,now2)
		printf("%d\n",ANS[i]);
	return 0;
}
/*
5 3
1 1 10 20 30
C 1 29
C 2 30
Q 1 4 40
*/
2023/4/29 10:12
加载中...