답안 #900317

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
900317 2024-01-08T06:28:33 Z Perl32 Simple game (IZhO17_game) C++14
100 / 100
44 ms 5460 KB
//I wrote this code 4 u <3
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

const int maxN = (int) 1e6 + 1e3;

template<typename T>
struct Bit { // [l, r)
    vector<T> t;
    int sz;

    Bit(int n) : t(n + 1), sz(n) {}

    void upd(int i, int val) {
        for (++i; i <= sz; i += i & -i) {
            t[i] += val;
        }
    }

    T get(int x) {
        ll ret = 0;
        for (; x; x -= x & -x) {
            ret += t[x];
        }
        return ret;
    }

    T get(int l, int r) {
        return get(r) - get(l);
    }
};

signed main(int32_t argc, char *argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    Bit<int> bit(maxN);
    auto add = [&](int l, int r, int v) {
        if (l > r) {
            swap(l, r);
        }
        bit.upd(l, v);
        bit.upd(r + 1, -v);
    };
    for (int i = 0; i < n - 1; ++i) {
        add(a[i], a[i + 1], 1);
    }
    while (m--) {
        int t;
        cin >> t;
        if (t == 1) {
            int i, v;
            cin >> i >> v;
            --i;
            if (i > 0) {
                add(a[i], a[i - 1], -1);
                add(v, a[i - 1], 1);
            }
            if (i < n - 1) {
                add(a[i], a[i + 1], -1);
                add(v, a[i + 1], 1);
            }
            a[i] = v;
        } else {
            int h;
            cin >> h;
            cout << bit.get(h + 1) << '\n';
        }
    }
}

/*

 */
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 1 ms 4188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 1 ms 4188 KB Output is correct
8 Correct 27 ms 4948 KB Output is correct
9 Correct 30 ms 5200 KB Output is correct
10 Correct 37 ms 5460 KB Output is correct
11 Correct 28 ms 4944 KB Output is correct
12 Correct 28 ms 5212 KB Output is correct
13 Correct 31 ms 5436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 1 ms 4188 KB Output is correct
8 Correct 27 ms 4948 KB Output is correct
9 Correct 30 ms 5200 KB Output is correct
10 Correct 37 ms 5460 KB Output is correct
11 Correct 28 ms 4944 KB Output is correct
12 Correct 28 ms 5212 KB Output is correct
13 Correct 31 ms 5436 KB Output is correct
14 Correct 41 ms 4892 KB Output is correct
15 Correct 44 ms 5156 KB Output is correct
16 Correct 39 ms 4944 KB Output is correct
17 Correct 39 ms 4956 KB Output is correct
18 Correct 39 ms 4828 KB Output is correct