Submission #576914

#TimeUsernameProblemLanguageResultExecution timeMemory
576914LawlietSimple game (IZhO17_game)C++17
100 / 100
190 ms9596 KiB
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 10; int n, m, v[MAX], op, seg[4 * MAX], x, y, h; void update(int p, int q, int ini, int fim, int pos, int val){ if(fim < p || q < ini) return; if(p <= ini && fim <= q){ seg[pos] += val; return; } int m = (ini + fim) / 2; update(p, q, ini, m, 2 * pos, val); update(p, q, m + 1, fim, 2 * pos + 1, val); return; } int query(int id, int ini, int fim, int pos){ if(id < ini || fim < id) return 0; if(ini == fim) return seg[pos]; int m = (ini + fim) / 2; int a = query(id, ini, m, 2 * pos); int b = query(id, m + 1, fim, 2 * pos + 1); return seg[pos] + a + b; } int main(){ scanf("%d %d", &n, &m); for(int i = 1; i <= n; i++){ scanf("%d", &v[i]); if(i > 1){ int a = min(v[i], v[i - 1]); int b = max(v[i], v[i - 1]); update(a, b, 0,MAX, 1, 1); } } for(int i = 1; i <= m; i++){ scanf("%d", &op); if(op == 1){ scanf("%d %d", &x, &y); if(x > 1){ int a = min(v[x], v[x - 1]); int b = max(v[x], v[x - 1]); update(a, b, 0, MAX, 1, - 1); a = min(y, v[x - 1]); b = max(y, v[x - 1]); update(a, b, 0, MAX, 1, 1); } if(x < n){ int a = min(v[x], v[x + 1]); int b = max(v[x], v[x + 1]); update(a, b, 0, MAX, 1, - 1); a = min(y, v[x + 1]); b = max(y, v[x + 1]); update(a, b, 0, MAX, 1, 1); } v[x] = y; continue; } scanf("%d", &h); printf("%d\n", query(h, 0,MAX, 1)); } return 0; }

Compilation message (stderr)

game.cpp: In function 'int main()':
game.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
game.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         scanf("%d", &v[i]);
      |         ~~~~~^~~~~~~~~~~~~
game.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         scanf("%d", &op);
      |         ~~~~~^~~~~~~~~~~
game.cpp:54:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |             scanf("%d %d", &x, &y);
      |             ~~~~~^~~~~~~~~~~~~~~~~
game.cpp:84:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         scanf("%d", &h);
      |         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...