結果

問題 No.900 aδδitivee
ユーザー smiken_61smiken_61
提出日時 2019-11-02 18:30:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 207 ms / 2,000 ms
コード長 11,392 bytes
コンパイル時間 3,096 ms
コンパイル使用メモリ 163,600 KB
実行使用メモリ 24,988 KB
最終ジャッジ日時 2023-10-13 01:26:07
合計ジャッジ時間 9,759 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
17,904 KB
testcase_01 AC 10 ms
17,868 KB
testcase_02 AC 10 ms
17,900 KB
testcase_03 AC 10 ms
17,768 KB
testcase_04 AC 10 ms
17,816 KB
testcase_05 AC 10 ms
17,732 KB
testcase_06 AC 10 ms
17,904 KB
testcase_07 AC 199 ms
21,960 KB
testcase_08 AC 197 ms
21,960 KB
testcase_09 AC 199 ms
21,964 KB
testcase_10 AC 199 ms
22,104 KB
testcase_11 AC 202 ms
22,092 KB
testcase_12 AC 203 ms
22,092 KB
testcase_13 AC 207 ms
22,092 KB
testcase_14 AC 206 ms
21,944 KB
testcase_15 AC 203 ms
22,204 KB
testcase_16 AC 198 ms
22,260 KB
testcase_17 AC 204 ms
21,964 KB
testcase_18 AC 206 ms
22,008 KB
testcase_19 AC 206 ms
22,020 KB
testcase_20 AC 203 ms
22,008 KB
testcase_21 AC 198 ms
22,256 KB
testcase_22 AC 184 ms
24,988 KB
testcase_23 AC 185 ms
24,908 KB
testcase_24 AC 185 ms
24,852 KB
testcase_25 AC 184 ms
24,864 KB
testcase_26 AC 189 ms
24,920 KB
testcase_27 AC 187 ms
24,864 KB
testcase_28 AC 185 ms
24,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

   #include <bits/stdc++.h>
 
//    #include <boost/multiprecision/cpp_int.hpp>
 #define int long long
 #define inf  1000000007
 #define pa pair<int,int>
 #define ll long long
 #define pal pair<double,double>
 #define ppap pair<pa,int>
  #define PI 3.14159265358979323846
  #define paa pair<int,char>
  #define  mp make_pair
  #define  pb push_back
  #define EPS (1e-8)
                                          
    int dx[8]={0,1,0,-1,1,1,-1,-1};
    int dy[8]={1,0,-1,0,-1,1,1,-1};
                                            using namespace std;
                                   			class pa3{
                                            	public:
                                            	int x;
                                   				int y,z;
                                            	pa3(int x=0,int y=0,int z=0):x(x),y(y),z(z) {}
                                            	bool operator < (const pa3 &p) const{
                                            		if(x!=p.x) return x<p.x;
                                            		if(y!=p.y) return y<p.y;
                                            		 return z<p.z;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                   				bool operator > (const pa3 &p) const{
                                            		if(x!=p.x) return x>p.x;
                                            		if(y!=p.y) return y>p.y;
                                            		 return z>p.z;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa3 &p) const{
                                            		return x==p.x && y==p.y && z==p.z;
                                            	}
                                            		bool operator != (const pa3 &p) const{
                                            			return !( x==p.x && y==p.y && z==p.z);
                                            	}
                                            
                                            };
                                            
                                            class pa4{
                                            	public:
                                            	int x;
                                            	int y,z,w;
                                            	pa4(int x=0,int y=0,int z=0,int w=0):x(x),y(y),z(z),w(w) {}
                                            	bool operator < (const pa4 &p) const{
                                            		if(x!=p.x) return x<p.x;
                                            		if(y!=p.y) return y<p.y;
                                            		if(z!=p.z)return z<p.z;
                                            		return w<p.w;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator > (const pa4 &p) const{
                                            		if(x!=p.x) return x>p.x;
                                            		if(y!=p.y) return y>p.y;
                                            		if(z!=p.z)return z>p.z;
                                            		return w>p.w;
                                            		//return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa4 &p) const{
                                            		return x==p.x && y==p.y && z==p.z &&w==p.w;
                                            	}
                                            		
                                            
                                            };
                                            class pa2{
                                            	public:
                                            	int x,y;
                                            	pa2(int x=0,int y=0):x(x),y(y) {}
                                            	pa2 operator + (pa2 p) {return pa2(x+p.x,y+p.y);}
                                            	pa2 operator - (pa2 p) {return pa2(x-p.x,y-p.y);}
                                            	bool operator < (const pa2 &p) const{
                                            		return y != p.y ? y<p.y: x<p.x;
                                            	}
                                            	bool operator > (const pa2 &p) const{
                                            		return x != p.x ? x<p.x: y<p.y;
                                            	}
                                            	bool operator == (const pa2 &p) const{
                                            		return abs(x-p.x)==0 && abs(y-p.y)==0;
                                            	}
                                            	bool operator != (const pa2 &p) const{
                                            		return !(abs(x-p.x)==0 && abs(y-p.y)==0);
                                            	}
                                            		
                                            
                                            };
                                            
 
                      
                                string itos( int i ) {
                                ostringstream s ;
                                s << i ;
                                return s.str() ;
                                }
                                 
                                int gcd(int v,int b){
                                	if(v==0) return b;
                                	if(b==0) return v;
                                	if(v>b) return gcd(b,v);
                                	if(v==b) return b;
                                	if(b%v==0) return v;
                                	return gcd(v,b%v);
                                }
                 
                            
                                int mod;
int extgcd(int a, int b, int &x, int &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int d = extgcd(b, a%b, y, x);
    y -= a/b * x;
    return d;
}
pa operator+(const pa & l,const pa & r) {   
    return {l.first+r.first,l.second+r.second};                                    
}    
pa operator-(const pa & l,const pa & r) {   
    return {l.first-r.first,l.second-r.second};                                    
}  
                                
                int pr[1000010];
                int inv[1000010];
                
                int beki(int wa,int rr,int warukazu){
                	if(rr==0) return 1%warukazu;
                	if(rr==1) return wa%warukazu;
                	wa%=warukazu;
                	if(rr%2==1) return ((ll)beki(wa,rr-1,warukazu)*(ll)wa)%warukazu;
                	ll zx=beki(wa,rr/2,warukazu);
                	return (zx*zx)%warukazu;
                }
 
                
    			int comb(int nn,int rr){
    				if(rr<0 || rr>nn || nn<0) return 0;
    				int r=pr[nn]*inv[rr];
    				r%=mod;
    				r*=inv[nn-rr];
    				r%=mod;
    				return r;
    			}
               
                void gya(int ert){
                	pr[0]=1;
                	for(int i=1;i<=ert;i++){
                		pr[i]=(pr[i-1]*i)%mod;
                	}
                		inv[ert]=beki(pr[ert],mod-2,mod);
                	for(int i=ert-1;i>=0;i--){
                		inv[i]=inv[i+1]*(i+1)%mod;
                	}
                }
                
              //   cin.tie(0);
    		//	ios::sync_with_stdio(false);
    			//priority_queue<pa3,vector<pa3>,greater<pa3>> pq;            
                 //sort(ve.begin(),ve.end(),greater<int>());
 //   mt19937(clock_per_sec);
  //  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) ;
      
       
       
                               //----------------kokomade tenpure------------


// 範囲を一様にa倍してb足す操作.区間maxminsumに対応

//要はupdate, addにも対応して3種の区間クエリに回答可能



	using Node =int;
	using Sayo =int;

struct seg_chusho{
	//       1
	//   2        3
	// 4   5   6    7
	
	
	private:
	public:
	
	// (1<<15)=32768
	// 1<<16 = 65536
	// 1<<17 = 131072
	// 1<<18 = 262144
	
	int cor=(1<<18);

	
	

	
	/*
	struct Node{
		int mi;
		int ma;
		int su;
	};
	
	struct Sayo{
		int a;
		int b;
		
		
		bool operator==(sayo v){
			return a==v.a && b==v.b;
		}
	};
	*/
	// 遅延が貯まっていないときに保持する値
	Sayo S_id=0;
	
	Node N_id=0;
	vector<int> ho; 
	Node node_merge(Node x,Node y){
		// x と yをマージする 区間和なら和
		return x+y;
		// ここに実装する

	}
	Sayo merge_sayo(Sayo x,Sayo y){
		// 作用xの上から作用yを更にのっける
		return x+y;
		
		// ここに実装する
		
		
		
	}
	
	Node node_sayo(Node x,Sayo y,int l,int r,int k){
		// 区間[l,r)のNode x に作用yを載せる
		// x == N_idの心配は基本的に不要
		// y == S_id も不必要

	return x+y*ho[k];
		
		// ここに実装する
		
		
	}
	
	
	vector<Node> vec;
	vector<Sayo> lazy;
	
	void shoki1(){
		//S_id,N_idが未定義ならここでやる
		
		ho.resize(2*cor+3,0);
		vec.resize(2*cor+3, N_id);
		lazy.resize(2*cor+3,S_id);
	}
	void shoki2(){
		for(int i=cor-1;i>0;i--) vec[i]=node_merge(vec[2*i],vec[2*i+1]),ho[i]=ho[2*i]+ho[2*i+1];
	}
	
	
	void chien(int k,int l,int r){
		if(lazy[k]==S_id) return;
		if(l+1<r){
			vec[k]=node_sayo(vec[k],lazy[k],l,r,k);
			lazy[2*k]=merge_sayo(lazy[2*k],lazy[k]);
			lazy[2*k+1]=merge_sayo(lazy[2*k+1],lazy[k]);
			lazy[k]=S_id;
		}
		else {
			vec[k]=node_sayo(vec[k],lazy[k],l,r,k);
			lazy[k]=S_id;
		}
	}
	
	Node rangeshori(int a,int b,Sayo w, int k=1,int l=0,int r=-3){
		
		if(r<0) r=cor;
		
		if(a<=l && r<=b){
			lazy[k]=merge_sayo(lazy[k],w);
			chien(k,l,r);
			return vec[k];
		}
		if(r<=a || b<=l){
			chien(k,l,r);
			return vec[k];
		}
		
		chien(k,l,r);
		Node w1=rangeshori(a,b,w,k*2,l,(l+r)/2);
		Node w2=rangeshori(a,b,w,k*2+1,(l+r)/2,r);
		vec[k]=node_merge(w1,w2);
		return vec[k];
	}

	
	

	// [a,b)
	// k-th node
	// k no kukanha [l,r)
	
	Node getrange(int a,int b,int k=1,int l=0,int r=-1){
		
		if(r<0) r=cor;
		chien(k,l,r);
		if(r<=a || b<=l){// 区間外
			return N_id;
		}
		
		if(a<=l && r<=b){// 完全含む
			
			return vec[k];
		}
		Node w1=getrange(a,b,k*2,l,(l+r)/2);
		Node w2=getrange(a,b,k*2+1,(l+r)/2,r);
		return node_merge(w1,w2);

	}
	

};


seg_chusho ss;

vector<pa> G[100020];
int cnt=0;
int fis[100020];
int las[100020];
void dfs(int r){
	fis[r]=cnt;
	for(auto v:G[r]){
		ss.ho[ss.cor+cnt]=1;
		ss.vec[ss.cor+cnt]=v.second;
		cnt++;
		dfs(v.first);
		ss.ho[ss.cor+cnt]=-1;
		ss.vec[ss.cor+cnt]=-v.second;
		cnt++;
	}
	las[r]=cnt;
}
signed main(){

   cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int y,yy,yyy;
		cin>>y>>yy>>yyy;
		G[y].pb(mp(yy,yyy));
	}
	
	
	ss.shoki1();
	
	dfs(0);
	
	ss.shoki2();
	
	
	int q;
	cin>>q;
	//for(int i=0;i<n;i++)cout<<fis[i]<<" "<<las[i]<<endl;
	for(int i=0;i<q;i++){
		int y;
		cin>>y;
		if(y==1){
			int a,x;
			cin>>a>>x;
			ss.rangeshori(fis[a],las[a],x);
		}
		else{
			int b;
			cin>>b;
			cout<<ss.getrange(0,las[b])<<endl;
	}
	}

	
return 0;
 	
 
 }
0