//Writer解 その1 #include #include #include #include using namespace std; using namespace atcoder; const int bit_length=10; typedef struct count{ vector val; count(){ val.resize(bit_length); } }Counter; void calculate_depth(const vector>& G,vector& depth){ int n=G.size(); deque dq; vector check(n,false); dq.push_back(0); while(!dq.empty()){ int q=dq.back(); dq.pop_back(); check.at(q)=true; for(int i:G.at(q)){ if(check.at(i))continue; dq.push_back(i); depth.at(i)=depth.at(q)+1; } } return; } void separate(const vector>& G,const vector& depth,vector>& parents,vector>& children){ int n=G.size(); for(int i=0;i>i)&1)ret.val.at(i)=1; else ret.val.at(i)=0; } return ret; } void convert(const vector>& parents,vector>& children,vector& C,vector>& Nodes,vector& A){ int n=parents.size(),next,now=0; vector check(n,false); while(true){ if(!check.at(now)){ Nodes.at(now).push_back((int)A.size()); A.push_back(change(C.at(now))); check.at(now)=true; } if(!children.at(now).empty()){ next=children.at(now).back(); children.at(now).pop_back(); }else if(!parents.at(now).empty()){ Nodes.at(now).push_back((int)A.size()); A.push_back(change(C.at(now))); next=parents.at(now).back(); }else{ Nodes.at(now).push_back((int)A.size()); A.push_back(change(C.at(now))); break; } now=next; } return; } Counter op(const Counter a,const Counter b){ Counter ret; for(int i=0;i>N>>Q; vectorC(N); vector>G(N); for(int i=0;i>C.at(i); for(int i=0;i>a>>b; G.at(a-1).push_back(b-1); G.at(b-1).push_back(a-1); } vectordepth(N,0); calculate_depth(G,depth); vector>parents(N); vector>children(N); separate(G,depth,parents,children); vector>Nodes(N); vectorA(N); convert(parents,children,C,Nodes,A); segtree seg(A); int T,x,y,r,l; Counter R,L,P; for(int i=0;i>T>>x>>y; x--; if(T==1){ l=Nodes.at(x).at(0); r=Nodes.at(x).at(1); L=seg.get(l); R=seg.get(r); seg.set(l,L^change(y)); seg.set(r,R^change(y)); }else{ l=Nodes.at(x).at(0); r=Nodes.at(x).at(1); P=seg.prod(l,r+1); cout<