Submission #886295

# Submission time Handle Problem Language Result Execution time Memory
886295 2023-12-11T18:50:09 Z boris_mihov Simple game (IZhO17_game) C++17
100 / 100
50 ms 6984 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <bitset>
#include <vector>

typedef long long llong;
const int MAXN = 100000 + 10;
const int MAXT = 1000000 + 10;

int n, q;
struct Fenwick
{
    int tree[MAXT];
    void update(int pos, int val)
    {
        for (int idx = pos ; idx < MAXT ; idx += idx & (-idx))
        {
            tree[idx] += val;
        }
    }

    int query(int t)
    {
        int res = 0;
        for (int idx = t ; idx > 0 ; idx -= idx & (-idx))
        {
            res += tree[idx];
        }

        return res;
    }
};

int a[MAXN];
Fenwick tree;

void add(int idx)
{
    int min = std::min(a[idx], a[idx + 1]);
    int max = std::max(a[idx], a[idx + 1]);
    tree.update(min + 1, 1);
    tree.update(max + 1, -1);
}

void remove(int idx)
{
    int min = std::min(a[idx], a[idx + 1]);
    int max = std::max(a[idx], a[idx + 1]);
    tree.update(min + 1, -1);
    tree.update(max + 1, 1);
}

void solve()
{
    for (int i = 1 ; i < n ; ++i)
    {
        add(i);
    }

    for (int i = 1 ; i <= n ; ++i)
    {
        int qType, pos, val;
        std::cin >> qType;

        if (qType == 1)
        {
            std::cin >> pos >> val;
            
            if (pos < n) remove(pos);
            if (pos > 1) remove(pos - 1);
            
            a[pos] = val;

            if (pos < n) add(pos);
            if (pos > 1) add(pos - 1);
        } else
        {
            std::cin >> val;
            std::cout << tree.query(val) << '\n';
        }
    }
}

void input()
{
    std::cin >> n >> q;
    for (int i = 1 ; i <= n ; ++i)
    {
        std::cin >> a[i];
    }
}

void fastIOI()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIOI();
    input();
    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 4856 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 4856 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 30 ms 5040 KB Output is correct
9 Correct 30 ms 6736 KB Output is correct
10 Correct 30 ms 6736 KB Output is correct
11 Correct 28 ms 5460 KB Output is correct
12 Correct 28 ms 6464 KB Output is correct
13 Correct 29 ms 6452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 4856 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 30 ms 5040 KB Output is correct
9 Correct 30 ms 6736 KB Output is correct
10 Correct 30 ms 6736 KB Output is correct
11 Correct 28 ms 5460 KB Output is correct
12 Correct 28 ms 6464 KB Output is correct
13 Correct 29 ms 6452 KB Output is correct
14 Correct 50 ms 6744 KB Output is correct
15 Correct 41 ms 6900 KB Output is correct
16 Correct 42 ms 6884 KB Output is correct
17 Correct 42 ms 6896 KB Output is correct
18 Correct 46 ms 6984 KB Output is correct