답안 #1097856

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097856 2024-10-08T11:53:40 Z michified Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
3724 ms 144196 KB
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define lid id * 2 + 1
#define rid id * 2 + 2
#define lmn LLONG_MIN
#define lmx LLONG_MAX
#define imn INT_MIN
#define imx INT_MAX
using namespace std;
const ll mod = 1e9 + 7;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag, tree_order_statistics_node_update> 

int n, m;

// segtree implementation begins here

vector<int> st, lazy;

void pd(int id, int l, int mid, int r) {
    st[lid] += lazy[id];
    st[rid] += lazy[id];
    lazy[lid] += lazy[id];
    lazy[rid] += lazy[id];
    lazy[id] = 0;
}

void update(int id, int l, int r, int ul, int ur, int val) {
    if (r < ul or l > ur) return;
    if (ul <= l and r <= ur) {
        st[id] += val;
        lazy[id] += val;
        return;
    }
    int mid = (l + r) / 2;
    pd(id, l, mid, r);
    update(lid, l, mid, ul, ur, val);
    update(rid, mid + 1, r, ul, ur, val);
    st[id] = max(st[lid], st[rid]);
}

void setas(int id, int l, int r, int pos, int val) {
    if (l == r) {
        st[id] = val;
        return;
    }
    int mid = (l + r) / 2;
    pd(id, l, mid, r);
    if (pos <= mid) setas(lid, l, mid, pos, val);
    else setas(rid, mid + 1, r, pos, val);
    st[id] = max(st[lid], st[rid]);
}

// segtree implementations ends here

vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
	n = A.size();
    int q = X.size(), i;
    vector<ll> a(n);
    for (i = 0; i < n; i++) a[i] = A[i] * 1000000ll + i;
    unordered_map<ll, int> b2s;
    vector<ll> s2b = a;
    for (i = 0; i < q; i++) s2b.push_back(V[i] * 1000000ll + X[i]);
    sort(s2b.begin(), s2b.end());
    for (i = 0; i < n + q; i++) b2s[s2b[i]] = i;
    m = s2b.size();
    st.resize(m * 4, -1e9);
    lazy.resize(m * 4);
    ordered_set os;
    for (ll elem : a) os.insert(elem);
    for (i = 0; i < n; i++) setas(0, 0, m - 1, b2s[a[i]], i - os.order_of_key(a[i]));
    vector<int> ans(q);
    for (i = 0; i < q; i++) {
        update(0, 0, m - 1, b2s[a[X[i]]] + 1, m - 1, 1);
        os.erase(a[X[i]]);
        setas(0, 0, m - 1, b2s[a[X[i]]], -1e9);
        a[X[i]] = V[i] * 1000000ll + X[i];
        os.insert(a[X[i]]);
        setas(0, 0, m - 1, b2s[a[X[i]]], X[i] - os.order_of_key(a[X[i]]));
        update(0, 0, m - 1, b2s[a[X[i]]] + 1, m - 1, -1);
        ans[i] = st[0];
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 4 ms 860 KB Output is correct
4 Correct 4 ms 860 KB Output is correct
5 Correct 4 ms 856 KB Output is correct
6 Correct 4 ms 860 KB Output is correct
7 Correct 4 ms 860 KB Output is correct
8 Correct 5 ms 860 KB Output is correct
9 Correct 4 ms 860 KB Output is correct
10 Correct 4 ms 860 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 4 ms 860 KB Output is correct
13 Correct 4 ms 860 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 4 ms 860 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 4 ms 920 KB Output is correct
18 Correct 4 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 4 ms 860 KB Output is correct
4 Correct 4 ms 860 KB Output is correct
5 Correct 4 ms 856 KB Output is correct
6 Correct 4 ms 860 KB Output is correct
7 Correct 4 ms 860 KB Output is correct
8 Correct 5 ms 860 KB Output is correct
9 Correct 4 ms 860 KB Output is correct
10 Correct 4 ms 860 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 4 ms 860 KB Output is correct
13 Correct 4 ms 860 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 4 ms 860 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 4 ms 920 KB Output is correct
18 Correct 4 ms 860 KB Output is correct
19 Correct 17 ms 2136 KB Output is correct
20 Correct 26 ms 2652 KB Output is correct
21 Correct 26 ms 2652 KB Output is correct
22 Correct 20 ms 2648 KB Output is correct
23 Correct 17 ms 2488 KB Output is correct
24 Correct 23 ms 2628 KB Output is correct
25 Correct 18 ms 2392 KB Output is correct
26 Correct 17 ms 2396 KB Output is correct
27 Correct 16 ms 2552 KB Output is correct
28 Correct 17 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 4992 KB Output is correct
2 Correct 84 ms 9424 KB Output is correct
3 Correct 146 ms 14244 KB Output is correct
4 Correct 154 ms 14076 KB Output is correct
5 Correct 144 ms 14128 KB Output is correct
6 Correct 143 ms 14128 KB Output is correct
7 Correct 141 ms 14128 KB Output is correct
8 Correct 146 ms 14076 KB Output is correct
9 Correct 168 ms 14024 KB Output is correct
10 Correct 120 ms 12232 KB Output is correct
11 Correct 124 ms 12152 KB Output is correct
12 Correct 129 ms 12040 KB Output is correct
13 Correct 115 ms 12232 KB Output is correct
14 Correct 132 ms 12232 KB Output is correct
15 Correct 123 ms 12116 KB Output is correct
16 Correct 116 ms 12488 KB Output is correct
17 Correct 115 ms 12228 KB Output is correct
18 Correct 120 ms 12232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 4 ms 860 KB Output is correct
4 Correct 4 ms 860 KB Output is correct
5 Correct 4 ms 856 KB Output is correct
6 Correct 4 ms 860 KB Output is correct
7 Correct 4 ms 860 KB Output is correct
8 Correct 5 ms 860 KB Output is correct
9 Correct 4 ms 860 KB Output is correct
10 Correct 4 ms 860 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 4 ms 860 KB Output is correct
13 Correct 4 ms 860 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 4 ms 860 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 4 ms 920 KB Output is correct
18 Correct 4 ms 860 KB Output is correct
19 Correct 17 ms 2136 KB Output is correct
20 Correct 26 ms 2652 KB Output is correct
21 Correct 26 ms 2652 KB Output is correct
22 Correct 20 ms 2648 KB Output is correct
23 Correct 17 ms 2488 KB Output is correct
24 Correct 23 ms 2628 KB Output is correct
25 Correct 18 ms 2392 KB Output is correct
26 Correct 17 ms 2396 KB Output is correct
27 Correct 16 ms 2552 KB Output is correct
28 Correct 17 ms 2392 KB Output is correct
29 Correct 25 ms 4992 KB Output is correct
30 Correct 84 ms 9424 KB Output is correct
31 Correct 146 ms 14244 KB Output is correct
32 Correct 154 ms 14076 KB Output is correct
33 Correct 144 ms 14128 KB Output is correct
34 Correct 143 ms 14128 KB Output is correct
35 Correct 141 ms 14128 KB Output is correct
36 Correct 146 ms 14076 KB Output is correct
37 Correct 168 ms 14024 KB Output is correct
38 Correct 120 ms 12232 KB Output is correct
39 Correct 124 ms 12152 KB Output is correct
40 Correct 129 ms 12040 KB Output is correct
41 Correct 115 ms 12232 KB Output is correct
42 Correct 132 ms 12232 KB Output is correct
43 Correct 123 ms 12116 KB Output is correct
44 Correct 116 ms 12488 KB Output is correct
45 Correct 115 ms 12228 KB Output is correct
46 Correct 120 ms 12232 KB Output is correct
47 Correct 685 ms 42800 KB Output is correct
48 Correct 3332 ms 130976 KB Output is correct
49 Correct 3724 ms 143852 KB Output is correct
50 Correct 3662 ms 143860 KB Output is correct
51 Correct 3689 ms 143944 KB Output is correct
52 Correct 3699 ms 143852 KB Output is correct
53 Correct 3514 ms 143944 KB Output is correct
54 Correct 3325 ms 144196 KB Output is correct
55 Correct 3623 ms 144192 KB Output is correct
56 Correct 3403 ms 144044 KB Output is correct
57 Correct 3559 ms 143940 KB Output is correct
58 Correct 3344 ms 143940 KB Output is correct
59 Correct 2727 ms 138820 KB Output is correct
60 Correct 2721 ms 138816 KB Output is correct
61 Correct 2857 ms 138704 KB Output is correct
62 Correct 2621 ms 136904 KB Output is correct
63 Correct 2719 ms 136668 KB Output is correct
64 Correct 2740 ms 136772 KB Output is correct
65 Correct 2553 ms 134728 KB Output is correct
66 Correct 2485 ms 134516 KB Output is correct
67 Correct 2447 ms 134724 KB Output is correct