Submission #1093901

# Submission time Handle Problem Language Result Execution time Memory
1093901 2024-09-28T04:20:27 Z anhthi Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
1601 ms 132816 KB
#include <bits/stdc++.h>
#include "bubblesort2.h"

using namespace std;

#define fi first
#define se second
#define ll long long
#define mp(x, y) make_pair(x, y)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define pb push_back
#define max_rng *max_element
#define min_rng *min_element
#define rep(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define forn(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)

template <class X, class Y>
    inline bool maximize(X &x, Y y) {
        return (x < y ? x = y, true : false);
    }

template <class X, class Y>
    inline bool minimize(X &x, Y y) {
        return (x > y ? x = y, true : false);
    }

template <class X>
    inline void compress(vector<X> &a) {
        sort(all(a));
        a.resize(unique(all(a)) - a.begin());
    }

int ctz(ll x) { return __builtin_ctzll(x); }
int lg(ll x) { return 63 - __builtin_clzll(x); }
int popcount(ll x) { return __builtin_popcount(x); }

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) {
    return l + abs((ll) rng()) % (r - l + 1);
}

const ll oo = (ll) 1e17;
const int inf = (ll) 2e9 + 7, mod = (ll) 1e9 + 7;

const int mxn = 5e5 + 5, LOG = 50;

void add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
void sub(int &x, int y) { x -= y; if (x < 0) x += mod; }

struct Seg {
    int n;
    vector<int> st, lz;

    Seg(int n) : n(n) {
        lz.resize(n << 2); st.resize(n << 2);
    }

    void setOne(int i, int d) {
        st[i] += d;
        lz[i] += d;
    }

    void down(int i) {
        if (!lz[i])
            return;
        setOne(2 * i, lz[i]);
        setOne(2 * i + 1, lz[i]);
        lz[i] = 0;
    }

    void upd(int i, int l, int r, int u, int v, int d) {
        if (l > v || r < u) return;
        if (l >= u && r <= v) {
            return setOne(i, d);
        }
        down(i);
        int m = (l + r) >> 1;
        upd(2 * i, l, m, u, v, d);
        upd(2 * i + 1, m + 1, r, u, v, d);

        st[i] = max(st[2 * i], st[2 * i + 1]);
    }

    void upd(int u, int v, int d) {
        if (u > v) return;
        return upd(1, 1, n, u, v, d);
    }
    int get() {
        return st[1];
    }
};

set<int> s[mxn << 1];

vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){

    int n = sz(A), q = sz(X);

    vector<int> cps;
    for (int i : A) cps.pb(i);
    for (int i : V) cps.pb(i);

    compress(cps);
    for (int &i : A) i = lower_bound(all(cps), i) - cps.begin() + 1;
    for (int &i : V) i = lower_bound(all(cps), i) - cps.begin() + 1;

    int m = sz(cps);
    forn(i, 0, n - 1) {
        s[A[i]].insert(i + 1);
    }
    Seg seg(m);
    forn(i, 1, m) if (sz(s[i])) {
        seg.upd(i, i, *s[i].rbegin());
        seg.upd(i, m, -sz(s[i]));
    }

    vector<int> ans(q);
    forn(i, 0, q - 1) {
        int p = X[i];
        int value = V[i];

        seg.upd(A[p], m, +1);
        seg.upd(A[p], A[p], -(*s[A[p]].rbegin()));
        s[A[p]].erase(p + 1);
        if (sz(s[A[p]])) seg.upd(A[p], A[p], *s[A[p]].rbegin());

        A[p] = value;

        seg.upd(A[p], m, -1);
        if (sz(s[A[p]])) seg.upd(A[p], A[p], -(*s[A[p]].rbegin()));
        s[A[p]].insert(p + 1);
        seg.upd(A[p], A[p], *s[A[p]].rbegin());

        ans[i] = seg.get();
    }

    return ans;
}

//int main(void) {
//
//    ios_base::sync_with_stdio(0);
//    cin.tie(0); cout.tie(0);
//
//    #define TASK "cquery"
//    if (fopen(TASK".inp", "r")) {
//        freopen(TASK".inp", "r", stdin);
//        freopen(TASK".out", "w", stdout);
//    }
//
//    vector<int> A = {1, 2, 3, 4};
//    vector<int> X = {0, 2};
//    vector<int> V = {3, 1};
//
//    for (int val : countScans(A, X, V))
//        cout << val << '\n';
//
//    return 0;
//}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47448 KB Output is correct
2 Correct 20 ms 47452 KB Output is correct
3 Correct 22 ms 47528 KB Output is correct
4 Correct 22 ms 47708 KB Output is correct
5 Correct 22 ms 47708 KB Output is correct
6 Correct 22 ms 47708 KB Output is correct
7 Correct 23 ms 47708 KB Output is correct
8 Correct 24 ms 47632 KB Output is correct
9 Correct 22 ms 47692 KB Output is correct
10 Correct 22 ms 47708 KB Output is correct
11 Correct 22 ms 47704 KB Output is correct
12 Correct 22 ms 47696 KB Output is correct
13 Correct 27 ms 47560 KB Output is correct
14 Correct 22 ms 47576 KB Output is correct
15 Correct 22 ms 47708 KB Output is correct
16 Correct 22 ms 47676 KB Output is correct
17 Correct 22 ms 47704 KB Output is correct
18 Correct 22 ms 47708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47448 KB Output is correct
2 Correct 20 ms 47452 KB Output is correct
3 Correct 22 ms 47528 KB Output is correct
4 Correct 22 ms 47708 KB Output is correct
5 Correct 22 ms 47708 KB Output is correct
6 Correct 22 ms 47708 KB Output is correct
7 Correct 23 ms 47708 KB Output is correct
8 Correct 24 ms 47632 KB Output is correct
9 Correct 22 ms 47692 KB Output is correct
10 Correct 22 ms 47708 KB Output is correct
11 Correct 22 ms 47704 KB Output is correct
12 Correct 22 ms 47696 KB Output is correct
13 Correct 27 ms 47560 KB Output is correct
14 Correct 22 ms 47576 KB Output is correct
15 Correct 22 ms 47708 KB Output is correct
16 Correct 22 ms 47676 KB Output is correct
17 Correct 22 ms 47704 KB Output is correct
18 Correct 22 ms 47708 KB Output is correct
19 Correct 30 ms 48468 KB Output is correct
20 Correct 33 ms 48732 KB Output is correct
21 Correct 38 ms 48720 KB Output is correct
22 Correct 37 ms 48732 KB Output is correct
23 Correct 35 ms 48592 KB Output is correct
24 Correct 43 ms 48472 KB Output is correct
25 Correct 37 ms 48464 KB Output is correct
26 Correct 37 ms 48476 KB Output is correct
27 Correct 33 ms 48468 KB Output is correct
28 Correct 38 ms 48476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 48988 KB Output is correct
2 Correct 54 ms 50136 KB Output is correct
3 Correct 85 ms 51400 KB Output is correct
4 Correct 84 ms 51412 KB Output is correct
5 Correct 87 ms 51400 KB Output is correct
6 Correct 83 ms 51400 KB Output is correct
7 Correct 83 ms 51396 KB Output is correct
8 Correct 83 ms 51404 KB Output is correct
9 Correct 100 ms 51376 KB Output is correct
10 Correct 80 ms 51400 KB Output is correct
11 Correct 68 ms 51304 KB Output is correct
12 Correct 67 ms 51312 KB Output is correct
13 Correct 62 ms 51400 KB Output is correct
14 Correct 64 ms 51400 KB Output is correct
15 Correct 65 ms 51408 KB Output is correct
16 Correct 63 ms 51304 KB Output is correct
17 Correct 60 ms 51396 KB Output is correct
18 Correct 64 ms 51404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47448 KB Output is correct
2 Correct 20 ms 47452 KB Output is correct
3 Correct 22 ms 47528 KB Output is correct
4 Correct 22 ms 47708 KB Output is correct
5 Correct 22 ms 47708 KB Output is correct
6 Correct 22 ms 47708 KB Output is correct
7 Correct 23 ms 47708 KB Output is correct
8 Correct 24 ms 47632 KB Output is correct
9 Correct 22 ms 47692 KB Output is correct
10 Correct 22 ms 47708 KB Output is correct
11 Correct 22 ms 47704 KB Output is correct
12 Correct 22 ms 47696 KB Output is correct
13 Correct 27 ms 47560 KB Output is correct
14 Correct 22 ms 47576 KB Output is correct
15 Correct 22 ms 47708 KB Output is correct
16 Correct 22 ms 47676 KB Output is correct
17 Correct 22 ms 47704 KB Output is correct
18 Correct 22 ms 47708 KB Output is correct
19 Correct 30 ms 48468 KB Output is correct
20 Correct 33 ms 48732 KB Output is correct
21 Correct 38 ms 48720 KB Output is correct
22 Correct 37 ms 48732 KB Output is correct
23 Correct 35 ms 48592 KB Output is correct
24 Correct 43 ms 48472 KB Output is correct
25 Correct 37 ms 48464 KB Output is correct
26 Correct 37 ms 48476 KB Output is correct
27 Correct 33 ms 48468 KB Output is correct
28 Correct 38 ms 48476 KB Output is correct
29 Correct 29 ms 48988 KB Output is correct
30 Correct 54 ms 50136 KB Output is correct
31 Correct 85 ms 51400 KB Output is correct
32 Correct 84 ms 51412 KB Output is correct
33 Correct 87 ms 51400 KB Output is correct
34 Correct 83 ms 51400 KB Output is correct
35 Correct 83 ms 51396 KB Output is correct
36 Correct 83 ms 51404 KB Output is correct
37 Correct 100 ms 51376 KB Output is correct
38 Correct 80 ms 51400 KB Output is correct
39 Correct 68 ms 51304 KB Output is correct
40 Correct 67 ms 51312 KB Output is correct
41 Correct 62 ms 51400 KB Output is correct
42 Correct 64 ms 51400 KB Output is correct
43 Correct 65 ms 51408 KB Output is correct
44 Correct 63 ms 51304 KB Output is correct
45 Correct 60 ms 51396 KB Output is correct
46 Correct 64 ms 51404 KB Output is correct
47 Correct 393 ms 72812 KB Output is correct
48 Correct 1517 ms 124356 KB Output is correct
49 Correct 1500 ms 132524 KB Output is correct
50 Correct 1508 ms 132536 KB Output is correct
51 Correct 1551 ms 132636 KB Output is correct
52 Correct 1601 ms 132508 KB Output is correct
53 Correct 1540 ms 132484 KB Output is correct
54 Correct 1520 ms 132800 KB Output is correct
55 Correct 1561 ms 132792 KB Output is correct
56 Correct 1487 ms 132816 KB Output is correct
57 Correct 1427 ms 132796 KB Output is correct
58 Correct 1431 ms 132792 KB Output is correct
59 Correct 1374 ms 127416 KB Output is correct
60 Correct 1373 ms 127420 KB Output is correct
61 Correct 1392 ms 127416 KB Output is correct
62 Correct 1309 ms 125488 KB Output is correct
63 Correct 1285 ms 125460 KB Output is correct
64 Correct 1320 ms 125368 KB Output is correct
65 Correct 1232 ms 123396 KB Output is correct
66 Correct 1157 ms 123324 KB Output is correct
67 Correct 1117 ms 123320 KB Output is correct