Submission #1232936

#TimeUsernameProblemLanguageResultExecution timeMemory
1232936BahaminSimple game (IZhO17_game)C++20
100 / 100
327 ms18532 KiB
#include <bits/stdc++.h> using namespace std; template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } #define ll long long #define ld long double #define all(a) (a).begin(), (a).end() #define sui cout.tie(NULL); cin.tie(NULL); ios_base::sync_with_stdio(false) #define lid id << 1 #define rid id << 1 | 1 #define mid ((r + l) >> 1) const int MAX_N = 1e6 + 5; const int MOD = 1e9 + 7; const ll INF = 1e9; const ld EPS = 1e-9; const int LOG = 30; int ops[MAX_N << 2]; void move(int l, int r, int id) { if (l == r - 1) return; ops[lid] += ops[id]; ops[rid] += ops[id]; ops[id] = 0; } void upd(int s, int t, int x, int l, int r, int id) { if (s >= t) swap(s, t); move(l, r, id); if (s <= l && t >= r) { ops[id] += x; return; } if (s < mid) upd(s, t, x, l, mid, lid); if (t > mid) upd(s, t, x, mid, r, rid); } int get(int x, int l, int r, int id) { move(l, r, id); if (l == r - 1) return ops[id]; if (x < mid) return get(x, l, mid, lid); else return get(x, mid, r, rid); } void solve() { int n, m; cin >> n >> m; int h[n]; map<int, int> cnt; int last = 1e6 + 1; for (int i = 0; i < n; i++) { cin >> h[i]; cnt[h[i]]++; if (i) upd(h[i - 1], h[i] + 1, 1, 0, last, 1); } while (m--) { int c; cin >> c; if (c == 1) { int p, v; cin >> p >> v; cnt[h[p - 1]]--; cnt[v]++; if (p > 1) upd(h[p - 2], h[p - 1] + 1, -1, 0, last, 1); if (p < n) upd(h[p - 1], h[p] + 1, -1, 0, last, 1); h[p - 1] = v; if (p > 1) upd(h[p - 2], h[p - 1] + 1, 1, 0, last, 1); if (p < n) upd(h[p - 1], h[p] + 1, 1, 0, last, 1); } else { int h; cin >> h; cout << get(h, 0, last, 1) - cnt[h] << "\n"; } } } int main() { sui; int tc = 1; //cin >> tc; for (int t = 1; t <= tc; t++) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...