1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| #include<bits/stdc++.h> #define Tp template<typename Ty> #define Ts template<typename Ty,typename... Ar> #define W while #define I inline #define RI register int #define LL long long #define Cn const #define CI Cn int& #define gc getchar #define D isdigit(c=gc()) #define pc(c) putchar((c)) using namespace std; namespace Debug{ Tp I void _debug(Cn char* f,Ty t){cerr<<f<<'='<<t<<endl;} Ts I void _debug(Cn char* f,Ty x,Ar... y){W(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);} Tp ostream& operator<<(ostream& os,Cn vector<Ty>& V){os<<"[";for(Cn auto& vv:V) os<<vv<<",";os<<"]";return os;} #define gdb(...) _debug(#__VA_ARGS__,__VA_ARGS__) }using namespace Debug; namespace FastIO{ Tp I void read(Ty& x){char c;int f=1;x=0;W(!D) f=c^'-'?1:-1;W(x=(x<<3)+(x<<1)+(c&15),D);x*=f;} Ts I void read(Ty& x,Ar&... y){read(x),read(y...);} Tp I void write(Ty x){x<0&&(pc('-'),x=-x,0),x<10?(pc(x+'0'),0):(write(x/10),pc(x%10+'0'),0);} Tp I void writeln(Cn Ty& x){write(x),pc('\n');} }using namespace FastIO; Cn int N=5e5+10; int n,m,a[N],b[N<<1],cnt,rt[N<<1]; set<int> v[N<<1]; struct Que{int opt,l,r;}q[N]; class SegmentTree{ private: int T[N<<2],Mx[N<<2],Mn[N<<2]; #define mid (l+r>>1) #define PT CI x=1,CI l=1,CI r=n #define LT x<<1,l,mid #define RT x<<11,mid+1,r #define PU(x) (T[x]=max(T[x<<1],T[x<<11]),Mx[x]=max(Mx[x<<1],Mx[x<<11]),Mn[x]=min(Mn[x<<1],Mn[x<<11])) public: I void U(CI p,CI v,PT){ if(l==r) return void(T[x]=v); p<=mid?U(p,v,LT):U(p,v,RT),PU(x); } I void UU(CI p,CI v,PT){ if(l==r) return void(Mx[x]=Mn[x]=v); p<=mid?UU(p,v,LT):UU(p,v,RT),PU(x); } I int Q(CI L,CI R,PT){ if(L<=l&&r<=R) return T[x]; RI S=0;return L<=mid&&(S=max(S,Q(L,R,LT))),R>mid&&(S=max(S,Q(L,R,RT))),S; } I int QM(CI L,CI R,PT){ if(L<=l&&r<=R) return Mx[x]; RI S=0;return L<=mid&&(S=max(S,QM(L,R,LT))),R>mid&&(S=max(S,QM(L,R,RT))),S; } I int QN(CI L,CI R,PT){ if(L<=l&&r<=R) return Mn[x]; RI S=2e9;return L<=mid&&(S=min(S,QN(L,R,LT))),R>mid&&(S=min(S,QN(L,R,RT))),S; } }T; I void U(CI x,CI y){ RI flg=0;auto t=v[a[x]].lower_bound(x),p=t,s=t;++s; if(p!=v[a[x]].begin()) flg=1,p--; if(flg&&s!=v[a[x]].end()) T.U(*s,*p),T.U(*t,0);else if(flg) T.U(*t,0); else if(s!=v[a[x]].end()) T.U(*s,0),T.U(*t,0);else T.U(*t,0); v[a[x]].erase(t); v[y].insert(x),flg=0;t=v[y].lower_bound(x),p=t,s=t;++s; if(p!=v[y].begin()) flg=1,p--; if(flg&&s!=v[y].end()) T.U(*s,*p),T.U(*t,*p);else if(flg) T.U(*t,*p); else if(s!=v[y].end()) T.U(*s,*t),T.U(*t,0);else T.U(*t,0);a[x]=y,T.UU(x,y); } I int Q(CI l,CI r){return r-l==T.QM(l,r)-T.QN(l,r)&&T.Q(l,r)<l;} int main(){
RI i;for(read(n,m),i=1;i<=n;i++) read(a[i]),b[++cnt]=a[i]; for(i=1;i<=m;i++) read(q[i].opt,q[i].l,q[i].r),q[i].opt&1&&(b[++cnt]=q[i].r); #define LW(x) lower_bound(b+1,b+cnt+1,x)-b for(sort(b+1,b+cnt+1),cnt=unique(b+1,b+cnt+1)-b-1,i=1;i<=n;i++) v[a[i]=LW(a[i])].size()&&(T.U(i,*v[a[i]].rbegin()),0),v[a[i]].insert(i),T.UU(i,a[i]); for(i=1;i<=m;i++) q[i].opt&1?U(q[i].l,LW(q[i].r)):void(puts(Q(q[i].l,q[i].r)?"damushen":"yuanxing"));return 0; }
|