주식회사 승범이네 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566#include <bits/stdc++.h>#define MAX_N 100001using namespace std;int n, m, no = 1;int adj[MAX_N];int in[MAX_N], out[MAX_N];int fenwick[MAX_N + 1];vector<int> radj[MAX_N];void dfs(int u) { in[u] = no; for(auto& v : radj[u]) { no++; dfs(v); } out[u] = no;}void ott() { for(int i = 2; i <= n; i++) { radj[adj[i]].push_back(i); } dfs(1);}void update(int u, int val) { while(u <= n + 1) { fenwick[u] += val; u += u & -u; }}int query(int u) { int res = 0; while(u > 0) { res += fenwick[u]; u -= u & -u; } return res;}int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m; for(int i = 1; i <= n; i++) { cin>>adj[i]; } ott(); int op, u, c; while(m--) { cin>>op; if(op == 1) { cin>>u>>c; update(in[u], c); update(out[u] + 1, -c); } else { cin>>u; cout<<query(in[u])<<'\n'; } }}