Submission #1293691

#TimeUsernameProblemLanguageResultExecution timeMemory
1293691domiSimple game (IZhO17_game)C++20
100 / 100
107 ms18184 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second #define sz(a) (int)((a).size()) #define all(a) (a).begin(), (a).end() #define lsb(x) (x & (-x)) #define vi vector<int> #define YES { cout << "YES" << endl; return; } #define NO { cout << "NO" << endl; return; } using ll = long long; using pii = std::pair<int, int>; const int NMAX = 1e5; const int VMAX = 1e6 + 5; using namespace std; struct Seg { int aint[4 * VMAX + 5]; void update(int pos, int val, int nod = 1, int st = 0, int dr = VMAX) { if (st == dr) { aint[nod] += val; return; } int m = (st + dr) >> 1; if (pos <= m) update(pos, val, 2 * nod, st, m); else update(pos, val, 2 * nod + 1, m + 1, dr); aint[nod] = aint[2 * nod] + aint[2 * nod + 1]; } int query(int l, int r, int nod = 1, int st = 0, int dr = VMAX) { if (st > r || dr < l) return 0; if (l <= st && dr <= r) return aint[nod]; int m = (st + dr) >> 1; return query(l, r, 2 * nod, st, m) + query(l, r, 2 * nod + 1, m + 1, dr); } }aint; int a[NMAX + 5], n, q; void add(int x, int y) { if (x > y)swap(x, y); if (x != y) { aint.update(x + 1, 1); aint.update(y, -1); } } void remove(int x, int y) { if (x > y)swap(x, y); if (x != y) { aint.update(x + 1, -1); aint.update(y, 1); } } signed main() { cin.tie(nullptr)->sync_with_stdio(false); cin >> n >> q; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i + 1 <= n; ++i) add(a[i], a[i + 1]); for (int i = 0, op, pos, val, h; i < q; ++i) { cin >> op; if (op == 1) { cin >> pos >> val; if (pos - 1 >= 1) remove(a[pos - 1], a[pos]); if (pos + 1 <= n) remove(a[pos], a[pos + 1]); a[pos] = val; if (pos - 1 >= 1) add(a[pos - 1], a[pos]); if (pos + 1 <= n) add(a[pos], a[pos + 1]); } if (op == 2) { cin >> h; cout << aint.query(0, h) << '\n'; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...