Submission #563228

#TimeUsernameProblemLanguageResultExecution timeMemory
563228Tien_NoobSimple game (IZhO17_game)C++17
100 / 100
87 ms6840 KiB
//Make CSP great again //Vengeance #include <bits/stdc++.h> #define TASK "TESTCODE" #define Log2(x) 31 - __builtin_clz(x) using namespace std; const int N = 1e5, M = 1e6; struct FenwickTree { int Tree[M + 1]; void add(int pos, int val) { for (; pos <= M; pos += (pos & (-pos))) { Tree[pos] += val; } } int sum(int pos) { int ret = 0; for (; pos > 0; pos -= (pos & (-pos))) { ret += Tree[pos]; } return ret; } int sum(int l, int r) { return sum(r) - sum(l - 1); } } tree; int h[N + 1], n, q; void read() { cin >> n >> q; for (int i = 1; i <= n; ++ i) { cin >> h[i]; if (i > 1) { tree.add(min(h[i], h[i - 1]), 1); tree.add(max(h[i], h[i - 1]) + 1, -1); } } } void solve() { while(q--) { int t; cin >> t; if (t == 1) { int i, a; cin >> i >> a; if (i < n) { tree.add(min(h[i], h[i + 1]), -1); tree.add(max(h[i], h[i + 1]) + 1, 1); tree.add(min(a, h[i + 1]), 1); tree.add(max(a, h[i + 1]) + 1, -1); } if (i > 1) { tree.add(min(h[i], h[i - 1]), -1); tree.add(max(h[i], h[i - 1]) + 1, 1); tree.add(min(a, h[i - 1]), 1); tree.add(max(a, h[i - 1]) + 1, -1); } h[i] = a; } else { int H; cin >> H; cout << tree.sum(H) << '\n'; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); //freopen(TASK".OUT", "w", stdout); } int t = 1; bool typetest = false; if (typetest) { cin >> t; } for (int __ = 1; __ <= t; ++ __) { //cout << "Case " << __ << ": "; read(); solve(); } }

Compilation message (stderr)

game.cpp: In function 'int main()':
game.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...