func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 7;   const int M = 2e6 + 7;   long long g[M], q[M];   int n, a[N];   void push(int v, int lr, int rl) {     g[v << 1] += q[v];     g[v << 1 | 1] += q[v];     q[v << 1] += q[v];     q[v << 1 | 1] += q[v];     q[v] = 0;   }   void upd1(int v, int lr, int rl, int l, int x) {     if ((lr & rl) == l) {       g[v] += x;       return;     }     push(v, lr, rl);     int m = (lr + rl) >> 1;     if (l <= m)       upd1(v << 1, lr, m, l, x);     else       upd1(v << 1 | 1, m + 1, rl, l, x);     g[v] = max(g[v << 1], g[v << 1 | 1]);   }   void upd2(int v, int lr, int rl, int l, int r, int x) {     if (l > r) return;     if (lr == l && rl == r) {       q[v] += x;       g[v] += x;       push(v, lr, rl);       return;     }     push(v, lr, rl);     int m = (lr + rl) >> 1;     upd2(v << 1, lr, m, l, min(m, r), x);     upd2(v << 1 | 1, m + 1, rl, max(l, m + 1), r, x);     g[v] = max(g[v << 1], g[v << 1 | 1]);   }   int get(int v, int lr, int rl) {     if (g[v] < 0) return -1;     push(v, lr, rl);     if (lr == rl) return (g[v] ? -1 : lr);     int m = (lr + rl) >> 1;     int first = get(v << 1, lr, m);     int second = get(v << 1 | 1, m + 1, rl);     g[v] = max(g[v << 1], g[v << 1 | 1]);     return max(first, second);   }   int main() {     int w, z = 1;     scanf( %d %d , &n, &w);     while (z < n) z <<= 1;     long long sum = 0;     memset(g, (-1000000000000000007), sizeof(g));     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       g[z - 1 + i] = a[i] - sum;       sum += a[i];     }     for (int i = z - 1; i; --i) g[i] = max(g[i << 1], g[i << 1 | 1]);     for (int i = 0, x, y; i < w; ++i) {       scanf( %d %d , &x, &y);       upd1(1, 1, z, x, y - a[x]);       upd2(1, 1, z, x + 1, n, a[x] - y);       a[x] = y;       printf( %d n , get(1, 1, z));     }     return 0;   }   