CSES - Shared codeLink to this code: https://cses.fi/paste/237707c8fc261ffc61a959/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>order_set;
typedef pair<int, int>pr;
#define all(i) i.begin() , i.end()
#define ft first
#define sn second
#define pb push_back
#define totalone(mask) __builtin_popcount(mask)
#define chkbit(mask,bit) (mask&(1LL << bit))
#define setbit(mask,bit) (mask|(1LL << bit))
#define cngbit(mask,bit) (mask^(1LL << bit))
#define en "\n"
#define dbg(x) cerr<<#x<<" is : "<<x<<en;
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define report cout<<-1<<en
#define sum(n) ((1LL*(n)*(n+1))/ 2LL)
#define sqr(n) (1LL*(n)*(n))
#define vag(a,b) ((a + b - 1)/b)
#define coutv(v) for(auto i: v) cout<<i<<" ";cout<<en;
#define cinv(v) for(auto &i: v) cin >> i;
const int MAXN = 200005;
#define inf 1e15
const int mod = 1e9 + 7;
vector<ll>g[MAXN];
ll vis[MAXN];
vector<ll>a;
ll v[MAXN];
ll n, q, timer;
ll in[MAXN], out[MAXN];
void dfs(ll nd)
{
vis[nd] = 1;
in[nd] = ++timer;
a.pb(v[nd]);
for (auto i : g[nd])
{
if (vis[i]) continue;
dfs(i);
}
out[nd] = timer;
}
struct segment_tree
{
struct node {
ll suru , ses, sm;
void init(ll l, ll r) {
suru = l, ses = r;
if (l == r) sm = a[l];
}
} g[4 * MAXN];
void fill_cn(node &cn, node &ln, node &rn) // fill_current_node
{
cn.sm = ln.sm + rn.sm;
}
void build(ll cn, ll l, ll r)
{
g[cn].init(l, r);
if (l == r ) return;
ll md = l + (r - l) / 2;
build(cn * 2, l, md);
build(cn * 2 + 1, md + 1, r);
fill_cn (g[cn], g[cn * 2] , g[cn * 2 + 1]);
}
void update(ll cn, ll pos, ll val)
{
ll x = g[cn].suru;
ll y = g[cn].ses;
if (y < pos || x > pos) return;
if (pos <= x && pos >= y ) {
g[cn].sm = val;
return;
}
update(cn * 2, pos, val);
update(cn * 2 + 1, pos, val);
fill_cn(g[cn], g[cn * 2], g[cn * 2 + 1]);
}
ll query(ll cn, ll l, ll r)
{
ll x = g[cn].suru;
ll y = g[cn].ses;
if (y < l || x > r) return 0;
if (l <= x && r >= y ) return g[cn].sm;
ll ans = query(cn * 2, l, r);
ans += query(cn * 2 + 1, l, r);
return ans;
}
} stre;
void solve()
{
cin >> n >> q;
a.pb(0);
for (ll i = 1; i <= n; i++) {
cin >> v[i];
}
for (ll i = 1; i < n; i++)
{
ll x, y;
cin >> x >> y;
g[x].pb(y); g[y].pb(x);
}
dfs(1);
// coutv(a);
stre.build(1, 1, n);
while (q--)
{
ll t, x, y;
cin >> t >> x;
if (t == 1)
{
cin >> y;
stre.update(1, in[x], y);
continue;
}
cout << stre.query(1, in[x], out[x]) << en;
}
}
int main()
{
IOS;
ll t;
t = 1;
// cin >> t;
int c = 0;
while ( t-- )
{
// cout<<"Case "<<++c<<": ";
solve();
}
return 0;
}