#include #include #include #include #include #include #include #define max_v 410000 #define cont continue using namespace std; int l[max_v], r[max_v], ord[max_v]; long long BIT[max_v], arr[max_v]; vector adj[max_v]; int n, q, cnt = 0; void U(int k, long long val){ for(; k <=max_v - 1; k += k&-k) BIT[k] += val; } long long S(int k){ return (!k) ? 0ll : BIT[k] + S(k - (k&-k)); } void dfs(int u, int p){ l[u] = ++cnt; ord[cnt] = u; for(int v : adj[u]){ if(v == p) cont; dfs(v, u); } r[u] = ++cnt; ord[cnt] = u; U(cnt, arr[u]); } int main(){ scanf("%d%d", &n, &q); for(int i = 1; i<=n; i++){ scanf("%lld", &arr[i]); } for(int i = 1; i