rt
调不了给个hack数据也行,万分感谢
#ifdef DEBUG
#define GNU_DEBUG
#define _GLIBCXX_DEBUG 1
#define _GLIBCXX_DEBUG_PEDANTIC 1
#define _GLIBCXX_SANITIZE_VECTOR 1
#endif
#include<bits/stdc++.h>
#include<bits/extc++.h>
#define F(i,j,k) for(auto i=j;i<=(decltype(i))k;i++)
#define exec(...) [&](){__VA_ARGS__}()
#define lambda [&]
#define endl '\n'
#define view(x) begin(x),end(x)
#define pb push_back
#define x first
#define y second
#define os ostream
using namespace std;
using namespace __gnu_pbds;
template<typename T>void ckmax(T& a,T b){a=max(a,b);}
template<typename T>void ckmin(T& a,T b){a=min(a,b);}
#ifdef DEBUG
template<typename...T>os& operator<<(os& out,tuple<T...> x);
template<typename T1,typename T2>os& operator<<(os& out,pair<T1,T2> x){return out<<tuple(x);}
template<typename T,typename=decltype(T().begin()),typename=enable_if_t<!is_same_v<decay_t<T>,string>>>os& operator<<(os& out,T x){return out<<"{",exec(auto n=0u;for(auto i:x) out<<i<<(++n==x.size()?"":",");),out<<"}";}
template<typename...T>os& operator<<(os& out,tuple<T...> x){return apply(lambda(T... xx){auto n=0u;out<<"{",((out<<xx<<(++n==sizeof...(T)?"":",")),...),out<<"}";},x),out;}
#define debug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<" = "<<std::make_tuple(__VA_ARGS__)<<endl
#else
#define debug(...) (void)0
#endif
#define nodebug(...) (void)0
const int maxn=3e5+5;
__gnu_pbds::priority_queue<int,less<int>,pairing_heap_tag> q[maxn];
decltype(q[0].begin()) iter[maxn];
string s;
int fa[maxn],n,x,y,Q,add[maxn],global_add,mx;
multiset<int,greater<int>> st;
int find_root(int x){
if(x==fa[x]) return x;
return fa[x]=find_root(fa[x]);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
F(i,1,n){
cin>>x;
q[i].push(x);
iter[i]=q[i].begin();
fa[i]=i;
st.insert(x);
}
cin>>Q;
F(i,1,Q){
cin>>s;
if(s=="U"){
cin>>x>>y;
x=find_root(x),y=find_root(y);
if(x==y) continue;
st.erase(st.find(q[x].top())),st.erase(st.find(q[y].top()));
if(q[x].size()<q[y].size()) swap(x,y);
for(auto i=q[y].begin();i!=q[y].end();++i)
q[y].modify(i,*i+add[x]-add[y]);
q[x].join(q[y]);
fa[y]=x;
st.insert(q[x].top());
}
else if(s=="A1"){
cin>>x>>y;
int rx=find_root(x);
st.erase(st.find(q[rx].top()+add[rx]));
q[rx].modify(iter[x],*iter[x]+y);
st.insert(q[rx].top()+add[rx]);
}
else if(s=="A2"){
cin>>x>>y;
x=find_root(x);
st.erase(st.find(q[x].top()+add[x]));
add[x]+=y;
st.insert(q[x].top()+add[x]);
}
else if(s=="A3"){
cin>>x;
global_add+=x;
}
else if(s=="F1"){
cin>>x;
cout<<*iter[x]+add[find_root(x)]+global_add<<endl;
}
else if(s=="F2"){
cin>>x;
x=find_root(x);
cout<<q[x].top()+add[x]+global_add<<endl;
}
else{
cout<<*st.begin()+global_add<<endl;
}
//debug(i);
//F(i,1,n) debug(q[find_root(i)],*iter[i]);
}
return 0;
}
/*
~
~
~
~
~
~
~
~
*/