Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
98603 | CSYZ_WanYL | Old Driver Tree | C++ | 编译错误 | 0 | 0 MS | 0 KB | 1699 | 2023-08-16 12:07:52 |
#include<bits/stdc++.h> #define int long long using namespace std; const int N=2e5+5; int n,m; int a[N]; int b[N],tot; int buc[N]; struct node { int l,r; mutable int v; bool operator < (const node &x) const{ return x.l>this->l; } }; struct Node{ int lt,rt,k; }q[N]; set<node>s; inline auto split(int pos) { auto it=lower_bound(s.begin(),s.end(),(node){pos,0,0}); if(it!=s.end() && it->l==pos) return it; it--; if(it->l>=pos) return s.end(); int l=it->l,r=it->r,v=it->v; s.erase(it),s.insert((node){l,pos-1,v}); return s.insert((node){pos,r,v}).first; } inline void assign(int l,int r,int x) { auto pr=split(r+1),pl=split(l); s.erase(pl,pr),s.insert((node){l,r,x}); } inline int query(int l,int r,int x) { int ans=0; auto qr=split(r+1),ql=split(l); for(;ql!=qr;ql++) if((*ql).v==x) ans+=(*ql).r-(*ql).l+1; return ans; } void baoli(){ for(int i=1;i<=n;i++){ cin>>a[i]; b[++tot]=a[i]; } for(int i=1;i<=m;i++){ cin>>q[i].lt>>q[i].rt>>q[i].k; b[++tot]=q[i].k; } sort(b+1,b+tot+1); tot=unique(b+1,b+tot+1)-b-1; for(int i=1;i<=n;i++) a[i]=lower_bound(b+1,b+tot+1,a[i])-b; for(int x=1;x<=m;x++){ q[x].k=lower_bound(b+1,b+tot+1,q[x].k)-b; for(int i=1;i<=tot;i++) buc[i]=0; for(int i=q[x].lt;i<=q[x].rt;i++){ buc[a[i]]++; a[i]=q[x].k; } cout<<buc[q[x].k]<<"\n"; } } signed main(){ ios::sync_with_stdio(false); cin>>n>>m; if(n<=8000&&m<=8000){ baoli(); return 0; } for(int i=1;i<=n;i++){ cin>>a[i]; s.insert((node){i,i,a[i]}); } while(m--){ int lt,rt,k; cin>>lt>>rt>>k; cout<<query(lt,rt,k)<<"\n"; assign(lt,rt,k); } return 0; }