Submission #37706

# Submission time Handle Problem Language Result Execution time Memory
37706 2017-12-27T03:47:44 Z adlet Simple game (IZhO17_game) C++14
100 / 100
539 ms 37180 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;
const int INF = 1e9 + 5;

int n, m, pos[N], t[N * 4], z[N * 4];

inline void push(int v, int tl, int tr) {
    if (z[v] != 0) {
        if (tl != tr) {
            t[v * 2] += z[v];
            t[v * 2 + 1] += z[v];
            z[v * 2] += z[v];
            z[v * 2 + 1] += z[v];
        }
        z[v] = 0;
    }
}

inline void upd(int v, int tl, int tr, int l, int r, int x) {
    push(v, tl, tr);
    if (tl > r || tr < l) {
        return;
    }
    if (tl >= l && tr <= r) {
        t[v] += x;
        z[v] += x;
        push(v, tl, tr);
        return;
    }
    push(v, tl, tr);
    int tm = (tl + tr) / 2;
    upd(v * 2, tl, tm, l, r, x);
    upd(v * 2 + 1, tm + 1, tr, l, r, x);
    t[v] = min(t[v * 2], t[v * 2 + 1]);
}

int get(int v, int tl, int tr, int l, int r) {
    push(v, tl, tr);
    if (tl > r || tr < l)
        return INF;
    if (tl >= l && tr <= r)
        return t[v];
    push(v, tl, tr);
    int tm = (tl + tr) / 2;
    return min(get(v * 2, tl, tm, l, r),
               get(v * 2 + 1, tm + 1, tr, l, r));
}

int main() {
//    freopen("game.in", "r", stdin);
//    freopen("game.out", "w", stdout);
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &pos[i]);
        if (i > 1)
            upd(1, 1, N, min(pos[i], pos[i - 1]), max(pos[i], pos[i - 1]), 1);
    }
    for (int i = 1; i <= m; ++i) {
        int type;
        scanf("%d", &type);
        if (type == 1) {
            int j, val;
            scanf("%d%d", &j, &val);
            if (j > 1) {
                upd(1, 1, N, min(pos[j], pos[j - 1]),  max(pos[j], pos[j - 1]), -1);
                upd(1, 1, N, min(pos[j - 1], val), max(pos[j - 1], val), 1);
            }
            if (j < n) {
                upd(1, 1, N, min(pos[j], pos[j + 1]), max(pos[j], pos[j + 1]), -1);
                upd(1, 1, N, min(pos[j + 1], val), max(pos[j + 1], val), 1);
            }
            pos[j] = val;
        } else {
            int h, cnt = 0;
            scanf("%d", &h);
            printf("%d\n", get(1, 1, N, h, h));
        }
    }
}

Compilation message

game.cpp: In function 'int main()':
game.cpp:77:20: warning: unused variable 'cnt' [-Wunused-variable]
             int h, cnt = 0;
                    ^
game.cpp:55:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
                          ^
game.cpp:57:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &pos[i]);
                             ^
game.cpp:63:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &type);
                           ^
game.cpp:66:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d", &j, &val);
                                    ^
game.cpp:78:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &h);
                            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 37180 KB Output is correct
2 Correct 3 ms 37180 KB Output is correct
3 Correct 9 ms 37180 KB Output is correct
4 Correct 9 ms 37180 KB Output is correct
5 Correct 9 ms 37180 KB Output is correct
6 Correct 0 ms 37180 KB Output is correct
7 Correct 6 ms 37180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 37180 KB Output is correct
2 Correct 3 ms 37180 KB Output is correct
3 Correct 9 ms 37180 KB Output is correct
4 Correct 9 ms 37180 KB Output is correct
5 Correct 9 ms 37180 KB Output is correct
6 Correct 0 ms 37180 KB Output is correct
7 Correct 6 ms 37180 KB Output is correct
8 Correct 96 ms 37180 KB Output is correct
9 Correct 239 ms 37180 KB Output is correct
10 Correct 259 ms 37180 KB Output is correct
11 Correct 76 ms 37180 KB Output is correct
12 Correct 146 ms 37180 KB Output is correct
13 Correct 156 ms 37180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 37180 KB Output is correct
2 Correct 3 ms 37180 KB Output is correct
3 Correct 9 ms 37180 KB Output is correct
4 Correct 9 ms 37180 KB Output is correct
5 Correct 9 ms 37180 KB Output is correct
6 Correct 0 ms 37180 KB Output is correct
7 Correct 6 ms 37180 KB Output is correct
8 Correct 96 ms 37180 KB Output is correct
9 Correct 239 ms 37180 KB Output is correct
10 Correct 259 ms 37180 KB Output is correct
11 Correct 76 ms 37180 KB Output is correct
12 Correct 146 ms 37180 KB Output is correct
13 Correct 156 ms 37180 KB Output is correct
14 Correct 459 ms 37180 KB Output is correct
15 Correct 489 ms 37180 KB Output is correct
16 Correct 539 ms 37180 KB Output is correct
17 Correct 509 ms 37180 KB Output is correct
18 Correct 469 ms 37180 KB Output is correct