Submission #92895

#TimeUsernameProblemLanguageResultExecution timeMemory
92895SamAndSimple game (IZhO17_game)C++17
100 / 100
258 ms11280 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1000006; int n, q; int a[N]; int t[N * 4]; void ubd(int tl, int tr, int l, int r, int y, int pos) { if (tl == l && tr == r) { t[pos] += y; return; } int m = (tl + tr) / 2; if (r <= m) ubd(tl, m, l, r, y, pos * 2); else if (l > m) ubd(m + 1, tr, l, r, y, pos * 2 + 1); else { ubd(tl, m, l, m, y, pos * 2); ubd(m + 1, tr, m + 1, r, y, pos * 2 + 1); } } int qry(int tl, int tr, int x, int pos) { if (tl == tr) return t[pos]; int m = (tl + tr) / 2; if (x <= m) return t[pos] + qry(tl, m, x, pos * 2); else return t[pos] + qry(m + 1, tr, x, pos * 2 + 1); } int main() { //freopen("input2.txt", "r", stdin); scanf("%d%d", &n, &q); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i < n; ++i) { ubd(1, N - 1, min(a[i], a[i + 1]), max(a[i], a[i + 1]), 1, 1); } while (q--) { int ty; scanf("%d", &ty); if (ty == 1) { int i, x; scanf("%d%d", &i, &x); if (i == 1) ubd(1, N - 1, min(a[i], a[i + 1]), max(a[i], a[i + 1]), -1, 1); else if (i == n) ubd(1, N - 1, min(a[i], a[i - 1]), max(a[i], a[i - 1]), -1, 1); else { ubd(1, N - 1, min(a[i], a[i + 1]), max(a[i], a[i + 1]), -1, 1); ubd(1, N - 1, min(a[i], a[i - 1]), max(a[i], a[i - 1]), -1, 1); } a[i] = x; if (i == 1) ubd(1, N - 1, min(a[i], a[i + 1]), max(a[i], a[i + 1]), 1, 1); else if (i == n) ubd(1, N - 1, min(a[i], a[i - 1]), max(a[i], a[i - 1]), 1, 1); else { ubd(1, N - 1, min(a[i], a[i + 1]), max(a[i], a[i + 1]), 1, 1); ubd(1, N - 1, min(a[i], a[i - 1]), max(a[i], a[i - 1]), 1, 1); } } else { int x; scanf("%d", &x); cout << qry(1, N - 1, x, 1) << endl; } } return 0; }

Compilation message (stderr)

game.cpp: In function 'int main()':
game.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~
game.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
game.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &ty);
         ~~~~~^~~~~~~~~~~
game.cpp:56:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d", &i, &x);
             ~~~~~^~~~~~~~~~~~~~~~
game.cpp:80:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...