Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
98702 CSYZCaoMY Karry5307 C++ 运行超时 0 1000 MS 36340 KB 1767 2023-08-16 12:50:00

Tests(2/7):


#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/hash_policy.hpp> using namespace std; struct num{ int l,r; long long v; }; bool operator < (num a,num b){ return (a.l<b.l); } __gnu_pbds::gp_hash_table<int,bool> ans; set<num> t; inline set<num>::iterator sp(int x){ auto it=lower_bound(t.begin(),t.end(),(num){x,0,0}); if(it!=t.end() && it->l==x) return it; it--; if(it->r<x) return t.end(); int ll=it->l,rr=it->r,vv=it->v;; t.erase(it),t.insert((num){ll,x-1,vv}); return t.insert((num){x,rr,vv}).first; } inline int query(int l,int r){ int ret=0; auto tmp=sp(r+1),cun=sp(l); ans.clear(); for(;cun!=tmp;cun++) if(!ans[cun->v]) ans[cun->v]=1,ret++; return ret; } inline void chan(int l,int r,long long x){ auto cun=sp(r+1),tmp=sp(l); t.erase(tmp,cun),t.insert({l,r,x}); } int main(){ int n,m,l,r,lai=0,op; scanf("%d%d",&n,&m); long long in,lan=LONG_LONG_MAX,x; for(int i=1;i<=n;i++){ scanf("%lld",&in); if(in!=lan){ if(lan!=LONG_LONG_MAX) t.insert((num){lai,i-1,lan}); lan=in,lai=i; } } t.insert((num){lai,n,lan}); for(int i=1;i<=m;i++){ scanf("%d%d%d",&op,&l,&r); switch(op){ case 1: scanf("%lld",&x); chan(l,r,x); break; case 2: printf("%d\n",query(l,r)); break; } } return 0; }/* Samples 1: Input: 5 5 1 2 3 4 5 2 1 5 1 2 3 4 2 1 5 2 3 3 2 2 4 Output: 5 3 1 1 Samples 2: Input: 4 5 1 1 4 5 1 3 4 5 2 3 4 1 1 3 4 2 1 4 2 2 2 Output: 1 2 1 */


测评信息: