社区讨论
爆0求助
P1903【模板】带修莫队 / [国家集训队] 数颜色 / 维护队列参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @lo8iafy7
- 此快照首次捕获于
- 2023/10/27 19:04 2 年前
- 此快照最后确认于
- 2023/10/27 19:04 2 年前
CPP
#include<bits/stdc++.h>
#define N 140000
using namespace std;
struct hhh{
int l,r,t,id;
}q[N];
struct qq{
int u,v,w;
}dl[N];
int n,m,x,y,a[N],l,r,t,tot,tot2,block,ans,sum[N],fans[N];
char b;
bool cmp(hhh a,hhh b){
if(a.l/block!=b.l/block) return a.l<b.l;
if(a.r/block!=b.r/block) return a.r<b.r;
return a.t<b.t;
}
void del(int x){
sum[a[x]]--;
if(!sum[a[x]]) ans--;
}
void add(int x){
sum[a[x]]++;
if(sum[a[x]]==1) ans++;
}
void go(int x,int p){
int w=dl[x].w;
sum[a[w]]--;
if(!sum[a[w]]&&w>=l&&w<=r) ans--;
if(p) a[w]=dl[x].v;
else a[w]=dl[x].w;
sum[a[w]]++;
if(sum[a[w]]==1&&w>=l&&w<=r) ans++;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=m;i++){
cin>>b>>x>>y;
if(b=='Q'){
q[++tot].id=tot,q[tot].l=x;
q[tot].r=y,q[tot].t=tot2;
}
else{
dl[++tot2].u=a[x],dl[tot2].v=y;
dl[tot2].w=x,a[x]=y;
}
}
for(int i=tot2;i;i--) a[dl[i].w]=dl[i].u;
block=n*2/3;
sort(q+1,q+tot+1,cmp);
for(int i=1;i<=tot;i++){
int ql=q[i].l,qr=q[i].r,qt=q[i].t;
while(l<ql) del(l++);
while(l>ql) add(--l);
while(r<qr) add(++r);
while(r>qr) del(r--);
while(t<qt) go(++t,1);
while(t>qt) go(t--,0);
fans[q[i].id]=ans;
}
for(int i=1;i<=tot;i++) cout<<fans[i]<<endl;
return 0;
}
QWQ
回复
共 0 条回复,欢迎继续交流。
正在加载回复...