Submission #975223

# Submission time Handle Problem Language Result Execution time Memory
975223 2024-05-04T15:02:20 Z LOLOLO Bubble Sort 2 (JOI18_bubblesort2) C++17
38 / 100
29 ms 52916 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 1e6 + 100;

struct seg{
    vector <int> st, laz;
    void ass(int n) {
        st.assign(n * 4 + 100, 0);
        laz.assign(n * 4 + 100, 0);
    }

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

    void upd(int id, int l, int r, int u, int v, int c) {
        if (l > v || r < u || u > v)
            return;

        if (l >= u && r <= v) {
            st[id] += c;
            laz[id] += c;
            return;
        }

        push(id);
        int m = (l + r) / 2;
        upd(id * 2, l, m, u, v, c);
        upd(id * 2 + 1, m + 1, r, u, v, c);
        st[id] = max(st[id * 2], st[id * 2 + 1]);
    }

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

set <int> pos[N];
int a[N], used[N];

vector <int> countScans(vector <int> A, vector <int> X, vector <int> V) {
    map <int, int> mp;
    for (auto &x : A)
        mp[x];

    for (auto &x : V)
        mp[x];

    int sz = 0;
    for (auto &x : mp) {
        sz++;
        x.s = sz;
    }

    seg st;
    st.ass(sz);

    int n = sz(A);
    for (int i = 0; i < n; i++) {
        A[i] = mp[A[i]];
        a[i + 1] = A[i];
        pos[a[i + 1]].insert(i + 1);
    }

    for (auto &x : V)
        x = mp[x];

    for (int i = n; i >= 1; i--) {
        if (used[a[i]] == 0) {
            used[a[i]] = 1;
            st.upd(1, 1, sz, a[i], a[i], i);       
        }

        st.upd(1, 1, sz, a[i] + 1, sz, -1);
    }

    vector <int> ans;
    int q = sz(X);

    for (int i = 0; i < q; i++) {
        X[i]++;
        int v = a[X[i]], nx = V[i];
        st.upd(1, 1, sz, v + 1, sz, 1);
        st.upd(1, 1, sz, nx + 1, sz, -1);

        if (*(--pos[v].end()) == X[i]) {
            if (sz(pos[v]) == 1) {
                st.upd(1, 1, sz, v, v, -X[i]);
            } else {
                auto it = (--pos[v].end());
                it--;
                st.upd(1, 1, sz, v, v, -(X[i] - (*it)));
            }
        }

        pos[v].erase(X[i]);
        a[X[i]] = nx;

        if (pos[nx].empty() || *(--pos[nx].end()) < X[i]) {
            int add = X[i];
            if (sz(pos[nx])) {
                add -= *(--pos[nx].end());
            }
            st.upd(1, 1, sz, nx, nx, add);
        }

        pos[nx].insert(X[i]);
        ans.pb(max(0, st.get() - 1));
    }

    return ans;
}


 
# Verdict Execution time Memory Grader output
1 Correct 14 ms 51036 KB Output is correct
2 Correct 12 ms 51288 KB Output is correct
3 Correct 17 ms 51292 KB Output is correct
4 Correct 15 ms 51440 KB Output is correct
5 Correct 14 ms 51288 KB Output is correct
6 Correct 14 ms 51540 KB Output is correct
7 Correct 14 ms 51292 KB Output is correct
8 Correct 14 ms 51208 KB Output is correct
9 Correct 15 ms 51384 KB Output is correct
10 Correct 14 ms 51412 KB Output is correct
11 Correct 14 ms 51292 KB Output is correct
12 Correct 14 ms 51288 KB Output is correct
13 Correct 17 ms 51288 KB Output is correct
14 Correct 14 ms 51292 KB Output is correct
15 Correct 14 ms 51292 KB Output is correct
16 Correct 15 ms 51148 KB Output is correct
17 Correct 14 ms 51196 KB Output is correct
18 Correct 14 ms 51292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 51036 KB Output is correct
2 Correct 12 ms 51288 KB Output is correct
3 Correct 17 ms 51292 KB Output is correct
4 Correct 15 ms 51440 KB Output is correct
5 Correct 14 ms 51288 KB Output is correct
6 Correct 14 ms 51540 KB Output is correct
7 Correct 14 ms 51292 KB Output is correct
8 Correct 14 ms 51208 KB Output is correct
9 Correct 15 ms 51384 KB Output is correct
10 Correct 14 ms 51412 KB Output is correct
11 Correct 14 ms 51292 KB Output is correct
12 Correct 14 ms 51288 KB Output is correct
13 Correct 17 ms 51288 KB Output is correct
14 Correct 14 ms 51292 KB Output is correct
15 Correct 14 ms 51292 KB Output is correct
16 Correct 15 ms 51148 KB Output is correct
17 Correct 14 ms 51196 KB Output is correct
18 Correct 14 ms 51292 KB Output is correct
19 Correct 26 ms 52572 KB Output is correct
20 Correct 29 ms 52828 KB Output is correct
21 Correct 28 ms 52916 KB Output is correct
22 Correct 29 ms 52828 KB Output is correct
23 Correct 27 ms 52572 KB Output is correct
24 Correct 26 ms 52548 KB Output is correct
25 Correct 26 ms 52828 KB Output is correct
26 Correct 28 ms 52568 KB Output is correct
27 Correct 26 ms 52572 KB Output is correct
28 Correct 27 ms 52816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 52316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 51036 KB Output is correct
2 Correct 12 ms 51288 KB Output is correct
3 Correct 17 ms 51292 KB Output is correct
4 Correct 15 ms 51440 KB Output is correct
5 Correct 14 ms 51288 KB Output is correct
6 Correct 14 ms 51540 KB Output is correct
7 Correct 14 ms 51292 KB Output is correct
8 Correct 14 ms 51208 KB Output is correct
9 Correct 15 ms 51384 KB Output is correct
10 Correct 14 ms 51412 KB Output is correct
11 Correct 14 ms 51292 KB Output is correct
12 Correct 14 ms 51288 KB Output is correct
13 Correct 17 ms 51288 KB Output is correct
14 Correct 14 ms 51292 KB Output is correct
15 Correct 14 ms 51292 KB Output is correct
16 Correct 15 ms 51148 KB Output is correct
17 Correct 14 ms 51196 KB Output is correct
18 Correct 14 ms 51292 KB Output is correct
19 Correct 26 ms 52572 KB Output is correct
20 Correct 29 ms 52828 KB Output is correct
21 Correct 28 ms 52916 KB Output is correct
22 Correct 29 ms 52828 KB Output is correct
23 Correct 27 ms 52572 KB Output is correct
24 Correct 26 ms 52548 KB Output is correct
25 Correct 26 ms 52828 KB Output is correct
26 Correct 28 ms 52568 KB Output is correct
27 Correct 26 ms 52572 KB Output is correct
28 Correct 27 ms 52816 KB Output is correct
29 Incorrect 22 ms 52316 KB Output isn't correct
30 Halted 0 ms 0 KB -