Submission #747898

# Submission time Handle Problem Language Result Execution time Memory
747898 2023-05-25T07:02:53 Z Sami_Massah Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
3778 ms 103132 KB
#include <bits/stdc++.h>
using namespace std;


const int maxn = 1e6 + 12, inf = 1e8;
int n, m, len, num[maxn * 4], mx[maxn * 4];
vector <int> ans;
vector <pair<int, int>> pos;
map <pair<int, int>, int> cnv;

void update_tree(int l, int r, int u, int k, int L = 0, int R = len){
    if(r < L || R < l)
        return;
    if(l <= L && R <= r){
        num[u] += k;
        mx[u] += k;
        return;

    }
    int mid = (L + R) / 2;
    update_tree(l, r, u * 2, k, L, mid);
    update_tree(l, r, u * 2 + 1, k, mid + 1, R);
    mx[u] = max(mx[u * 2], mx[u * 2 + 1]) + num[u];
}

vector <int> countScans(vector <int> a, vector <int> y, vector <int> x){
    n = a.size();
    m = x.size();
    for(int i = 0; i < m; i++)
        pos.push_back(make_pair(x[i], y[i]));
    for(int i = 0; i < n; i++)
        pos.push_back(make_pair(a[i], i));
    sort(pos.begin(), pos.end());
    len = 1;
    for(auto i: pos)
        if(cnv[i] == 0){
            cnv[i] = len;
            len += 1;
        }

    for(int i = 0; i < n; i++){
        int now = cnv[make_pair(a[i], i)];
        update_tree(now + 1, len, 1, -1);
        update_tree(now, now, 1, i);
     //   cout << now + 1 << ' ' << len << endl;
 //       cout << now << endl << endl;
    }
   // cout << get_max(0, len, 1) << endl;
   // cout << endl;
    for(int i = 0; i < m; i++){
        int now = cnv[make_pair(a[y[i]], y[i])];
        update_tree(now + 1, len, 1, 1);
        update_tree(now, now, 1, -y[i]);

        now = cnv[make_pair(x[i], y[i])];
        update_tree(now + 1, len, 1, -1);
        update_tree(now, now, 1, y[i]);

        a[y[i]] = x[i];
        ans.push_back(mx[1]);
    }
    return ans;


}
/*
int main(){
    vector <int> a, x, y;
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        int b;
        cin >> b;
        a.push_back(b);
    }
    for(int i = 0; i < m; i++){
        int b, c;
        cin >> b >> c;
        x.push_back(b);
        y.push_back(c);
    }
    countScans(a, x, y);
    for(int i: ans)
        cout << i << ' ';




}*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 5 ms 724 KB Output is correct
4 Correct 5 ms 724 KB Output is correct
5 Correct 5 ms 744 KB Output is correct
6 Correct 5 ms 724 KB Output is correct
7 Correct 5 ms 712 KB Output is correct
8 Correct 7 ms 724 KB Output is correct
9 Correct 5 ms 724 KB Output is correct
10 Correct 5 ms 596 KB Output is correct
11 Correct 5 ms 596 KB Output is correct
12 Correct 4 ms 596 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 4 ms 596 KB Output is correct
15 Correct 5 ms 692 KB Output is correct
16 Correct 5 ms 664 KB Output is correct
17 Correct 4 ms 596 KB Output is correct
18 Correct 5 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 5 ms 724 KB Output is correct
4 Correct 5 ms 724 KB Output is correct
5 Correct 5 ms 744 KB Output is correct
6 Correct 5 ms 724 KB Output is correct
7 Correct 5 ms 712 KB Output is correct
8 Correct 7 ms 724 KB Output is correct
9 Correct 5 ms 724 KB Output is correct
10 Correct 5 ms 596 KB Output is correct
11 Correct 5 ms 596 KB Output is correct
12 Correct 4 ms 596 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 4 ms 596 KB Output is correct
15 Correct 5 ms 692 KB Output is correct
16 Correct 5 ms 664 KB Output is correct
17 Correct 4 ms 596 KB Output is correct
18 Correct 5 ms 596 KB Output is correct
19 Correct 20 ms 1724 KB Output is correct
20 Correct 22 ms 1944 KB Output is correct
21 Correct 20 ms 1964 KB Output is correct
22 Correct 22 ms 2024 KB Output is correct
23 Correct 19 ms 1876 KB Output is correct
24 Correct 19 ms 1876 KB Output is correct
25 Correct 19 ms 1748 KB Output is correct
26 Correct 20 ms 1772 KB Output is correct
27 Correct 18 ms 1676 KB Output is correct
28 Correct 18 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 3096 KB Output is correct
2 Correct 106 ms 6672 KB Output is correct
3 Correct 187 ms 10984 KB Output is correct
4 Correct 190 ms 10956 KB Output is correct
5 Correct 230 ms 10896 KB Output is correct
6 Correct 203 ms 10792 KB Output is correct
7 Correct 209 ms 10844 KB Output is correct
8 Correct 198 ms 10812 KB Output is correct
9 Correct 204 ms 10868 KB Output is correct
10 Correct 129 ms 7140 KB Output is correct
11 Correct 121 ms 7068 KB Output is correct
12 Correct 127 ms 7044 KB Output is correct
13 Correct 123 ms 7096 KB Output is correct
14 Correct 126 ms 7108 KB Output is correct
15 Correct 119 ms 7272 KB Output is correct
16 Correct 108 ms 7088 KB Output is correct
17 Correct 108 ms 7144 KB Output is correct
18 Correct 108 ms 7136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 5 ms 724 KB Output is correct
4 Correct 5 ms 724 KB Output is correct
5 Correct 5 ms 744 KB Output is correct
6 Correct 5 ms 724 KB Output is correct
7 Correct 5 ms 712 KB Output is correct
8 Correct 7 ms 724 KB Output is correct
9 Correct 5 ms 724 KB Output is correct
10 Correct 5 ms 596 KB Output is correct
11 Correct 5 ms 596 KB Output is correct
12 Correct 4 ms 596 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 4 ms 596 KB Output is correct
15 Correct 5 ms 692 KB Output is correct
16 Correct 5 ms 664 KB Output is correct
17 Correct 4 ms 596 KB Output is correct
18 Correct 5 ms 596 KB Output is correct
19 Correct 20 ms 1724 KB Output is correct
20 Correct 22 ms 1944 KB Output is correct
21 Correct 20 ms 1964 KB Output is correct
22 Correct 22 ms 2024 KB Output is correct
23 Correct 19 ms 1876 KB Output is correct
24 Correct 19 ms 1876 KB Output is correct
25 Correct 19 ms 1748 KB Output is correct
26 Correct 20 ms 1772 KB Output is correct
27 Correct 18 ms 1676 KB Output is correct
28 Correct 18 ms 1748 KB Output is correct
29 Correct 36 ms 3096 KB Output is correct
30 Correct 106 ms 6672 KB Output is correct
31 Correct 187 ms 10984 KB Output is correct
32 Correct 190 ms 10956 KB Output is correct
33 Correct 230 ms 10896 KB Output is correct
34 Correct 203 ms 10792 KB Output is correct
35 Correct 209 ms 10844 KB Output is correct
36 Correct 198 ms 10812 KB Output is correct
37 Correct 204 ms 10868 KB Output is correct
38 Correct 129 ms 7140 KB Output is correct
39 Correct 121 ms 7068 KB Output is correct
40 Correct 127 ms 7044 KB Output is correct
41 Correct 123 ms 7096 KB Output is correct
42 Correct 126 ms 7108 KB Output is correct
43 Correct 119 ms 7272 KB Output is correct
44 Correct 108 ms 7088 KB Output is correct
45 Correct 108 ms 7144 KB Output is correct
46 Correct 108 ms 7136 KB Output is correct
47 Correct 909 ms 34432 KB Output is correct
48 Correct 3434 ms 96064 KB Output is correct
49 Correct 3755 ms 102976 KB Output is correct
50 Correct 3713 ms 103060 KB Output is correct
51 Correct 3778 ms 103004 KB Output is correct
52 Correct 3697 ms 102992 KB Output is correct
53 Correct 3651 ms 103032 KB Output is correct
54 Correct 3371 ms 103044 KB Output is correct
55 Correct 3536 ms 103056 KB Output is correct
56 Correct 3339 ms 103132 KB Output is correct
57 Correct 3591 ms 102964 KB Output is correct
58 Correct 3599 ms 102836 KB Output is correct
59 Correct 3129 ms 95068 KB Output is correct
60 Correct 3182 ms 95148 KB Output is correct
61 Correct 2931 ms 95032 KB Output is correct
62 Correct 2901 ms 91180 KB Output is correct
63 Correct 2779 ms 91180 KB Output is correct
64 Correct 3117 ms 91320 KB Output is correct
65 Correct 2584 ms 87284 KB Output is correct
66 Correct 2641 ms 87276 KB Output is correct
67 Correct 2627 ms 87428 KB Output is correct