malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int arr[600][600] = {};   int visited[600][600] = {};   void dfs(int, int);   int main() {     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         char t;         cin >> t;         if (t ==  . ) {           arr[i][j] = 1;         }         if (t ==  # ) arr[i][j] = 2;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (arr[i][j] == 1) {           dfs(i, j);           break;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (arr[i][j] == 1) cout <<  . ;         if (arr[i][j] == 2) cout <<  # ;         if (arr[i][j] == 3) cout <<  X ;       }       cout << endl;     }   }   void dfs(int i, int j) {     visited[i][j] = 1;     if (arr[i][j + 1] == 1 && !visited[i][j + 1]) {       dfs(i, j + 1);     }     if (arr[i + 1][j] == 1 && !visited[i + 1][j]) {       dfs(i + 1, j);     }     if (arr[i][j - 1] == 1 && !visited[i][j - 1]) {       dfs(i, j - 1);     }     if (arr[i - 1][j] == 1 && !visited[i - 1][j]) {       dfs(i - 1, j);     }     if (k) {       arr[i][j] = 3;       k--;     }   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   long long arr[200005];   pair<long long, long long> pt[200005];   int main() {     long long n, x, y, newX, newY, cnt = 0, ansX, ansY, val = 0;     map<pair<long long, long long>, long long> mp1;     cin >> n >> x >> y;     for (int i = 0; i < n; i++) {       cin >> pt[i].first >> pt[i].second;     }     newX = x + 1, newY = y;     for (int i = 0; i < n; i++) {       if (newX >= min(pt[i].first, x) and newX <= max(pt[i].first, x)) {         if (newY >= min(pt[i].second, y) and newY <= max(pt[i].second, y)) cnt++;       }     }     mp1[{newX, newY}] = cnt;     cnt = 0;     newX = x - 1, newY = y;     for (int i = 0; i < n; i++) {       if (newX >= min(pt[i].first, x) and newX <= max(pt[i].first, x)) {         if (newY >= min(pt[i].second, y) and newY <= max(pt[i].second, y)) cnt++;       }     }     mp1[{newX, newY}] = cnt;     cnt = 0;     newX = x, newY = y + 1;     for (int i = 0; i < n; i++) {       if (newX >= min(pt[i].first, x) and newX <= max(pt[i].first, x)) {         if (newY >= min(pt[i].second, y) and newY <= max(pt[i].second, y)) cnt++;       }     }     mp1[{newX, newY}] = cnt;     cnt = 0;     newX = x, newY = y - 1;     for (int i = 0; i < n; i++) {       if (newX >= min(pt[i].first, x) and newX <= max(pt[i].first, x)) {         if (newY >= min(pt[i].second, y) and newY <= max(pt[i].second, y)) cnt++;       }     }     mp1[{newX, newY}] = cnt;     for (auto it = mp1.begin(); it != mp1.end(); it++) {       if (it->second > val) {         val = it->second;         ansX = it->first.first;         ansY = it->first.second;       }     }     cout << val << endl;     cout << ansX <<     << ansY << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<string> rs;     if (n == 1) {       rs.push_back( a );       rs.push_back( a );       rs.push_back( b );       rs.push_back( b );     } else if (n == 2) {       rs.push_back( aa );       rs.push_back( bb );       rs.push_back( aa );       rs.push_back( bb );     } else if (n == 3) {       rs.push_back( aac );       rs.push_back( bbc );       rs.push_back( add );       rs.push_back( abb );     } else if (n == 4) {       rs.push_back( aabb );       rs.push_back( cddc );       rs.push_back( ceec );       rs.push_back( aabb );     } else if (n % 2 == 0) {       int b = 0;       int c = 5;       int d = 10;       string pal1 =   ;       string pal2 =  z ;       string pal3 =  z ;       for (int i = 0; i < n / 2; i++) {         b = (b + 1) % 24;         c = (c + 1) % 24;         d = (d + 1) % 24;         pal1 += string(2, char( a  + b));         if (i == n / 2 - 1) continue;         pal2 += string(2, char( a  + c));         pal3 += string(2, char( a  + d));       }       pal2 +=  z ;       pal3 +=  z ;       rs.push_back(pal1);       rs.push_back(pal2);       rs.push_back(pal3);       rs.push_back(pal1);     } else if (n % 2 != 0) {       int b = 0;       int c = 5;       int d = 10;       string pal1 =   ;       string pal2 =   ;       string pal3 =  z ;       for (int i = 0; i < n / 2; i++) {         b = (b + 1) % 24;         c = (c + 1) % 24;         d = (d + 1) % 24;         pal1 += string(2, char( a  + b));         pal2 += string(2, char( a  + c));         pal3 += string(2, char( a  + d));       }       string pal4 =  z  + pal1;       pal1 +=  z ;       pal2 +=  z ;       rs.push_back(pal1);       rs.push_back(pal2);       rs.push_back(pal3);       rs.push_back(pal4);     }     for (int i = int(0); i < int(4); i++) {       cout << rs[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-6;   int H[1005];   int main() {     int n, m, h;     int l, r, x;     int i, j;     scanf( %d%d%d , &n, &h, &m);     for (i = 1; i <= n; i++) H[i] = h;     for (i = 0; i < m; i++) {       scanf( %d%d%d , &l, &r, &x);       for (j = l; j <= r; j++) H[j] = min(H[j], x);     }     int ans = 0;     for (i = 1; i <= n; i++) ans += H[i] * H[i];     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[500006];   long long dp[500006];   long long vis[500006];   vector<long long> v[500006];   long long on;   long long n, d, che;   void dfs(long long root, long long parent) {     vis[root] = 1;     dp[root] = 1;     for (auto it : v[root]) {       if (!vis[it]) {         dfs(it, root);         if (a[it] == che && it < on) {           continue;         }         if (it != parent && che <= a[it] && a[it] <= che + d) {           (dp[root] *= (1 + dp[it])) %= 1000000007;         }       }     }   }   void solve() {     cin >> d >> n;     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 0; i < n - 1; i++) {       long long a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     long long ans = 0;     for (long long i = 1; i <= n; i++) {       on = i;       for (long long j = 1; j <= n; j++) vis[j] = dp[j] = 0;       che = a[i];       dfs(i, -1);       (ans += dp[i]) %= 1000000007;     }     cout << ans <<   n ;   }   signed main() {     ios_base ::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 64;   int n, m, r, a[maxn][maxn], dis[maxn];   int dp[maxn][maxn][maxn];   set<pair<int, int> > s;   void dij(int v) {     memset(dis, 127, sizeof dis);     dis[v] = 0;     s.insert(make_pair(dis[v], v));     while (s.size()) {       v = s.begin()->second;       s.erase(s.begin());       for (int u = 0; u < n; u++)         if (dis[v] + a[v][u] < dis[u]) {           s.erase(make_pair(dis[u], u));           dis[u] = dis[v] + a[v][u];           s.insert(make_pair(dis[u], u));         }     }   }   void set_distance() {     memset(dis, 127, sizeof dis);     for (int i = 0; i < n; i++) {       dij(i);       for (int j = 0; j < n; j++)         if (dis[j] < dp[i][j][0]) dp[i][j][0] = dis[j];     }   }   void update_dp() {     for (int k = 1; k < n; k++)       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++)           for (int l = 0; l < n; l++)             dp[i][j][k] = min(dp[i][j][k], dp[i][l][k - 1] + dp[l][j][0]);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> r;     memset(dp, 31, sizeof dp);     while (m--) {       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) cin >> a[i][j];       set_distance();     }     update_dp();     for (int S, T, k; r--;) {       cin >> S >> T >> k;       cout << dp[S - 1][T - 1][min(k, n - 2)] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005], b[100005], c[100005];   class segtree {    public:     int seg[524288 * 2];     int lazy[524288 * 2];     void init() {       for (int i = 0; i < 524288 * 2; i++) {         seg[i] = 0;       }     }     void lazy_evaluate(int x) {       if (x * 2 + 2 >= 524288 * 2) return;       lazy[x * 2 + 1] += lazy[x];       lazy[x * 2 + 2] += lazy[x];       seg[x * 2 + 1] += lazy[x];       seg[x * 2 + 2] += lazy[x];       lazy[x] = 0;     }     int update(int a, int b, int k, int lb, int ub, int val) {       pair<int, int> p;       p.first = -2000000000, p.second = -2000000000;       if (ub < a || b < lb) return seg[k];       if (a <= lb && ub <= b) {         lazy[k] += val;         seg[k] += val;         return seg[k];       }       if (lazy[k]) lazy_evaluate(k);       int p1 = update(a, b, k * 2 + 1, lb, (lb + ub) / 2, val);       int p2 = update(a, b, k * 2 + 2, (lb + ub) / 2 + 1, ub, val);       return seg[k] = max(p1, p2);     }     int query() { return seg[0]; }   } seg;   int main() {     int n;     vector<pair<int, pair<int, int> > > p;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d %d , &a[i], &b[i], &c[i]);       p.push_back(make_pair(a[i], make_pair(b[i], c[i])));     }     sort(p.begin(), p.end());     seg.init();     int ret = -1;     int lb, ub;     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         que;     for (int i = 0; i < n; i++) {       while (!que.empty() && p[i].first > que.top().first) {         seg.update(p[que.top().second].second.first,                    p[que.top().second].second.second, 0, 0, 524288 - 1, -1);         que.pop();       }       que.push(make_pair(p[i].second.first, i));       seg.update(p[i].second.first, p[i].second.second, 0, 0, 524288 - 1, 1);       int pp = seg.query();       if (pp > ret) {         ret = pp;         lb = p[i].first;       }     }     printf( %d n , ret);     priority_queue<int, vector<int>, greater<int> > que2;     int next;     vector<pair<int, int> > in;     for (int i = 0; i < n; i++) {       if (p[i].second.first >= lb && p[i].first <= lb) {         in.push_back(make_pair(p[i].second.first, i));       }     }     sort(in.begin(), in.end());     next = 0;     for (int j = lb;; j++) {       while (!que2.empty() && que2.top() < j) que2.pop();       while (next != in.size() && in[next].first <= j) {         que2.push(p[in[next].second].second.second);         next++;       }       if (que2.size() == ret) {         ub = j;         break;       }     }     int x = 0;     for (int i = 0; i < n; i++) {       if (a[i] <= lb && ub <= c[i] && lb <= b[i] && b[i] <= ub) {         x++;         printf( %d%c , i + 1, x == ret ?   n  :    );       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int ans;   int p1 = 1 << 17;   int p2 = 1 << 18;   void solve(int x) {     int a = p1 | x;     int b = p2 | p1;     cout << a <<     << b <<     << p2;   }   int main() {     cin >> n >> k;     if (n == 2 && k == 0) {       cout <<  NO  << endl;       return 0;     }     if (n == 1) {       cout <<  YES n  << k << endl;       return 0;     }     if (n == 2) {       cout <<  YES n  << k <<     <<  0  << endl;       return 0;     }     cout <<  YES n ;     for (int i = 1; i <= n - 3; i++) {       cout << i <<    ;       ans ^= i;     }     solve(ans ^ k);   }
#include <bits/stdc++.h>   using namespace std;   const int max_N = 2e5 + 10;   const int l_N = 20;   int st[l_N][max_N];   int lg[max_N];   int inp[max_N];   vector<int> bits[30];   int query_max(int i, int j);   int main() {     {       int j = 0;       for (int i = 0; i < max_N; ++i) {         while ((1 << j) <= i) {           ++j;         }         lg[i] = j - 1;       }     }     int N;     scanf( %d , &N);     for (int i = 1; i <= N; ++i) {       scanf( %d , &inp[i]);       st[0][i] = inp[i];     }     for (int j = 1; j < l_N; ++j) {       for (int i = 1; i + (1 << j) - 1 <= N; ++i) {         st[j][i] = max(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);       }     }     for (int i = 1; i <= N; ++i) {       for (int j = 0; j < 30; ++j) {         if ((inp[i] >> j) & 1) {           bits[j].push_back(i);         }       }     }     long long ans = 0;     for (int i = 1; i <= N; ++i) {       vector<int> or_changes;       for (int j = 0; j < 30; ++j) {         auto it = lower_bound(bits[j].begin(), bits[j].end(), i);         if (it != bits[j].end()) {           or_changes.push_back(*it);         }       }       sort(or_changes.begin(), or_changes.end());       or_changes.push_back(N + 1);       int cid = *or_changes.begin();       int cor = inp[cid];       for (int j = 1; j < or_changes.size(); ++j) {         int L = cid, R = or_changes[j];         int low = L, high = R - 1, mid, best = R;         while (low <= high) {           mid = (low + high) >> 1;           if (query_max(L, mid) >= cor) {             best = mid;             high = mid - 1;           } else {             low = mid + 1;           }         }         ans += best - L;         cid = R;         cor |= inp[R];       }     }     cout << ans << endl;   }   int query_max(int i, int j) {     int d = lg[j - i + 1];     return max(st[d][i], st[d][j - (1 << d) + 1]);   }
#include <bits/stdc++.h>   using namespace std;   int num[1005];   char num0[1005];   int res1[1005];   int N;   int query() {     int res = 0;     for (int i = 0; i < N; i++) {       if (num[i] != 0) {         res *= 10;         res += num[i];       } else if (num[i] == 0) {         res *= 10;       }     }     return res >= 0 ? res : -res;   }   int move_1() {     int t = num[0];     for (int i = 0; i < N - 1; i++) {       num[i] = num[i + 1];     }     num[N - 1] = t;     return 0;   }   int up1() {     for (int i = 0; i < N; i++) {       if (num[i] == 9) {         num[i] = 0;       } else {         num[i] += 1;       }     }     return 0;   }   void print() {     printf(  num =  );     for (int i = 0; i < N; i++) {       printf( %d , num[i]);     }     puts(  );   }   void printres() {     for (int i = 0; i < N; i++) {       printf( %d , res1[i]);     }     puts(  );   }   int panduan() {     char temp1[1005], temp2[1005];     for (int i = 0; i < N; i++) {       temp1[i] = num[i] +  0 ;     }     for (int i = 0; i < N; i++) {       temp2[i] = res1[i] +  0 ;     }     if (strcmp(temp1, temp2) < 0) {       return 1;     } else       return 0;   }   int copy1() {     for (int i = 0; i < N; i++) {       num[i] = num0[i] -  0 ;     }     return 0;   }   int copy2() {     for (int i = 0; i < N; i++) {       res1[i] = num[i];     }     return 0;   }   int main() {     while (scanf( %d , &N) != EOF) {       getchar();       for (int i = 0; i < N; i++) {         scanf( %c , &num0[i]);       }       int res = 1e9;       copy1();       copy2();       for (int i = 0; i < 10; i++) {         for (int j = 1; j <= N; j++) {           move_1();           if (panduan() > 0) {             copy2();           }         }         up1();       }       printres();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long nax = 100001;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n);       for (auto& x : a) {         cin >> x;       }       if (a[0]) {         cout << n + 1 <<    ;         for (int i = 1; i <= n; ++i) {           cout << i <<    ;         }         cout <<   n ;         continue;       }       if (!a.back()) {         for (int i = 1; i <= n + 1; ++i) {           cout << i <<    ;         }         cout <<   n ;         continue;       }       for (int i = 0; i < n - 1; ++i) {         if (a[i] == 0 && a[i + 1] == 1) {           for (int j = 1; j <= i + 1; ++j) {             cout << j <<    ;           }           cout << n + 1 <<    ;           for (int j = i + 2; j <= n; ++j) {             cout << j <<    ;           }           cout <<   n ;           break;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int x, n, p;   int a[1005];   long double f[205][205][205];   int check(int m) {     int s = 0;     while (m % 2 == 0) {       s++;       m /= 2;     }     return s;   }   int main() {     ios_base::sync_with_stdio(false);     int i, j, k;     long double xx, yy;     cin >> x >> n >> p;     xx = (long double)p / 100.0;     yy = (long double)(100 - p) / 100.0;     for (i = 0; i <= 1000; i++) a[i] = check(x + i);     for (j = 0; j <= 201; j++) {       for (k = 0; k <= 201; k++) {         f[0][j][k] = (long double)(a[j] + k);       }     }     for (i = 1; i <= n; i++) {       for (j = 0; j <= 200; j++) {         for (k = 0; k <= 200; k++) {           f[i][j][k] = f[i - 1][j + 1][k] * yy;           if (j % 2 == 0)             f[i][j][k] += (f[i - 1][j / 2][k + 1] * xx);           else             f[i][j][k] += ((long double)k * xx);         }       }     }     cout.precision(9);     cout << fixed << f[n][0][0] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int tr[100001];   int sum(int ind) {     int sum = 0;     ind = ind + 1;     while (ind) {       sum += tr[ind];       ind -= ind & (-ind);     }     return sum;   }   void update(int ind, int val) {     ++ind;     while (ind <= 100000) {       tr[ind] += val;       ind += ind & (-ind);     }   }   int main() {     int n;     cin >> n;     vector<int> a(n);     set<int> ind[100001];     for (int i = 0; i < n; ++i) {       cin >> a[i];       ind[a[i]].emplace(i);     }     long long ans = 1;     int pos = 0;     sort(a.begin(), a.end());     for (int i = 0; i < n; ++i) {       int next;       if (i > 0 && a[i] == a[i - 1]) {         next = (ind[a[i]].upper_bound(pos) == ind[a[i]].end())                    ? *(ind[a[i]].begin())                    : *(ind[a[i]].upper_bound(pos));       } else {         next = (ind[a[i]].lower_bound(pos) == ind[a[i]].end())                    ? *(ind[a[i]].begin())                    : *(ind[a[i]].lower_bound(pos));       }       int rn = next - sum(next);       int rp = pos - sum(pos);       ans += (rn >= rp) ? (long long)(rn - rp) : (long long)(n - i - rp + rn + 1);       if (i) update(pos, 1);       pos = next;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2000000;   const int mod = 998244353;   int used[N][2];   int f[N][2];   bool ok[N];   int solve(int n, int k) {     if (used[n][k]) {       return f[n][k];     }     if (!ok[n]) {       return 0;     }     int last = 0;     int m = n;     int j = 0;     for (int i = 0; i < 40; i++) {       if ((1 << i) > m) {         last = m;         break;       }       j = i;       m -= (1 << i);     }     if (m == 0) {       used[n][k] = 1;       f[n][k] = 0;       return 0;     }     int ans = 0;     int nxt = (1 << j);     int sz = (n - last) / 2;     for (int i = max(0, last - sz - 1); i <= min(last, sz + 1); i++) {       if ((sz + i) % 2 != k) {         continue;       }       ans += 1ll * (solve(sz + i, 0) + solve(sz + i, 1)) % mod *              solve(sz + last - i, 1) % mod;       if (ans >= mod) {         ans -= mod;       }     }     used[n][k] = 1;     f[n][k] = ans;     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     int x = 1;     int v = 0;     while (x <= n) {       ok[x] = 1;       ok[x + 1] = 1;       x++;       x = x * 2 - v;       v = 1 - v;     }     used[0][0] = 1;     f[0][0] = 1;     used[0][1] = 1;     f[0][1] = 1;     used[1][0] = 1;     f[1][0] = 1;     used[1][1] = 1;     f[1][1] = 0;     cout << (solve(n, 0) + solve(n, 1)) % mod <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     long long a, b, c;     for (scanf( %d , &T); T; T--) {       cin >> a >> b >> c;       if (a >= c) {         printf( -1  );       } else         printf( 1  );       if (a * b > c)         printf( %I64d n , b);       else         printf( -1 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void upmax(T& a, T b) {     if (a < b) a = b;   }   template <class T>   inline void upmin(T& a, T b) {     if (a > b) a = b;   }   const int maxn = 307;   const int maxm = 100007;   const int mod = 1000000007;   const int inf = 0x7fffffff;   const double eps = 1e-7;   typedef int arr[maxn];   typedef int adj[maxm];   inline int fcmp(double a, double b) {     if (fabs(a - b) <= eps) return 0;     if (a < b - eps) return -1;     return 1;   }   inline int add(int a, int b) { return ((long long)a + b) % mod; }   inline int mul(int a, int b) { return ((long long)a * b) % mod; }   inline int dec(int a, int b) { return add(a, mod - b % mod); }   inline int Pow(int a, int b) {     int t = 1;     while (b) {       if (b & 1) t = mul(t, a);       a = mul(a, a), b >>= 1;     }     return t;   }   template <typename Type>   inline Type RD() {     char c = getchar();     Type x = 0, flag = 1;     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       flag = -1;     else       x = c -  0 ;     while (isdigit(c = getchar())) x = x * 10 + c -  0 ;     return x * flag;   }   inline char rdch() {     char c = getchar();     while (!isalpha(c)) c = getchar();     return c;   }   int n, m, k;   double C[maxn][maxn], f[maxm];   void input() {     n = RD<int>(), m = RD<int>(), k = RD<int>();     for (int i = 0, _ = n; i <= _; i++) {       C[i][0] = 1;       for (int j = 1, _ = i; j <= _; j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];     }     f[0] = 1;     for (int i = 1, _ = k; i <= _; i++)       f[i] = f[i - 1] * (k - i + 1) / (m - i + 1);   }   void solve() {     double ans = 0;     for (int i = 0, _ = n; i <= _; i++) {       for (int j = 0, _ = n; j <= _; j++) {         ans += C[n][i] * C[n][j] * f[(i + j) * n - i * j];         if (ans > 1e99) break;       }       if (ans > 1e99) break;     }     if (ans > 1e99) ans = 1e99;     printf( %.10lf n , ans);   }   int main() {     input();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int n, Q, pos;   long long a[maxn], sum[maxn], x;   long long tr[maxn << 2], tag[maxn << 2];   void pushup(int rt) { tr[rt] = max(tr[rt << 1], tr[rt << 1 | 1]); }   void build(int rt = 1, int l = 1, int r = n) {     tag[rt] = 0;     if (l == r) {       tr[rt] = sum[l];       return;     }     int mid = (l + r) >> 1;     build(rt << 1, l, mid);     build(rt << 1 | 1, mid + 1, r);     pushup(rt);   }   void load(int rt, long long k) {     tag[rt] += k;     tr[rt] += k;   }   void pushdown(int rt, int l, int r) {     if (tag[rt] == 0) return;     load(rt << 1, tag[rt]);     load(rt << 1 | 1, tag[rt]);     tag[rt] = 0;   }   void update(int nl, int nr, long long k, int l = 1, int r = n, int rt = 1) {     if (nl <= l && nr >= r) {       load(rt, k);       return;     }     pushdown(rt, l, r);     int mid = (l + r) >> 1;     if (nl <= mid) update(nl, nr, k, l, mid, rt << 1);     if (nr >= mid + 1) update(nl, nr, k, mid + 1, r, rt << 1 | 1);     pushup(rt);   }   long long temp_x;   int id;   int get_pos(long long limit, int l = 1, int r = n, int rt = 1) {     if (l == r) {       temp_x = tr[rt];       return l;     }     pushdown(rt, l, r);     int mid = (l + r) >> 1;     if (tr[rt << 1] >= limit)       return get_pos(limit, l, mid, rt << 1);     else       return get_pos(limit, mid + 1, r, rt << 1 | 1);   }   void go() {     long long now_x = 0;     int now_id = 0;     while (now_id != n) {       int temp_id = get_pos(2 * now_x);       if (temp_x == 2 * a[temp_id]) {         printf( %d n , temp_id);         return;       }       now_id = temp_id;       now_x = temp_x;     }     puts( -1 );   }   int main() {     scanf( %d %d , &n, &Q);     for (int i = 1; i <= n; i++) {       scanf( %lld , a + i);       sum[i] = sum[i - 1] + a[i];     }     build();     while (Q--) {       scanf( %d %lld , &pos, &x);       update(pos, n, x - a[pos]);       a[pos] = x;       go();     }     return 0;   }