Submission #224816

# Submission time Handle Problem Language Result Execution time Memory
224816 2020-04-18T23:19:53 Z Bruteforceman Bubble Sort 2 (JOI18_bubblesort2) C++11
100 / 100
4777 ms 230776 KB
#include "bits/stdc++.h"
#include "bubblesort2.h"
using namespace std;
const int maxn = 1000010;
int t[4 * maxn], prop[4 * maxn], opt[maxn], pre[maxn];
set <int> cont[maxn];
int idx;

void pushdown(int c) {
    if(!prop[c]) return ;
    int l = c << 1;
    int r = l + 1;
    t[l] += prop[c]; t[r] += prop[c];
    prop[l] += prop[c]; prop[r] += prop[c];
    prop[c] = 0;
}
void add(int x, int y, int val, int c = 1, int b = 1, int e = idx) {
    if(x <= b && e <= y) {
        t[c] += val;
        prop[c] += val;
        return ;
    }
    if(y < b || e < x) return ;
    pushdown(c);
    int m = (b + e) >> 1;
    int l = c << 1;
    int r = l + 1;
    add(x, y, val, l, b, m);
    add(x, y, val, r, m + 1, e);
    t[c] = max(t[l], t[r]);
}
inline int getMin() {
    return max(0, t[1]);
}
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
    vector <int> answer (X.size());
    map <int, int> cmp;
    for(int i = 0; i < A.size(); i++) cmp[A[i]];
    for(int i = 0; i < V.size(); i++) cmp[V[i]];
    idx = 0;
    for(auto &i : cmp) {
        i.second = ++idx;
        pre[idx] = opt[idx] = 0;
        cont[idx].clear();
    }
    for(int i = 1; i <= idx * 4; i++) {
        t[i] = prop[i] = 0;
    }
    for(int i = 0; i < A.size(); i++) {
        A[i] = cmp[A[i]];
        pre[A[i]] += 1;
        opt[A[i]] = i + 1;
        cont[A[i]].insert(i + 1);
    }
    for(int i = 1; i <= idx; i++) {
        pre[i] += pre[i - 1];
        add(i, i, opt[i] - pre[i]);
        cont[i].insert(0);
    }
    for(int i = 0; i < V.size(); i++) {
        int x = X[i];
        int tmp;
        V[i] = cmp[V[i]];

        add(A[x], idx, 1);
        cont[A[x]].erase(x + 1);
        tmp = opt[A[x]];
        opt[A[x]] = *cont[A[x]].rbegin();
        add(A[x], A[x], opt[A[x]] - tmp);


        A[x] = V[i];
        add(A[x], idx, -1);
        cont[A[x]].insert(x + 1);
        tmp = opt[A[x]];
        opt[A[x]] = *cont[A[x]].rbegin();
        add(A[x], A[x], opt[A[x]] - tmp);
        answer[i] = getMin();
    }
    return answer;
}

Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:38:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < A.size(); i++) cmp[A[i]];
                    ~~^~~~~~~~~~
bubblesort2.cpp:39:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < V.size(); i++) cmp[V[i]];
                    ~~^~~~~~~~~~
bubblesort2.cpp:49:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < A.size(); i++) {
                    ~~^~~~~~~~~~
bubblesort2.cpp:60:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < V.size(); i++) {
                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 31 ms 47488 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 41 ms 47992 KB Output is correct
4 Correct 35 ms 48000 KB Output is correct
5 Correct 34 ms 47952 KB Output is correct
6 Correct 35 ms 48000 KB Output is correct
7 Correct 35 ms 48000 KB Output is correct
8 Correct 35 ms 48000 KB Output is correct
9 Correct 42 ms 48120 KB Output is correct
10 Correct 34 ms 47872 KB Output is correct
11 Correct 34 ms 47872 KB Output is correct
12 Correct 41 ms 47992 KB Output is correct
13 Correct 34 ms 47872 KB Output is correct
14 Correct 35 ms 47872 KB Output is correct
15 Correct 41 ms 47872 KB Output is correct
16 Correct 35 ms 47872 KB Output is correct
17 Correct 41 ms 47872 KB Output is correct
18 Correct 35 ms 47872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 47488 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 41 ms 47992 KB Output is correct
4 Correct 35 ms 48000 KB Output is correct
5 Correct 34 ms 47952 KB Output is correct
6 Correct 35 ms 48000 KB Output is correct
7 Correct 35 ms 48000 KB Output is correct
8 Correct 35 ms 48000 KB Output is correct
9 Correct 42 ms 48120 KB Output is correct
10 Correct 34 ms 47872 KB Output is correct
11 Correct 34 ms 47872 KB Output is correct
12 Correct 41 ms 47992 KB Output is correct
13 Correct 34 ms 47872 KB Output is correct
14 Correct 35 ms 47872 KB Output is correct
15 Correct 41 ms 47872 KB Output is correct
16 Correct 35 ms 47872 KB Output is correct
17 Correct 41 ms 47872 KB Output is correct
18 Correct 35 ms 47872 KB Output is correct
19 Correct 51 ms 49784 KB Output is correct
20 Correct 58 ms 50112 KB Output is correct
21 Correct 57 ms 50168 KB Output is correct
22 Correct 54 ms 50048 KB Output is correct
23 Correct 60 ms 49816 KB Output is correct
24 Correct 58 ms 49828 KB Output is correct
25 Correct 63 ms 49664 KB Output is correct
26 Correct 51 ms 49664 KB Output is correct
27 Correct 51 ms 49536 KB Output is correct
28 Correct 50 ms 49532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 48896 KB Output is correct
2 Correct 82 ms 50040 KB Output is correct
3 Correct 127 ms 51192 KB Output is correct
4 Correct 120 ms 51192 KB Output is correct
5 Correct 118 ms 51192 KB Output is correct
6 Correct 121 ms 51232 KB Output is correct
7 Correct 122 ms 51192 KB Output is correct
8 Correct 131 ms 51320 KB Output is correct
9 Correct 115 ms 51192 KB Output is correct
10 Correct 110 ms 51192 KB Output is correct
11 Correct 104 ms 51192 KB Output is correct
12 Correct 109 ms 51192 KB Output is correct
13 Correct 106 ms 51192 KB Output is correct
14 Correct 97 ms 51192 KB Output is correct
15 Correct 99 ms 51192 KB Output is correct
16 Correct 92 ms 51192 KB Output is correct
17 Correct 93 ms 51128 KB Output is correct
18 Correct 100 ms 51192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 47488 KB Output is correct
2 Correct 31 ms 47616 KB Output is correct
3 Correct 41 ms 47992 KB Output is correct
4 Correct 35 ms 48000 KB Output is correct
5 Correct 34 ms 47952 KB Output is correct
6 Correct 35 ms 48000 KB Output is correct
7 Correct 35 ms 48000 KB Output is correct
8 Correct 35 ms 48000 KB Output is correct
9 Correct 42 ms 48120 KB Output is correct
10 Correct 34 ms 47872 KB Output is correct
11 Correct 34 ms 47872 KB Output is correct
12 Correct 41 ms 47992 KB Output is correct
13 Correct 34 ms 47872 KB Output is correct
14 Correct 35 ms 47872 KB Output is correct
15 Correct 41 ms 47872 KB Output is correct
16 Correct 35 ms 47872 KB Output is correct
17 Correct 41 ms 47872 KB Output is correct
18 Correct 35 ms 47872 KB Output is correct
19 Correct 51 ms 49784 KB Output is correct
20 Correct 58 ms 50112 KB Output is correct
21 Correct 57 ms 50168 KB Output is correct
22 Correct 54 ms 50048 KB Output is correct
23 Correct 60 ms 49816 KB Output is correct
24 Correct 58 ms 49828 KB Output is correct
25 Correct 63 ms 49664 KB Output is correct
26 Correct 51 ms 49664 KB Output is correct
27 Correct 51 ms 49536 KB Output is correct
28 Correct 50 ms 49532 KB Output is correct
29 Correct 43 ms 48896 KB Output is correct
30 Correct 82 ms 50040 KB Output is correct
31 Correct 127 ms 51192 KB Output is correct
32 Correct 120 ms 51192 KB Output is correct
33 Correct 118 ms 51192 KB Output is correct
34 Correct 121 ms 51232 KB Output is correct
35 Correct 122 ms 51192 KB Output is correct
36 Correct 131 ms 51320 KB Output is correct
37 Correct 115 ms 51192 KB Output is correct
38 Correct 110 ms 51192 KB Output is correct
39 Correct 104 ms 51192 KB Output is correct
40 Correct 109 ms 51192 KB Output is correct
41 Correct 106 ms 51192 KB Output is correct
42 Correct 97 ms 51192 KB Output is correct
43 Correct 99 ms 51192 KB Output is correct
44 Correct 92 ms 51192 KB Output is correct
45 Correct 93 ms 51128 KB Output is correct
46 Correct 100 ms 51192 KB Output is correct
47 Correct 1155 ms 98808 KB Output is correct
48 Correct 4557 ms 213624 KB Output is correct
49 Correct 4760 ms 230700 KB Output is correct
50 Correct 4777 ms 230652 KB Output is correct
51 Correct 4692 ms 230476 KB Output is correct
52 Correct 4733 ms 230648 KB Output is correct
53 Correct 4632 ms 230460 KB Output is correct
54 Correct 4080 ms 230360 KB Output is correct
55 Correct 4487 ms 230560 KB Output is correct
56 Correct 4062 ms 230476 KB Output is correct
57 Correct 4591 ms 230776 KB Output is correct
58 Correct 4286 ms 230676 KB Output is correct
59 Correct 3553 ms 212816 KB Output is correct
60 Correct 4267 ms 212816 KB Output is correct
61 Correct 3512 ms 212696 KB Output is correct
62 Correct 3498 ms 204296 KB Output is correct
63 Correct 3366 ms 204164 KB Output is correct
64 Correct 3428 ms 204368 KB Output is correct
65 Correct 3211 ms 195976 KB Output is correct
66 Correct 3093 ms 195988 KB Output is correct
67 Correct 3164 ms 196036 KB Output is correct