1 #include<cstdio>
2 #include<iostream>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 using namespace std;
7 char ch; bool ok;
8 void read(int &x){
9 for (ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if (ch==‘-‘) ok=1;
10 for (x=0;isdigit(ch);x=x*10+ch-‘0‘,ch=getchar());
11 if (ok) x=-x;
12 }
13 const int maxn=100005;
14 int n,q,x,y;
15 char op[10];
16 struct LCT{
17 #define ls son[x][0]
18 #define rs son[x][1]
19 int fa[maxn],son[maxn][2],rev[maxn],val[maxn],sum[maxn];
20 int which(int x){return son[fa[x]][1]==x;}
21 bool isroot(int x){return son[fa[x]][0]!=x&&son[fa[x]][1]!=x;}
22 void addtag_rev(int x){if (x) rev[x]^=1,swap(ls,rs);}
23 void pushdown(int x){if (rev[x]) addtag_rev(ls),addtag_rev(rs),rev[x]=0;}
24 void relax(int x){
25 if (!isroot(x)) relax(fa[x]);
26 pushdown(x);
27 }
28 void updata(int x){sum[x]=sum[ls]+val[x]+sum[rs];}
29 void rotate(int x){
30 int y=fa[x],z=fa[y],d=which(x),dd=which(y);
31 fa[son[x][d^1]]=y,son[y][d]=son[x][d^1],fa[x]=fa[y];
32 if (!isroot(y)) son[z][dd]=x;
33 son[x][d^1]=y,fa[y]=x,updata(y);
34 }
35 void splay(int x){
36 relax(x);
37 while (!isroot(x)){
38 if (isroot(fa[x])) rotate(x);
39 else if (which(fa[x])==which(x)) rotate(fa[x]),rotate(x);
40 else rotate(x),rotate(x);
41 }
42 updata(x);
43 }
44 void access(int x){for (int p=0;x;x=fa[x]) splay(x),son[x][1]=p,p=x;}
45 void make_root(int x){access(x),splay(x),addtag_rev(x);}
46 void connect(int u,int v){make_root(u),fa[u]=v;}
47 int query_sum(int u,int v){make_root(u),access(v),splay(v);return sum[v];}
48 int find_left(int x){for (pushdown(x);son[x][0];x=son[x][0],pushdown(x));return x;}
49 bool query_con(int u,int v){make_root(u),access(v),splay(v);return find_left(v)==u;}
50 void modify(int x,int v){val[x]=sum[x]=v,splay(x);}
51 }T;
52 int main(){
53 read(n);
54 for (int i=1;i<=n;i++) read(x),T.modify(i,x);
55 for (read(q);q;q--){
56 scanf("%s",op+1),read(x),read(y);
57 if (op[1]==‘b‘){
58 if (T.query_con(x,y)) puts("no");
59 else T.connect(x,y),puts("yes");
60 }
61 else if (op[1]==‘p‘) T.modify(x,y);
62 else if (op[1]==‘e‘){
63 if (T.query_con(x,y)) printf("%d\n",T.query_sum(x,y));
64 else puts("impossible");
65 }
66 }
67 return 0;
68 }