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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
| #include <bits/stdc++.h>
using namespace std;
# define Rep(i,a,b) for(int i=a;i<=b;i++) # define _Rep(i,a,b) for(int i=a;i>=b;i--) # define RepG(i,u) for(int i=head[u];~i;i=e[i].next)
const int N=1e5+5; const unsigned long long inf=0-1;
# define ll long long # define db double # define ull unsigned long long # define uint unsigned int # define chkmax(a,b) a=max(a,b) # define chkmin(a,b) a=min(a,b) # define mkp make_pair # define PII pair<int,int> # define PLL pair<ll,ll> # define PIL pair<int,ll> # define PLI pair<ll,int>
template<typename T> void read(T &x){ x=0;int f=1; char c=getchar(); for(;!isdigit(c);c=getchar())if(c=='-')f=-1; for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0'; x*=f; }
int n,m,bit; int head[N],cnt; int o[N]; ull a[N]; int dfn[N],siz[N],_a[N],top[N],dep[N],faz[N],son[N],dfsxu;
struct Edge{ int to,next; }e[N<<1];
void add(int x,int y){ e[++cnt]=(Edge){y,head[x]},head[x]=cnt; }
struct node{ ull l0,l1,r0,r1; node(){l0=r0=0,l1=r1=inf;} }seg[N<<2];
void dfs1(int u,int fa){ faz[u]=fa,dep[u]=dep[fa]+1; siz[u]=1; RepG(i,u){ int v=e[i].to; if(v==fa)continue; dfs1(v,u); siz[u]+=siz[v]; if(siz[v]>siz[son[u]])son[u]=v; } }
void dfs2(int u,int _top){ dfn[u]=++dfsxu; _a[dfsxu]=u; top[u]=_top; if(!son[u])return; dfs2(son[u],_top); RepG(i,u){ int v=e[i].to; if(v==faz[u]||v==son[u])continue; dfs2(v,v); } }
# define lc (u<<1) # define rc (u<<1|1)
ull calc(ull x,int p){ if(o[p]==1)return x&a[p]; if(o[p]==2)return x|a[p]; if(o[p]==3)return x^a[p]; }
node merge(node x,node y){ node res; res.l0=(x.l0&y.l1)|((~x.l0)&y.l0); res.l1=(x.l1&y.l1)|((~x.l1)&y.l0); res.r0=(y.r0&x.r1)|((~y.r0)&x.r0); res.r1=(y.r1&x.r1)|((~y.r1)&x.r0); return res; }
void build(int u,int l,int r){ if(l==r){ seg[u].l0=seg[u].r0=calc(0,_a[l]); seg[u].l1=seg[u].r1=calc(inf,_a[l]); return; } int mid=l+r>>1; build(lc,l,mid); build(rc,mid+1,r); seg[u]=merge(seg[lc],seg[rc]); }
void update(int u,int l,int r,int x){ if(l==r){ seg[u].l0=seg[u].r0=calc(0,_a[l]); seg[u].l1=seg[u].r1=calc(inf,_a[l]); return; } int mid=l+r>>1; if(x<=mid)update(lc,l,mid,x); else update(rc,mid+1,r,x); seg[u]=merge(seg[lc],seg[rc]); }
node query(int u,int l,int r,int ql,int qr){ if(l>=ql&&r<=qr)return seg[u]; int mid=l+r>>1; if(qr<=mid)return query(lc,l,mid,ql,qr); else if(ql>mid)return query(rc,mid+1,r,ql,qr); else return merge(query(lc,l,mid,ql,qr),query(rc,mid+1,r,ql,qr)); }
node RouteQuery(int x,int y){ node l,r; while(top[x]!=top[y]) if(dfn[top[x]]>dfn[top[y]]){ l=merge(query(1,1,n,dfn[top[x]],dfn[x]),l); x=faz[top[x]]; } else{ r=merge(query(1,1,n,dfn[top[y]],dfn[y]),r); y=faz[top[y]]; } if(dfn[x]<dfn[y])r=merge(query(1,1,n,dfn[x],dfn[y]),r); else l=merge(query(1,1,n,dfn[y],dfn[x]),l); swap(l.l0,l.r0),swap(l.l1,l.r1); return merge(l,r); }
int main() { # ifndef ONLINE_JUDGE freopen("testdata.in","r",stdin); # endif memset(head,-1,sizeof(head)); read(n),read(m),read(bit); Rep(i,1,n)read(o[i]),read(a[i]); Rep(i,1,n-1){ int x,y; read(x),read(y); add(x,y),add(y,x); } dfs1(1,0); dfs2(1,1); build(1,1,n); Rep(i,1,m){ int opt,x,y; ull z; read(opt),read(x),read(y),read(z); if(opt==2){ o[x]=y; a[x]=z; update(1,1,n,dfn[x]); } else{ node res=RouteQuery(x,y); ull ans=0; _Rep(i,63,0){ int v0=(res.l0>>i)&1ull; int v1=(res.l1>>i)&1ull; if(v0>=v1||((1ull<<i)>z))ans|=(v0?(1ull<<i):0); else ans|=(v1?(1ull<<i):0),z-=1ull<<i; } printf("%llu\n",ans); } } return 0; }
|