답안 #900315

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
900315 2024-01-08T06:24:31 Z Perl32 Simple game (IZhO17_game) C++14
0 / 100
2 ms 8308 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<ll> bit(maxN);
    auto add = [&](int l, int r, int v) {
        bit.upd(l, v);
        bit.upd(r + 1, -v);
    };
    for (int i = 0; i < n - 1; ++i) {
        int l = min(a[i], a[i + 1]), r = max(a[i], a[i + 1]);
        add(l, r, 1);
    }
    while (m--) {
        int t;
        cin >> t;
        if (t == 1) {
            int i, v;
            cin >> i >> v;
            --i;
            if (i > 0) {
                add(min(a[i], a[i - 1]), max(a[i], a[i - 1]), -1);
                add(min(v, a[i - 1]), max(v, a[i - 1]), 1);
            }
            if (i < n - 1) {
                add(min(a[i], a[i + 1]), max(a[i], a[i + 1]), -1);
                add(min(v, a[i + 1]), max(v, a[i + 1]), 1);
            }
            a[i] = v;
        } else {
            int h;
            cin >> h;
            cout << bit.get(h) << '\n';
        }
    }
}

/*

 */
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8284 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Incorrect 2 ms 8308 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8284 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Incorrect 2 ms 8308 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8284 KB Output is correct
2 Correct 2 ms 8284 KB Output is correct
3 Incorrect 2 ms 8308 KB Output isn't correct
4 Halted 0 ms 0 KB -