Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
98794 | CSYZDuZhenyu | Old Driver Tree | C++ | 编译错误 | 0 | 0 MS | 0 KB | 1123 | 2023-08-16 14:58:49 |
#include<bits/stdc++.h> #define int long long using namespace std; int n,m; struct node { int l,r; mutable int v; inline bool operator < (const node &a) const { return l < a.l; } }; set<node> s; using st = set<node>::iterator; inline auto split(int pos) { st it = s.lower_bound((node){pos,0,0}); if(it != s.end() && it->l == pos) return it; it--; if(it->r < 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) { st pr = split(r+1); st 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; st qr = split(r+1); st ql = split(l); for(;ql != qr;ql++) if((*ql).v == x) ans += (*ql).r-(*ql).l+1; return ans; } signed main() { scanf("%lld%lld",&n,&m); for(int i = 1,a;i <= n;i++) { scanf("%lld",&a); s.insert((node){i,i,a}); } for(;m;m--) { int l,r,c; scanf("%lld%lld%lld",&l,&r,&c); printf("%lld\n",query(l,r,c)); assign(l,r,c); } return 0; }