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
| #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") #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=1e5+10,M=1e4+10,BM=sqrt(N)+5; int n,m,S,a[N],tot,bl[N],L[BM],R[BM],s[BM][M],c[BM][N],cp[M]; I void U(CI p,CI v){if(a[p]==v) return ;RI i;for(i=bl[p];i<=tot;i++) --c[i][s[i][a[p]]--],++c[i][++s[i][v]];a[p]=v;} I int Q1(CI x){RI i,X=s[bl[x]-1][a[x]];for(i=L[bl[x]];i<=x;i++) X+=(a[i]==a[x]);return X;} I int Q2(CI x){RI i,t=Q1(x),X=c[bl[x]-1][t];for(i=L[bl[x]];i<=x;i++) X+=((++cp[a[i]])+s[bl[x]-1][a[i]]==t);for(i=L[bl[x]];i<=x;i++) --cp[a[i]];return X;} int main(){ freopen("password.in","r",stdin),freopen("password.out","w",stdout); RI i,j,o,x,y;for(read(n),S=min((int)sqrt(n)*3,n),i=1;i<=n;i++) read(a[i]),!((i-1)%S)&&(R[tot]=i-1,L[++tot]=i),bl[i]=tot;R[tot]=n; for(i=1;i<=tot;i++){for(j=0;j<M;j++) s[i][j]=s[i-1][j];for(j=0;j<=n;j++) c[i][j]=c[i-1][j];for(j=L[i];j<=R[i];j++) ++c[i][++s[i][a[j]]];} for(read(m);m--;) read(o,x,y),o&1?U(y,x):writeln(x^1?x&1?Q2(y):Q1(y):a[y]);return 0; }
|