Submission #85937

#TimeUsernameProblemLanguageResultExecution timeMemory
85937inomSimple game (IZhO17_game)C++14
100 / 100
242 ms15532 KiB
#include<bits/stdc++.h> #define fi first #define se second #define sc scanf #define pr printf #define pb push_back #define sz(c) (int)(c).size() #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() #define in freopen("game.in", "r", stdin); #define out freopen("game.out", "w", stdout); using namespace std; const int N = 100100; const int INF = 1000001; int TN = 1; int n, m; int a[N], t[8 * INF]; void update(int v, int tl, int tr, int l, int r, int add) { if (l > r) { return; } if (tl == l && tr == r) { t[v] += add; return; } int tm = (tl + tr) >> 1; update(v << 1, tl, tm, l, min(r, tm), add); update(v << 1 | 1, tm + 1, tr, max(tm + 1, l), r, add); } int get(int v, int tl, int tr, int pos) { if (tl == tr) { return t[v]; } int tm = (tl + tr) >> 1; if (pos <= tm) { return t[v] + get(v << 1, tl, tm, pos); } else { return t[v] + get(v << 1 | 1, tm + 1, tr, pos); } } void solve() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for (int i = 2; i <= n; i++) { update(1, 1, INF, min(a[i - 1], a[i]), max(a[i - 1], a[i]), 1); } while (m--) { int type; scanf("%d", &type); if (type == 1) { int pos, val; scanf("%d %d", &pos, &val); if (pos > 1) { update(1, 1, INF, min(a[pos - 1], a[pos]), max(a[pos - 1], a[pos]), -1); update(1, 1, INF, min(a[pos - 1], val), max(a[pos- 1], val), 1); } if (pos < n) { update(1, 1, INF, min(a[pos], a[pos + 1]), max(a[pos], a[pos + 1]), -1); update(1, 1, INF, min(a[pos + 1], val), max(a[pos + 1], val), 1); } a[pos] = val; } else { int H; scanf("%d", &H); printf("%d\n", get(1, 1, INF, H)); } } return; } signed main() { // ios_base::sync_with_stdio(0); // in; out; // cin >> TN; while (TN--) solve(); return 0; }

Compilation message (stderr)

game.cpp: In function 'void solve()':
game.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
game.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
game.cpp:57:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int type; scanf("%d", &type);
                   ~~~~~^~~~~~~~~~~~~
game.cpp:59:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             int pos, val; scanf("%d %d", &pos, &val);
                           ~~~~~^~~~~~~~~~~~~~~~~~~~~
game.cpp:71:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             int H; scanf("%d", &H);
                    ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...