Submission #1190582

#TimeUsernameProblemLanguageResultExecution timeMemory
1190582lovrotSimple game (IZhO17_game)C++20
0 / 100
1 ms580 KiB
#include <cstdio> #include <algorithm> #include <vector> using namespace std; struct point { int x, y; point() {} point(int x, int y) : x(x), y(y) { } }; const int N = 1e5 + 10; const int M = 1e6 + 10; int f[N]; void add(int x, int w) { for(; x < N; x += x & -x) f[x] += w; } int sum(int x) { int ret = 0; for(; x; x -= x & -x) { ret += f[x]; } return ret; } int n, m; point p[N]; void update(int a, int b, int k) { if(a < 0 || b >= n) return; int l = min(p[a].y, p[b].y); int r = max(p[a].y, p[b].y); if(l + 1 < r) { add(l + 1, k); add(r, -k); } add(l, k); add(l + 1, -k); if(l < r) { add(r, k); add(r + 1, -k); } } int main() { scanf("%d%d", &n, &m); for(int i = 0; i < n; ++i) { scanf("%d", &p[i].y); } for(int i = 0; i < n - 1; ++i) { update(i, i + 1, 1); add(p[i].y, -1); add(p[i].y + 1, 1); } // for(int i = 0; i < 10; ++i) { printf("%d\n", sum(i)); } for(; m--; ) { int t; int x, y; scanf("%d", &t); if(t == 1) { scanf("%d%d", &x, &y); x --; update(x - 1, x, -1); update(x, x + 1, -1); add(p[x].y, 1); add(p[x].y + 1, -1); p[x].y = y; update(x - 1, x, 1); update(x, x + 1, 1); add(p[x].y, -1); add(p[x].y + 1, 1); // printf("\n"); // for(int i = 1; i < 6; ++i) { printf("%d\n", sum(i)); } } else { scanf("%d", &x); printf("%d\n", sum(x)); } } return 0; }

Compilation message (stderr)

game.cpp: In function 'int main()':
game.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         scanf("%d%d", &n, &m);
      |         ~~~~~^~~~~~~~~~~~~~~~
game.cpp:50:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |                 scanf("%d", &p[i].y);
      |                 ~~~~~^~~~~~~~~~~~~~~
game.cpp:64:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |                 scanf("%d", &t);
      |                 ~~~~~^~~~~~~~~~
game.cpp:66:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |                         scanf("%d%d", &x, &y);
      |                         ~~~~~^~~~~~~~~~~~~~~~
game.cpp:84:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |                         scanf("%d", &x);
      |                         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...