Submission #594853

# Submission time Handle Problem Language Result Execution time Memory
594853 2022-07-13T04:46:26 Z zeroesandones Simple game (IZhO17_game) C++17
100 / 100
71 ms 6812 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;

#define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i)
#define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i)
#define nl "\n"
#define all(x) (x).begin(), (x).end()

#define sc second
#define fr first
#define pb push_back

const int mxN = (1e6 + 1);
int tree[(int) 1e6 + 1] = {};
int n;

int sum(int k) {
    int s = 0;
    while(k >= 1) {
        s += tree[k];
        k -= k&-k;
    }
    return s;
}

void add(int k, int x) {
    while(k <= mxN) {
        tree[k] += x;
        k += k&-k;
    }
}

void newL(int a, int b) {
    if(a > b)
        swap(a, b);
    add(a + 1, 1);
    add(b, -1);
}

void removeL(int a, int b) {
    if(a > b)
        swap(a, b);
    add(a + 1, -1);
    add(b, 1);
}

void solve()
{
    int m;
    cin >> n >> m;

    int a[n + 1];
    FOR(i, 1, n + 1)
        cin >> a[i];

    FOR(i, 2, n + 1) {
        newL(a[i], a[i - 1]);
    }

    FOR(i, 0, m) {
        int x;
        cin >> x;
        if(x == 1) {
            int p, h;
            cin >> p >> h;
            if(p != 1) {
                removeL(a[p], a[p - 1]);
                newL(a[p - 1], h);
            }
            if(p != n) {
                removeL(a[p], a[p + 1]);
                newL(a[p + 1], h);
            }
            a[p] = h;
        } else {
            int p;
            cin >> p;
            cout << sum(p) << nl;
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 4052 KB Output is correct
3 Correct 4 ms 4052 KB Output is correct
4 Correct 3 ms 4052 KB Output is correct
5 Correct 4 ms 4052 KB Output is correct
6 Correct 3 ms 4052 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 4052 KB Output is correct
3 Correct 4 ms 4052 KB Output is correct
4 Correct 3 ms 4052 KB Output is correct
5 Correct 4 ms 4052 KB Output is correct
6 Correct 3 ms 4052 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 39 ms 1636 KB Output is correct
9 Correct 37 ms 6748 KB Output is correct
10 Correct 40 ms 6780 KB Output is correct
11 Correct 30 ms 1528 KB Output is correct
12 Correct 33 ms 2784 KB Output is correct
13 Correct 41 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 4052 KB Output is correct
3 Correct 4 ms 4052 KB Output is correct
4 Correct 3 ms 4052 KB Output is correct
5 Correct 4 ms 4052 KB Output is correct
6 Correct 3 ms 4052 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 39 ms 1636 KB Output is correct
9 Correct 37 ms 6748 KB Output is correct
10 Correct 40 ms 6780 KB Output is correct
11 Correct 30 ms 1528 KB Output is correct
12 Correct 33 ms 2784 KB Output is correct
13 Correct 41 ms 2764 KB Output is correct
14 Correct 49 ms 6716 KB Output is correct
15 Correct 47 ms 6808 KB Output is correct
16 Correct 56 ms 6812 KB Output is correct
17 Correct 53 ms 6784 KB Output is correct
18 Correct 71 ms 6780 KB Output is correct