Submission #503128

# Submission time Handle Problem Language Result Execution time Memory
503128 2022-01-07T10:22:27 Z KiriLL1ca Simple game (IZhO17_game) C++17
100 / 100
60 ms 6824 KB
#include <bits/stdc++.h>
#define fr first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define endl '\n'
#define pw(x) (1ll << x)
#define sz(x) (int)((x).size())
#define sqr(x) ((ll)x)*((ll)x)
#define bcnt(X) __builtin_popcountll(X)

#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e6 + 10;

int fnw[N];

inline void upd (int pos, int x) { pos += 5;
    for (; pos < N; pos += (pos & (-pos))) fnw[pos] += x;
}

inline void upd (int l, int r, int x) {
    if (l > r) swap(l, r);
    upd(l, x);
    upd(r + 1, -x);
}

inline int get (int x) { x += 5;
    int ret = 0;
    for (; x; x -= (x & (-x))) ret += fnw[x];
    return ret;
}

signed main ()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, q; cin >> n >> q;
    vector <int> h (n);
    for (auto &i : h) cin >> i;
    for (int i = 1; i < n; i++) {
        upd(h[i - 1], h[i], 1);
    }
    if (n == 1) {
        while (q--) {
            int tp; cin >> tp;
            if (tp == 1) {
                int i, x; cin >> i >> x;
                h[0] = x;
            }
            else {
                int y; cin >> y;
                cout << (y == h[0]) << endl;
            }
        }
        return 0;
    }
    while (q--) {
        int tp; cin >> tp;
        if (tp == 1) {
            int i, x; cin >> i >> x;
            i--;
            if (i == 0) {
                upd(h[0], h[1], -1);
                h[0] = x;
                upd(h[0], h[1], 1);
            }
            else if (i == n - 1) {
                upd(h[n - 2], h[n - 1], -1);
                h[n - 1] = x;
                upd(h[n - 2], h[n - 1], 1);
            }
            else {
                upd(h[i], h[i + 1], -1);
                upd(h[i - 1], h[i], -1);
                h[i] = x;
                upd(h[i], h[i + 1], 1);
                upd(h[i - 1], h[i], 1);
            }
        }
        else {
            int y; cin >> y;
            cout << get(y) << endl;
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 3 ms 4044 KB Output is correct
3 Correct 2 ms 4056 KB Output is correct
4 Correct 3 ms 4044 KB Output is correct
5 Correct 3 ms 4036 KB Output is correct
6 Correct 3 ms 4044 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 3 ms 4044 KB Output is correct
3 Correct 2 ms 4056 KB Output is correct
4 Correct 3 ms 4044 KB Output is correct
5 Correct 3 ms 4036 KB Output is correct
6 Correct 3 ms 4044 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 31 ms 1704 KB Output is correct
9 Correct 41 ms 6716 KB Output is correct
10 Correct 46 ms 6776 KB Output is correct
11 Correct 32 ms 1604 KB Output is correct
12 Correct 35 ms 2744 KB Output is correct
13 Correct 37 ms 2740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 3 ms 4044 KB Output is correct
3 Correct 2 ms 4056 KB Output is correct
4 Correct 3 ms 4044 KB Output is correct
5 Correct 3 ms 4036 KB Output is correct
6 Correct 3 ms 4044 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 31 ms 1704 KB Output is correct
9 Correct 41 ms 6716 KB Output is correct
10 Correct 46 ms 6776 KB Output is correct
11 Correct 32 ms 1604 KB Output is correct
12 Correct 35 ms 2744 KB Output is correct
13 Correct 37 ms 2740 KB Output is correct
14 Correct 56 ms 6820 KB Output is correct
15 Correct 49 ms 6756 KB Output is correct
16 Correct 50 ms 6708 KB Output is correct
17 Correct 60 ms 6824 KB Output is correct
18 Correct 52 ms 6724 KB Output is correct