답안 #996053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
996053 2024-06-10T07:37:21 Z gmroh06 Employment (JOI16_employment) C++14
100 / 100
241 ms 29060 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

inline void fastio() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
}

class Fenwick {
private:
    vector<ll> tree;
    ll n;

public:
    Fenwick(ll x) {
        n = x;
        tree.resize(x + 1);
    }

    void add(ll idx, ll val) {
        for (ll x = idx + 1; x <= n; x += x & -x) {
            tree[x] += val;
        }
    }

    ll sum(ll idx) {
        ll ret = 0;

        for (ll x = idx; x > 0; x &= x - 1) {
            ret += tree[x];
        }

        return ret;
    }
};

int main() {
    fastio();

    ll n, m;

    cin >> n >> m;

    vector<ll> arr(n + 1);

    for (ll i = 1; i <= n; i++) {
        cin >> arr[i];
    }

    vector<tuple<ll, ll, ll>> query(m);
    vector<ll> val = arr;

    for (auto& [t, a, b] : query) {
        cin >> t;

        if (t == 1) {
            cin >> a;
            val.emplace_back(a);
        } else {
            cin >> a >> b;
            val.emplace_back(b);
        }
    }

    sort(val.begin(), val.end());
    val.erase(unique(val.begin(), val.end()), val.end());

    for (auto& x : arr) {
        x = lower_bound(val.begin(), val.end(), x) - val.begin();
    }

    for (auto& [t, a, b] : query) {
        if (t == 1) {
            a = lower_bound(val.begin(), val.end(), a) - val.begin();
        } else {
            b = lower_bound(val.begin(), val.end(), b) - val.begin();
        }
    }

    const ll MAX = n + m << 1;

    Fenwick tree(MAX | 1), min_tree(MAX | 1);

    auto add = [&](ll idx, ll val) {
        tree.add(arr[idx], val);
        min_tree.add(min(arr[idx - 1], arr[idx]), val);
    };

    for (ll i = 1; i <= n; i++) {
        add(i, 1);
    }

    for (auto& [t, a, b] : query) {
        if (t == 1) {
            cout << (tree.sum(MAX) - tree.sum(a)) - (min_tree.sum(MAX) - min_tree.sum(a)) << '\n';
        } else {
            add(a, -1);
            if (a != n) add(a + 1, -1);

            arr[a] = b;

            add(a, 1);
            if (a != n) add(a + 1, 1);
        }
    }

    return 0;
}

Compilation message

employment.cpp: In function 'int main()':
employment.cpp:56:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   56 |     for (auto& [t, a, b] : query) {
      |                ^
employment.cpp:75:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   75 |     for (auto& [t, a, b] : query) {
      |                ^
employment.cpp:83:22: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   83 |     const ll MAX = n + m << 1;
      |                    ~~^~~
employment.cpp:96:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   96 |     for (auto& [t, a, b] : query) {
      |                ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 1 ms 548 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 524 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 740 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 784 KB Output is correct
4 Correct 11 ms 2724 KB Output is correct
5 Correct 22 ms 4664 KB Output is correct
6 Correct 38 ms 7076 KB Output is correct
7 Correct 55 ms 10484 KB Output is correct
8 Correct 74 ms 13048 KB Output is correct
9 Correct 125 ms 21944 KB Output is correct
10 Correct 114 ms 19340 KB Output is correct
11 Correct 144 ms 25012 KB Output is correct
12 Correct 174 ms 27804 KB Output is correct
13 Correct 159 ms 27200 KB Output is correct
14 Correct 163 ms 27096 KB Output is correct
15 Correct 166 ms 26976 KB Output is correct
16 Correct 167 ms 27708 KB Output is correct
17 Correct 167 ms 27708 KB Output is correct
18 Correct 164 ms 27680 KB Output is correct
19 Correct 184 ms 27700 KB Output is correct
20 Correct 167 ms 27716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 1 ms 548 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 524 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 740 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 524 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 2 ms 784 KB Output is correct
19 Correct 11 ms 2724 KB Output is correct
20 Correct 22 ms 4664 KB Output is correct
21 Correct 38 ms 7076 KB Output is correct
22 Correct 55 ms 10484 KB Output is correct
23 Correct 74 ms 13048 KB Output is correct
24 Correct 125 ms 21944 KB Output is correct
25 Correct 114 ms 19340 KB Output is correct
26 Correct 144 ms 25012 KB Output is correct
27 Correct 174 ms 27804 KB Output is correct
28 Correct 159 ms 27200 KB Output is correct
29 Correct 163 ms 27096 KB Output is correct
30 Correct 166 ms 26976 KB Output is correct
31 Correct 167 ms 27708 KB Output is correct
32 Correct 167 ms 27708 KB Output is correct
33 Correct 164 ms 27680 KB Output is correct
34 Correct 184 ms 27700 KB Output is correct
35 Correct 167 ms 27716 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 2 ms 860 KB Output is correct
39 Correct 13 ms 2624 KB Output is correct
40 Correct 23 ms 4376 KB Output is correct
41 Correct 41 ms 6824 KB Output is correct
42 Correct 62 ms 9768 KB Output is correct
43 Correct 90 ms 13496 KB Output is correct
44 Correct 171 ms 22836 KB Output is correct
45 Correct 139 ms 18708 KB Output is correct
46 Correct 152 ms 20968 KB Output is correct
47 Correct 204 ms 26948 KB Output is correct
48 Correct 201 ms 29060 KB Output is correct
49 Correct 210 ms 27200 KB Output is correct
50 Correct 215 ms 26752 KB Output is correct
51 Correct 205 ms 27700 KB Output is correct
52 Correct 219 ms 27924 KB Output is correct
53 Correct 241 ms 27704 KB Output is correct
54 Correct 215 ms 27716 KB Output is correct
55 Correct 212 ms 27788 KB Output is correct