답안 #678419

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
678419 2023-01-05T21:34:14 Z sysia Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
2651 ms 53496 KB
//Sylwia Sapkowska
#include <bits/stdc++.h>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef DEBUG
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const int oo = 1e9+7;
typedef pair<int, int> T;

struct TreeSum{
    vector<int>tab, lazy;
    int size = 1;

    TreeSum(int n){
        while (size < n) size*=2;
        tab.assign(2*size, 0);
        lazy.assign(2*size, 0); 
    }

    void update(int x, int lx, int rx, int l, int r, int v){
        push(x, lx, rx);
        if (lx > r || rx < l) return;
        if (lx >= l && rx <= r){
            tab[x] += v;
            lazy[x] += v;
            return;
        }
        int m = (lx+rx)/2;
        update(2*x, lx, m, l, r, v);
        update(2*x+1, m+1, rx, l, r, v);
        tab[x] = max(tab[2*x], tab[2*x+1]);
    }

    void pushall(int x, int lx, int rx){
        if (lx == rx) return;
        push(x, lx, rx);
        int m = (lx+rx)/2;
        pushall(2*x, lx, m);
        pushall(2*x+1, m+1, rx);
    }

    void d(){
        pushall(1, 0, size-1);
        for (int i = 1; i<(int)tab.size(); i++) cerr << tab[i] << " ";
        cerr << "\n";
    }

    void push(int x, int lx, int rx){
        if (lazy[x] == 0 || lx == rx) return;
        tab[2*x] += lazy[x];
        tab[2*x+1] += lazy[x];
        lazy[2*x] += lazy[x];
        lazy[2*x+1] += lazy[x];
        lazy[x] = 0;
    }

    int query(int x, int lx, int rx, int l, int r){
        push(x, lx, rx);
        if (lx > r || rx < l) return -oo;
        if (lx >= l && rx <= r) return tab[x];
        int m = (lx+rx)/2;
        return max(query(2*x, lx, m, l, r), query(2*x+1, m+1, rx, l, r));
    }
};

vector<int> countScans(vector<int>a, vector<int>x, vector<int>v){
    int n = (int)a.size();
    int q = (int)x.size();
    vector<pair<int, int>>s;
    s.emplace_back(-oo, -oo);
    for (int i = 0; i<n; i++) s.emplace_back(a[i], i);
    for (int i = 0; i<q; i++) s.emplace_back(v[i], x[i]);
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    // debug(s);
    int mx = (int)s.size()-1;
    TreeSum t(mx+3);
    auto get = [&](pair<int, int>now) -> int {
        return lower_bound(s.begin(), s.end(), now) - s.begin();
    };
    for (int i = 0; i < n; i++){
        auto curr = get(T{a[i], i});
        t.update(1, 0, t.size-1, curr, mx, -1);
        t.update(1, 0, t.size-1, curr, curr, i+1);
    }
    //ans = max(i-(less or equal to ai))
    // t.d();
    vector<int>ans;
    for (int i = 0; i<q; i++){
        auto nxt = get(T{v[i], x[i]});
        auto curr = get(T{a[x[i]], x[i]});
        // debug(curr, nxt);
        a[x[i]] = v[i];
        t.update(1, 0, t.size-1, curr, curr, -(x[i]+1));
        t.update(1, 0, t.size-1, curr, mx, 1);
        t.update(1, 0, t.size-1, nxt, nxt, x[i]+1);
        t.update(1, 0, t.size-1, nxt, mx, -1);
        // t.d();
        ans.emplace_back(t.query(1, 0, t.size-1, 1, mx));
    }
    return ans;
}

/*
void solve(){
    int n, q; cin >> n >> q;
    vector<int>a(n);
    for (int i = 0; i<n; i++) cin >> a[i];
    vector<int>x(q), v(q);
    for (int i = 0; i < q; i++) cin >> x[i] >> v[i];
    countScans(a, x, v);
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 6 ms 468 KB Output is correct
4 Correct 6 ms 468 KB Output is correct
5 Correct 6 ms 468 KB Output is correct
6 Correct 5 ms 468 KB Output is correct
7 Correct 6 ms 468 KB Output is correct
8 Correct 6 ms 468 KB Output is correct
9 Correct 7 ms 468 KB Output is correct
10 Correct 6 ms 468 KB Output is correct
11 Correct 6 ms 440 KB Output is correct
12 Correct 7 ms 468 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 6 ms 468 KB Output is correct
15 Correct 7 ms 476 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 6 ms 468 KB Output is correct
18 Correct 5 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 6 ms 468 KB Output is correct
4 Correct 6 ms 468 KB Output is correct
5 Correct 6 ms 468 KB Output is correct
6 Correct 5 ms 468 KB Output is correct
7 Correct 6 ms 468 KB Output is correct
8 Correct 6 ms 468 KB Output is correct
9 Correct 7 ms 468 KB Output is correct
10 Correct 6 ms 468 KB Output is correct
11 Correct 6 ms 440 KB Output is correct
12 Correct 7 ms 468 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 6 ms 468 KB Output is correct
15 Correct 7 ms 476 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 6 ms 468 KB Output is correct
18 Correct 5 ms 468 KB Output is correct
19 Correct 20 ms 980 KB Output is correct
20 Correct 25 ms 1120 KB Output is correct
21 Correct 24 ms 1104 KB Output is correct
22 Correct 24 ms 1100 KB Output is correct
23 Correct 30 ms 1040 KB Output is correct
24 Correct 25 ms 1076 KB Output is correct
25 Correct 24 ms 1052 KB Output is correct
26 Correct 23 ms 1056 KB Output is correct
27 Correct 22 ms 1072 KB Output is correct
28 Correct 23 ms 1048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1360 KB Output is correct
2 Correct 104 ms 2980 KB Output is correct
3 Correct 183 ms 5276 KB Output is correct
4 Correct 175 ms 5272 KB Output is correct
5 Correct 180 ms 5272 KB Output is correct
6 Correct 184 ms 5352 KB Output is correct
7 Correct 184 ms 5384 KB Output is correct
8 Correct 189 ms 5340 KB Output is correct
9 Correct 172 ms 5316 KB Output is correct
10 Correct 166 ms 4352 KB Output is correct
11 Correct 147 ms 4280 KB Output is correct
12 Correct 160 ms 4288 KB Output is correct
13 Correct 149 ms 4288 KB Output is correct
14 Correct 140 ms 4312 KB Output is correct
15 Correct 145 ms 4308 KB Output is correct
16 Correct 139 ms 4300 KB Output is correct
17 Correct 150 ms 4316 KB Output is correct
18 Correct 136 ms 4372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 6 ms 468 KB Output is correct
4 Correct 6 ms 468 KB Output is correct
5 Correct 6 ms 468 KB Output is correct
6 Correct 5 ms 468 KB Output is correct
7 Correct 6 ms 468 KB Output is correct
8 Correct 6 ms 468 KB Output is correct
9 Correct 7 ms 468 KB Output is correct
10 Correct 6 ms 468 KB Output is correct
11 Correct 6 ms 440 KB Output is correct
12 Correct 7 ms 468 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 6 ms 468 KB Output is correct
15 Correct 7 ms 476 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 6 ms 468 KB Output is correct
18 Correct 5 ms 468 KB Output is correct
19 Correct 20 ms 980 KB Output is correct
20 Correct 25 ms 1120 KB Output is correct
21 Correct 24 ms 1104 KB Output is correct
22 Correct 24 ms 1100 KB Output is correct
23 Correct 30 ms 1040 KB Output is correct
24 Correct 25 ms 1076 KB Output is correct
25 Correct 24 ms 1052 KB Output is correct
26 Correct 23 ms 1056 KB Output is correct
27 Correct 22 ms 1072 KB Output is correct
28 Correct 23 ms 1048 KB Output is correct
29 Correct 32 ms 1360 KB Output is correct
30 Correct 104 ms 2980 KB Output is correct
31 Correct 183 ms 5276 KB Output is correct
32 Correct 175 ms 5272 KB Output is correct
33 Correct 180 ms 5272 KB Output is correct
34 Correct 184 ms 5352 KB Output is correct
35 Correct 184 ms 5384 KB Output is correct
36 Correct 189 ms 5340 KB Output is correct
37 Correct 172 ms 5316 KB Output is correct
38 Correct 166 ms 4352 KB Output is correct
39 Correct 147 ms 4280 KB Output is correct
40 Correct 160 ms 4288 KB Output is correct
41 Correct 149 ms 4288 KB Output is correct
42 Correct 140 ms 4312 KB Output is correct
43 Correct 145 ms 4308 KB Output is correct
44 Correct 139 ms 4300 KB Output is correct
45 Correct 150 ms 4316 KB Output is correct
46 Correct 136 ms 4372 KB Output is correct
47 Correct 636 ms 19656 KB Output is correct
48 Correct 2454 ms 50580 KB Output is correct
49 Correct 2651 ms 53496 KB Output is correct
50 Correct 2596 ms 53196 KB Output is correct
51 Correct 2579 ms 53172 KB Output is correct
52 Correct 2599 ms 53164 KB Output is correct
53 Correct 2616 ms 53160 KB Output is correct
54 Correct 2370 ms 53408 KB Output is correct
55 Correct 2502 ms 53332 KB Output is correct
56 Correct 2418 ms 53452 KB Output is correct
57 Correct 2482 ms 53372 KB Output is correct
58 Correct 2403 ms 53448 KB Output is correct
59 Correct 2327 ms 52000 KB Output is correct
60 Correct 2119 ms 52044 KB Output is correct
61 Correct 2286 ms 51996 KB Output is correct
62 Correct 2279 ms 51900 KB Output is correct
63 Correct 2318 ms 51792 KB Output is correct
64 Correct 2247 ms 51856 KB Output is correct
65 Correct 2179 ms 51704 KB Output is correct
66 Correct 2180 ms 51768 KB Output is correct
67 Correct 2174 ms 51652 KB Output is correct