Advertisement
ivnikkk

Untitled

Jul 15th, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define debug(tl) cerr<<#tl<<' '<<tl<<'\n';
  3. #include "bits/stdc++.h"
  4. using namespace std;
  5. #define all(d) d.begin(), d.end()
  6. signed main() {
  7. #ifdef _DEBUG
  8.     freopen("input.txt", "r", stdin);
  9.     freopen("output.txt", "w", stdout);
  10. #endif
  11.     ios_base::sync_with_stdio(false);
  12.     cin.tie(nullptr);
  13.     cout.tie(nullptr);
  14.     int n, q;
  15.     cin >> n >> q;
  16.     vector<int> cnt(2e5 + 44);
  17.     vector<int> a(n);
  18.     for (int i = 0; i < n; i++) {
  19.         int x;
  20.         cin >> x;
  21.         a[i] = x;
  22.         cnt[x]++;
  23.     }
  24.     set<int> mx;
  25.     for (int i = 2; i <= 2e5 + 43; i++) {
  26.         cnt[i] += (cnt[i - 1] / 2);
  27.         if(cnt[i])mx.insert(i);
  28.     }
  29.     for (int i = 0; i < q; i++) {
  30.         int k, l;
  31.         cin >> k >> l;
  32.         k--;
  33.         for (int j = a[k]; j <= 2e5; j++) {
  34.             if (cnt[j] % 2 == 0) {
  35.                 cnt[j]--;
  36.                 continue;
  37.             }
  38.             else {
  39.                 cnt[j]--;
  40.                 if (!cnt[j]) {
  41.                     mx.erase(j);
  42.                 }
  43.                 break;
  44.             }
  45.         }
  46.         a[k] = l;
  47.         for (int j = a[k]; l <= 2e5 + 43; j++) {
  48.             if (cnt[j] & 1) {
  49.                 cnt[j]++;
  50.                 continue;
  51.             }
  52.             else {
  53.                 cnt[j]++;
  54.                 if (cnt[j] == 1) {
  55.                     mx.insert(j);
  56.                 }
  57.                 break;
  58.             }
  59.         }
  60.         cout << *--mx.end() << '\n';
  61.     }
  62.     /*int n;
  63.     cin >> n;
  64.     string s(n, 'F');
  65.     int sum;
  66.     auto ask = [&](int& x) {
  67.         cout << s << endl;
  68.         cin >> x;
  69.     };
  70.     ask(sum);
  71.     for (int i = 0; i < n; i++) {
  72.         if (i + 1 < n) {
  73.             s[i] = 'T', s[i + 1] = 'T';
  74.             int ne;
  75.             ask(ne);
  76.             if (ne + 2 == sum) {
  77.                 s[i] = 'F', s[i + 1] = 'F';
  78.                 sum = ne;
  79.                 continue;
  80.             }
  81.             else if(ne == sum){
  82.  
  83.             }
  84.             else {
  85.                 continue;
  86.             }
  87.         }
  88.         else {
  89.  
  90.         }
  91.     }*/
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement