Submission #92895

# Submission time Handle Problem Language Result Execution time Memory
92895 2019-01-05T13:14:19 Z SamAnd Simple game (IZhO17_game) C++17
100 / 100
258 ms 11280 KB
#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

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 time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 9 ms 6520 KB Output is correct
3 Correct 8 ms 6392 KB Output is correct
4 Correct 9 ms 6392 KB Output is correct
5 Correct 8 ms 6392 KB Output is correct
6 Correct 9 ms 6520 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 9 ms 6520 KB Output is correct
3 Correct 8 ms 6392 KB Output is correct
4 Correct 9 ms 6392 KB Output is correct
5 Correct 8 ms 6392 KB Output is correct
6 Correct 9 ms 6520 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 168 ms 1756 KB Output is correct
9 Correct 240 ms 11256 KB Output is correct
10 Correct 245 ms 11280 KB Output is correct
11 Correct 164 ms 1688 KB Output is correct
12 Correct 200 ms 3064 KB Output is correct
13 Correct 189 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 9 ms 6520 KB Output is correct
3 Correct 8 ms 6392 KB Output is correct
4 Correct 9 ms 6392 KB Output is correct
5 Correct 8 ms 6392 KB Output is correct
6 Correct 9 ms 6520 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 168 ms 1756 KB Output is correct
9 Correct 240 ms 11256 KB Output is correct
10 Correct 245 ms 11280 KB Output is correct
11 Correct 164 ms 1688 KB Output is correct
12 Correct 200 ms 3064 KB Output is correct
13 Correct 189 ms 2908 KB Output is correct
14 Correct 251 ms 11128 KB Output is correct
15 Correct 257 ms 11128 KB Output is correct
16 Correct 258 ms 11128 KB Output is correct
17 Correct 252 ms 11128 KB Output is correct
18 Correct 254 ms 11260 KB Output is correct