#pragma GCC optimize("Ofast") #include // #include // #include // #include // using namespace __gnu_pbds; // #include // namespace multiprecisioninteger = boost::multiprecision; // using cint=multiprecisioninteger::cpp_int; using namespace std; using ll=long long; #define double long double using datas=pair; using ddatas=pair; using tdata=pair; using vec=vector; using mat=vector; using pvec=vector; using pmat=vector; // using llset=tree,rb_tree_tag,tree_order_statistics_node_update>; #define For(i,a,b) for(i=a;i<(ll)b;++i) #define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i) #define rep(i,N) For(i,0,N) #define rep1(i,N) For(i,1,N) #define brep(i,N) bFor(i,N,0) #define brep1(i,N) bFor(i,N,1) #define all(v) (v).begin(),(v).end() #define allr(v) (v).rbegin(),(v).rend() #define vsort(v) sort(all(v)) #define vrsort(v) sort(allr(v)) #define endl "\n" #define eb emplace_back #define print(v) cout< inline bool chmax(T& a,T b){bool x=a inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} struct unionfind{ private: int maxN; vector par; public:unionfind(int N) :maxN(N),par(N){ for(int i=0;ipy)swap(px,py); if(px!=py){ par[px]=py; } return px!=py; } bool parcheck(int x,int y){ return root(x)==root(y); } void clear(){ int i; for(i=0;i struct LazySegmentTree{ private: using func=function; func f,g; size_t N=1; T E; vector node,lazy; vector vis; void eval(size_t& x){ if(!vis[x])return; node[x]=g(node[x],lazy[x]); vis[x]=false; if(x>1); update(a,b,x,now<<1|1,(l+r)>>1,r); node[now]=f(node[now<<1],node[now<<1|1]); } } T call(size_t& a,size_t &b,size_t now,size_t l,size_t r){ eval(now); if((b<=l)|(r<=a))return E; if((a<=l)&(r<=b))return node[now]; return f(call(a,b,now<<1,l,(l+r)>>1),call(a,b,now<<1|1,(l+r)>>1,r)); } public: LazySegmentTree(vector& v,func F,func G,T Ie):f(F),g(G),E(Ie){ size_t i=v.size(); while(i){ N<<=1;i>>=1; } node.resize(N<<1,E); lazy.resize(N<<1); vis.resize(N<<1,false); for(i=0;i> g; vector> pos; int euler_tour(int now,int cnt){ pos[now].first=cnt; cnt++; for(int x:g[now]){ cnt=euler_tour(x,cnt); } return pos[now].second=cnt; } int main(){ int i,Q,a,b,cnt=0; scanf("%d %d",&N,&Q); g.resize(N*2-1); pos.resize(N*2-1); unionfind tree(N*2-1); vector>> queli; while(Q--){ scanf("%d %d %d",&i,&a,&b); --a; if(i==1){ --b; a=tree.root(a); b=tree.root(b); if(a!=b){ tree.unite(a,cnt+N); tree.unite(b,cnt+N); queli.eb(1,pair(a,cnt+N)); queli.eb(1,pair(b,cnt+N)); g[cnt+N].eb(a); g[cnt+N].eb(b); ++cnt; } }else{ queli.eb(i,pair(a,b)); } } if(cnt==0){ vector v(N,0); for(auto x:queli){ if(x.first==2){ v[x.second.first]+=x.second.second; }else{ printf("%d\n",v[x.second.first]); } } return 0; } i=1; while(cnt seg(N*2-1,0); LazySegmentTree v(seg,[](int a,int b){return a+b;},[](int a,int b){return a+b;},0); for(auto x:queli){ if(x.first==1){ tree.unite(x.second.first,x.second.second); }else if(x.first==2){ a=tree.root(x.second.first); v.update(pos[a].first,pos[a].second,x.second.second); }else{ printf("%d\n",v.get(pos[x.second.first].first,pos[x.second.first].first+1)); } } }