Submission #1268842

#TimeUsernameProblemLanguageResultExecution timeMemory
1268842kawhietSimple game (IZhO17_game)C++20
0 / 100
10 ms320 KiB
#include <bits/stdc++.h> using namespace std; void fileio(string s) { #ifndef LOCAL freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); #endif } constexpr int N = 1e6; int st[4 * N], lz[4 * N]; void update(int id, int tl, int tr, int l, int r, int v) { if (r < tl || tr < l) return; if (l <= tl && tr <= r) { st[id] += v; lz[id] += v; return; } int x = (id << 1) + 1, y = x + 1, tm = (tl + tr) >> 1; update(x, tl, tm, l, r, v); update(y, tm + 1, tr, l, r, v); st[id] = st[x] + st[y] + lz[id]; } int query(int id, int tl, int tr, int l, int r) { if (r < tl || tr < l) return 0; if (l <= tl && tr <= r) return st[id]; int x = (id << 1) + 1, y = x + 1, tm = (tl + tr) >> 1; return query(x, tl, tm, l, r) + query(y, tm + 1, tr, l, r) + lz[id]; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); fileio("game"); int n, q; cin >> n >> q; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 1; i < n; i++) { update(0, 0, N - 1, min(a[i], a[i - 1]), max(a[i], a[i - 1]), 1); } while (q--) { int t; cin >> t; if (t == 1) { int i, h; cin >> i >> h; i--; if (i != 0) update(0, 0, N - 1, min(a[i], a[i - 1]), max(a[i], a[i - 1]), -1); if (i != n - 1) update(0, 0, N - 1, min(a[i], a[i + 1]), max(a[i], a[i + 1]), -1); a[i] = h; if (i != 0) update(0, 0, N - 1, min(a[i], a[i - 1]), max(a[i], a[i - 1]), 1); if (i != n - 1) update(0, 0, N - 1, min(a[i], a[i + 1]), max(a[i], a[i + 1]), 1); } else { int x; cin >> x; cout << query(0, 0, N - 1, x, x) << '\n'; } } return 0; }

Compilation message (stderr)

game.cpp: In function 'void fileio(std::string)':
game.cpp:6:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:7:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...