提交时间:2023-08-16 12:11:17
运行 ID: 98646
#include<bits/stdc++.h> using namespace std; #define ll long long const int N=2e5+10; struct node{ ll l,r,v; bool operator<(const node &x)const{ return l<x.l; } bool operator>(const node &x)const{ return l>x.l; } }; set<node>s; #define st set<node>::iterator inline st split(ll pos){ st it=lower_bound(s.begin(),s.end(),node{pos,0,0}); if(it!=s.end()&&it->l==pos)return it; it--; if(it->r<pos) return s.end(); ll 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(ll l,ll r,ll x) { st pr=split(r+1),pl=split(l); s.erase(pl,pr),s.insert((node){l,r,x}); } inline ll query(ll l,ll r) { ll ans=0;map<ll,bool>vis; st qr=split(r+1),ql=split(l); for(;ql!=qr;ql++) if(!vis[(*ql).v]) ans+=1,vis[(*ql).v]=1; return ans; } inline void read(ll &x){ x=0;bool f=0;char c=getchar(); while(c>'9'||c<'0'){if(c=='-')f=1;c=getchar();} while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar(); if(f)x=-x; } ll n,m; int main(){ // freopen("karry5307.in","r",stdin); // freopen("karry5307.out","w",stdout); read(n);read(m); s.insert((node{1,n,0})); for(ll i=1;i<=n;i++){ ll x;read(x); assign(i,i,x); } while(m--){ ll op,l,r,x; read(op);read(l);read(r); if(op==1){ read(x); assign(l,r,x); } else if(op==2) cout<<query(l,r)<<endl; } return 0; } /* 4 5 1 1 4 5 1 3 4 5 2 3 4 1 1 3 4 2 1 4 2 2 2 */