結果
| 問題 |
No.900 aδδitivee
|
| コンテスト | |
| ユーザー |
latte0119
|
| 提出日時 | 2019-10-04 22:17:51 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 90 ms / 2,000 ms |
| コード長 | 1,580 bytes |
| コンパイル時間 | 1,452 ms |
| コンパイル使用メモリ | 165,656 KB |
| 実行使用メモリ | 17,224 KB |
| 最終ジャッジ日時 | 2024-10-03 07:55:36 |
| 合計ジャッジ時間 | 4,631 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:60:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
60 | scanf("%lld",&N);
| ~~~~~^~~~~~~~~~~
main.cpp:63:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
63 | scanf("%lld%lld%lld",&a,&b,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:70:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
70 | int Q;scanf("%lld",&Q);
| ~~~~~^~~~~~~~~~~
main.cpp:72:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
72 | int t;scanf("%lld",&t);
| ~~~~~^~~~~~~~~~~
main.cpp:75:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
75 | scanf("%lld%lld",&a,&x);
| ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:80:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
80 | int b;scanf("%lld",&b);
| ~~~~~^~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
int N;
vpint G[111111];
int dep[111111];
int dist[111111];
int tt,tin[111111],tout[111111];
void dfs(int v,int p,int d,int c){
tin[v]=tt++;
dep[v]=d;
dist[v]=c;
for(auto e:G[v]){
if(e.fi==p)continue;
dfs(e.fi,v,d+1,c+e.se);
}
tout[v]=tt;
}
/*
0-indexed
add(k,x): a[k]+=x
sum(k): sum(a[0,k])
space:O(N)
time:O(logN) per query
*/
struct BinaryIndexedTree{
int n;
vector<int>dat;
BinaryIndexedTree(int n=0):n(n){
dat.resize(n+1);
}
void add(int k,int x){
for(k++;k<=n;k+=k&-k)dat[k]+=x;
}
int sum(int k){
int ret=0;
for(k++;k;k-=k&-k)ret+=dat[k];
return ret;
}
};
signed main(){
scanf("%lld",&N);
rep(i,N-1){
int a,b,c;
scanf("%lld%lld%lld",&a,&b,&c);
G[a].pb({b,c});
}
dfs(0,-1,0,0);
BinaryIndexedTree bit0(111111),bit1(111111);
int Q;scanf("%lld",&Q);
while(Q--){
int t;scanf("%lld",&t);
if(t==1){
int a,x;
scanf("%lld%lld",&a,&x);
bit1.add(tin[a],x);bit1.add(tout[a],-x);
bit0.add(tin[a],-dep[a]*x);bit0.add(tout[a],dep[a]*x);
}
else{
int b;scanf("%lld",&b);
int ans=dist[b];
ans+=bit0.sum(tin[b]);
ans+=bit1.sum(tin[b])*dep[b];
printf("%lld\n",ans);
}
}
return 0;
}
latte0119