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 80 81 82 83 84
| #include<bits/stdc++.h> using namespace std;
inline int read(){int x=0,f=1;char ch=getchar(); while(ch<'0'|| ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;} #define Z(x) (x)*(x) #define pb push_back
#define N 5000010
struct node { int x, id; bool operator <(const node &A) const { if(x==A.x) return id<A.id; return x<A.x; } }; int n, m, i, j, k, T; set<node>s; set<node>::iterator it1, it2, it; int f[N], p[N], a[N], l, r, q, w, mid, op;
int fa(int x) { if(f[x]==x) return x; return f[x]=fa(f[x]); }
signed main() {
n=read(); for(i=1; i<=n; ++i) { a[i]=read(); s.insert({a[i], i}); p[i]=i; f[i]=i; }
q=read(); auto work = [&] (int l, int r, int k) -> void{
a[++n]=k; f[n]=n; s.insert({a[n], n}); it1=it=s.lower_bound({l, 0}), it2=s.lower_bound({r+1, 0});
for(; it1!=it2; ++it1) {
f[fa(it1->id)]=fa(n); } s.erase(it, it2);
}; while(q--) { op=read(); if(op==1) { k=read(); w=read(); p[k]=++n; a[n]=w; f[n]=n; s.insert({a[n], n}); } if(op==2) { k=read(); printf("%lld\n", a[fa(p[k])]); } if(op==3) { l=read(); r=read(); mid=(l+r)/2; work(l, mid, l-1); work(mid+1, r, r+1); }
} return 0; }
|