Submission #1091053

# Submission time Handle Problem Language Result Execution time Memory
1091053 2024-09-19T15:53:45 Z TrinhKhanhDung Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
2395 ms 187536 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)

using namespace std;

template<class T1, class T2>
    bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

template<class T1, class T2>
    bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}

template<class T1, class T2>
    void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}

template<class T1, class T2>
    void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}

template<class T>
    void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}

struct seg{
    vector<int> ma, laz;
    int n;

    seg(int _n = 0){
        n = _n;
        ma.resize(4 * n + 3, 0);
        laz.resize(4 * n + 3, 0);
    }

    void push(int i){
        int t = laz[i];
        laz[i] = 0;
        ma[i * 2] += t;
        ma[i * 2 + 1] += t;
        laz[i * 2] += t;
        laz[i * 2 + 1] += t;
    }

    void upd(int i, int l, int r, int u, int v, int c){
        if(r < u || v < l) return;
        if(u <= l && r <= v){
            ma[i] += c;
            laz[i] += c;
            return;
        }
        push(i);
        int m = (l + r) >> 1;
        upd(i * 2, l, m, u, v, c);
        upd(i * 2 + 1, m + 1, r, u, v, c);
        ma[i] = max(ma[i * 2], ma[i * 2 + 1]);
    }

    void upd(int u, int v, int c){
        upd(1, 0, n - 1, u, v, c);
    }

    int get(){
        return ma[1];
    }
};

const int MAX = 5e5 + 10;

int N, Q;
int a[MAX];
vector<pair<int, int>> queries;
set<int> st[MAX * 2];

std::vector<int> countScans(std::vector<int> A, std::vector<int> X, std::vector<int> V){
    N = sz(A);
    Q = sz(X);
    vector<int> ord;
    for(int i = 1; i <= N; i++){
        a[i] = A[i - 1];
        ord.push_back(a[i]);
    }
    for(int i = 1; i <= Q; i++){
        int p = X[i - 1], x = V[i - 1];
        p++;
        queries.push_back({p, x});
        ord.push_back(x);
    }
    cps(ord);
    for(int i = 1; i <= N; i++){
        a[i] = lower_bound(ALL(ord), a[i]) - ord.begin();
        st[a[i]].insert(i);
    }
    seg it(sz(ord));
    for(int i = 0; i < sz(ord); i++){
        st[i].insert(-INF);
        it.upd(i, i, *st[i].rbegin());
        it.upd(i, sz(ord) - 1, -(sz(st[i]) - 1));
    }
    vector<int> ans;
    for(auto &o: queries){
        o.se = lower_bound(ALL(ord), o.se) - ord.begin();
        int p = o.fi, c = o.se;

        it.upd(a[p], a[p], -*st[a[p]].rbegin());
        st[a[p]].erase(p);
        it.upd(a[p], a[p], *st[a[p]].rbegin());
        it.upd(a[p], sz(ord) - 1, 1);
        a[p] = c;

        it.upd(a[p], a[p], -*st[a[p]].rbegin());
        st[a[p]].insert(p);
        it.upd(a[p], a[p], *st[a[p]].rbegin());
        it.upd(a[p], sz(ord) - 1, -1);
        ans.push_back(it.get());
    }
    return ans;
}

//int main(){
//    ios_base::sync_with_stdio(0); cin.tie(0);
//     freopen("mst.inp","r",stdin);
//     freopen("mst.out","w",stdout);

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

//    return 0;
//}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47444 KB Output is correct
2 Correct 22 ms 47452 KB Output is correct
3 Correct 24 ms 47720 KB Output is correct
4 Correct 25 ms 47708 KB Output is correct
5 Correct 24 ms 47960 KB Output is correct
6 Correct 24 ms 47832 KB Output is correct
7 Correct 25 ms 47960 KB Output is correct
8 Correct 25 ms 47696 KB Output is correct
9 Correct 25 ms 47964 KB Output is correct
10 Correct 25 ms 47704 KB Output is correct
11 Correct 24 ms 47708 KB Output is correct
12 Correct 25 ms 47700 KB Output is correct
13 Correct 25 ms 47704 KB Output is correct
14 Correct 28 ms 47708 KB Output is correct
15 Correct 28 ms 47708 KB Output is correct
16 Correct 30 ms 47716 KB Output is correct
17 Correct 25 ms 47708 KB Output is correct
18 Correct 25 ms 47704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47444 KB Output is correct
2 Correct 22 ms 47452 KB Output is correct
3 Correct 24 ms 47720 KB Output is correct
4 Correct 25 ms 47708 KB Output is correct
5 Correct 24 ms 47960 KB Output is correct
6 Correct 24 ms 47832 KB Output is correct
7 Correct 25 ms 47960 KB Output is correct
8 Correct 25 ms 47696 KB Output is correct
9 Correct 25 ms 47964 KB Output is correct
10 Correct 25 ms 47704 KB Output is correct
11 Correct 24 ms 47708 KB Output is correct
12 Correct 25 ms 47700 KB Output is correct
13 Correct 25 ms 47704 KB Output is correct
14 Correct 28 ms 47708 KB Output is correct
15 Correct 28 ms 47708 KB Output is correct
16 Correct 30 ms 47716 KB Output is correct
17 Correct 25 ms 47708 KB Output is correct
18 Correct 25 ms 47704 KB Output is correct
19 Correct 42 ms 49236 KB Output is correct
20 Correct 43 ms 49488 KB Output is correct
21 Correct 42 ms 49588 KB Output is correct
22 Correct 39 ms 49496 KB Output is correct
23 Correct 40 ms 49204 KB Output is correct
24 Correct 40 ms 49232 KB Output is correct
25 Correct 39 ms 49244 KB Output is correct
26 Correct 38 ms 49244 KB Output is correct
27 Correct 40 ms 49236 KB Output is correct
28 Correct 42 ms 49224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 49244 KB Output is correct
2 Correct 59 ms 51000 KB Output is correct
3 Correct 84 ms 52868 KB Output is correct
4 Correct 86 ms 52816 KB Output is correct
5 Correct 86 ms 52812 KB Output is correct
6 Correct 88 ms 52808 KB Output is correct
7 Correct 84 ms 53068 KB Output is correct
8 Correct 81 ms 52808 KB Output is correct
9 Correct 81 ms 52860 KB Output is correct
10 Correct 69 ms 52812 KB Output is correct
11 Correct 69 ms 52816 KB Output is correct
12 Correct 71 ms 52816 KB Output is correct
13 Correct 71 ms 52812 KB Output is correct
14 Correct 67 ms 52812 KB Output is correct
15 Correct 70 ms 52984 KB Output is correct
16 Correct 71 ms 52812 KB Output is correct
17 Correct 63 ms 52840 KB Output is correct
18 Correct 67 ms 52768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47444 KB Output is correct
2 Correct 22 ms 47452 KB Output is correct
3 Correct 24 ms 47720 KB Output is correct
4 Correct 25 ms 47708 KB Output is correct
5 Correct 24 ms 47960 KB Output is correct
6 Correct 24 ms 47832 KB Output is correct
7 Correct 25 ms 47960 KB Output is correct
8 Correct 25 ms 47696 KB Output is correct
9 Correct 25 ms 47964 KB Output is correct
10 Correct 25 ms 47704 KB Output is correct
11 Correct 24 ms 47708 KB Output is correct
12 Correct 25 ms 47700 KB Output is correct
13 Correct 25 ms 47704 KB Output is correct
14 Correct 28 ms 47708 KB Output is correct
15 Correct 28 ms 47708 KB Output is correct
16 Correct 30 ms 47716 KB Output is correct
17 Correct 25 ms 47708 KB Output is correct
18 Correct 25 ms 47704 KB Output is correct
19 Correct 42 ms 49236 KB Output is correct
20 Correct 43 ms 49488 KB Output is correct
21 Correct 42 ms 49588 KB Output is correct
22 Correct 39 ms 49496 KB Output is correct
23 Correct 40 ms 49204 KB Output is correct
24 Correct 40 ms 49232 KB Output is correct
25 Correct 39 ms 49244 KB Output is correct
26 Correct 38 ms 49244 KB Output is correct
27 Correct 40 ms 49236 KB Output is correct
28 Correct 42 ms 49224 KB Output is correct
29 Correct 32 ms 49244 KB Output is correct
30 Correct 59 ms 51000 KB Output is correct
31 Correct 84 ms 52868 KB Output is correct
32 Correct 86 ms 52816 KB Output is correct
33 Correct 86 ms 52812 KB Output is correct
34 Correct 88 ms 52808 KB Output is correct
35 Correct 84 ms 53068 KB Output is correct
36 Correct 81 ms 52808 KB Output is correct
37 Correct 81 ms 52860 KB Output is correct
38 Correct 69 ms 52812 KB Output is correct
39 Correct 69 ms 52816 KB Output is correct
40 Correct 71 ms 52816 KB Output is correct
41 Correct 71 ms 52812 KB Output is correct
42 Correct 67 ms 52812 KB Output is correct
43 Correct 70 ms 52984 KB Output is correct
44 Correct 71 ms 52812 KB Output is correct
45 Correct 63 ms 52840 KB Output is correct
46 Correct 67 ms 52768 KB Output is correct
47 Correct 564 ms 89656 KB Output is correct
48 Correct 2072 ms 174444 KB Output is correct
49 Correct 2307 ms 187444 KB Output is correct
50 Correct 2395 ms 187536 KB Output is correct
51 Correct 2306 ms 187436 KB Output is correct
52 Correct 2325 ms 187292 KB Output is correct
53 Correct 2177 ms 187408 KB Output is correct
54 Correct 1961 ms 187444 KB Output is correct
55 Correct 2085 ms 187444 KB Output is correct
56 Correct 1997 ms 187488 KB Output is correct
57 Correct 2102 ms 187444 KB Output is correct
58 Correct 2036 ms 187448 KB Output is correct
59 Correct 1809 ms 176496 KB Output is correct
60 Correct 1824 ms 176480 KB Output is correct
61 Correct 1844 ms 176488 KB Output is correct
62 Correct 1864 ms 171504 KB Output is correct
63 Correct 1701 ms 171572 KB Output is correct
64 Correct 1792 ms 171576 KB Output is correct
65 Correct 1623 ms 166452 KB Output is correct
66 Correct 1592 ms 166380 KB Output is correct
67 Correct 1624 ms 166460 KB Output is correct