Submission #1025770

#TimeUsernameProblemLanguageResultExecution timeMemory
1025770phoenixSimple game (IZhO17_game)C++17
22 / 100
1068 ms175484 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int N = 100100; const int M = (1 << 18); ordered_set st[2 * M]; bool count(ordered_set &st, pair<int, int> p) { return (st.lower_bound(p) != st.end() && *st.lower_bound(p) == p); } void insert(int pos, pair<int, int> p) { for (pos += M; pos; pos >>= 1) st[pos].insert(p); } void erase(int pos, pair<int, int> p) { static int iteration = 0; for (pos += M; pos; pos >>= 1) { assert(count(st[pos], p)); st[pos].erase(p); } } int get_lower(int ql, int qr, int H) { int res = 0; for (ql += M, qr += M + 1; ql < qr; ql >>= 1, qr >>= 1) { if (ql & 1) { res += st[ql].order_of_key({H, 0}); ql++; } if (qr & 1) { qr--; res += st[qr].order_of_key({H, 0}); } } return res; } int get_upper(int ql, int qr, int H) { int res = 0; for (ql += M, qr += M + 1; ql < qr; ql >>= 1, qr >>= 1) { if (ql & 1) { res += (int)st[ql].size() - st[ql].order_of_key({H, 0}); ql++; } if (qr & 1) { qr--; res += (int)st[qr].size() - st[qr].order_of_key({H, 0}); } } return res; } int n, m; int h[N]; vector<vector<int>> queries; int main() { ios::sync_with_stdio(0); cin.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif cin >> n >> m; for (int i = 0; i < n; i++) cin >> h[i]; for (int i = 0; i < m; i++) { int tp; cin >> tp; if (tp == 1) { int pos, val; cin >> pos >> val; pos--; queries.push_back({tp, pos, val}); } else { int H; cin >> H; queries.push_back({tp, H}); } } { map<int, int> mp; for (int i = 0; i < n; i++) mp[h[i]] = 1; for (int i = 0; i < m; i++) mp[queries[i].back()] = 1; int k = 0; for (auto &c : mp) c.second = k++; for (int i = 0; i < n; i++) h[i] = mp[h[i]]; for (int i = 0; i < m; i++) queries[i].back() = mp[queries[i].back()]; } for (int i = 0; i < n - 1; i++) { insert(h[i], {h[i + 1], i}); } for (auto c : queries) { int tp = c[0]; if (tp == 1) { int pos = c[1], val = c[2]; if (pos) erase(h[pos - 1], {h[pos], pos - 1}); if (pos < n - 1) erase(h[pos], {h[pos + 1], pos}); h[pos] = val; if (pos) insert(h[pos - 1], {h[pos], pos - 1}); if (pos < n - 1) insert(h[pos], {h[pos + 1], pos}); } else { int H = c[1]; cout << get_upper(0, H, H) + get_lower(H + 1, M - 1, H) << '\n'; } } return 0; }

Compilation message (stderr)

game.cpp: In function 'void erase(int, std::pair<int, int>)':
game.cpp:29:16: warning: unused variable 'iteration' [-Wunused-variable]
   29 |     static int iteration = 0;
      |                ^~~~~~~~~
game.cpp: At global scope:
game.cpp:29:16: warning: 'iteration' defined but not used [-Wunused-variable]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...