Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
98853 | 007yingziyu | Old Driver Tree | C++ | 运行超时 | 60 | 1000 MS | 13532 KB | 1097 | 2023-08-16 21:36:19 |
#include<bits/stdc++.h> using namespace std; int a[200005]; struct Node{ int l,r; mutable int v; Node(int l,int r=-1,int v=0):l(l),r(r),v(v){} friend inline bool operator<(const Node&a,const Node&b){ return a.l<b.l; } }; set<Node>S; typedef set<Node>::iterator It; inline It split(int pos){ It it=S.lower_bound(pos); if(it!=S.end()&&it->l==pos)return it; --it; if(pos>it->r)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 int query(int l,int r,int k){ int ret=0; It R=split(r+1),L=split(l); for(It it=L;it!=R;++it)if(k==it->v)ret+=it->r-it->l+1; return ret; } inline void assign(int l,int r,int v){ It R=split(r+1),L=split(l); S.erase(L,R),S.insert(Node(l,r,v)); } int main() { //freopen("ODT.in","r",stdin); // freopen("ODT","w",stdout); int n,m; cin>>n>>m; for(int i=1;i<=n;i++) { cin>>a[i]; S.insert(Node(i,i,a[i])); } for(int i=1;i<=m;i++) { int l,r,c; cin>>l>>r>>c; cout<<query(l,r,c)<<endl; assign(l,r,c); } }