Submission #747899

# Submission time Handle Problem Language Result Execution time Memory
747899 2023-05-25T07:03:41 Z Sami_Massah Bubble Sort 2 (JOI18_bubblesort2) C++11
100 / 100
4109 ms 103328 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 3 ms 340 KB Output is correct
2 Correct 2 ms 492 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 724 KB Output is correct
6 Correct 5 ms 768 KB Output is correct
7 Correct 5 ms 724 KB Output is correct
8 Correct 5 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 676 KB Output is correct
12 Correct 5 ms 596 KB Output is correct
13 Correct 4 ms 664 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
15 Correct 5 ms 588 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 5 ms 596 KB Output is correct
18 Correct 4 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 2 ms 492 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 724 KB Output is correct
6 Correct 5 ms 768 KB Output is correct
7 Correct 5 ms 724 KB Output is correct
8 Correct 5 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 676 KB Output is correct
12 Correct 5 ms 596 KB Output is correct
13 Correct 4 ms 664 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
15 Correct 5 ms 588 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 5 ms 596 KB Output is correct
18 Correct 4 ms 596 KB Output is correct
19 Correct 20 ms 1752 KB Output is correct
20 Correct 26 ms 2028 KB Output is correct
21 Correct 35 ms 1964 KB Output is correct
22 Correct 38 ms 1904 KB Output is correct
23 Correct 20 ms 1876 KB Output is correct
24 Correct 20 ms 1876 KB Output is correct
25 Correct 21 ms 1736 KB Output is correct
26 Correct 20 ms 1768 KB Output is correct
27 Correct 22 ms 1748 KB Output is correct
28 Correct 20 ms 1744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 3152 KB Output is correct
2 Correct 143 ms 6820 KB Output is correct
3 Correct 215 ms 11004 KB Output is correct
4 Correct 202 ms 10876 KB Output is correct
5 Correct 192 ms 10852 KB Output is correct
6 Correct 180 ms 10852 KB Output is correct
7 Correct 190 ms 10816 KB Output is correct
8 Correct 212 ms 10776 KB Output is correct
9 Correct 205 ms 10820 KB Output is correct
10 Correct 138 ms 7108 KB Output is correct
11 Correct 145 ms 7012 KB Output is correct
12 Correct 129 ms 7180 KB Output is correct
13 Correct 133 ms 7100 KB Output is correct
14 Correct 130 ms 7128 KB Output is correct
15 Correct 130 ms 7100 KB Output is correct
16 Correct 122 ms 7104 KB Output is correct
17 Correct 115 ms 7104 KB Output is correct
18 Correct 120 ms 7168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 2 ms 492 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 724 KB Output is correct
6 Correct 5 ms 768 KB Output is correct
7 Correct 5 ms 724 KB Output is correct
8 Correct 5 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 676 KB Output is correct
12 Correct 5 ms 596 KB Output is correct
13 Correct 4 ms 664 KB Output is correct
14 Correct 5 ms 596 KB Output is correct
15 Correct 5 ms 588 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 5 ms 596 KB Output is correct
18 Correct 4 ms 596 KB Output is correct
19 Correct 20 ms 1752 KB Output is correct
20 Correct 26 ms 2028 KB Output is correct
21 Correct 35 ms 1964 KB Output is correct
22 Correct 38 ms 1904 KB Output is correct
23 Correct 20 ms 1876 KB Output is correct
24 Correct 20 ms 1876 KB Output is correct
25 Correct 21 ms 1736 KB Output is correct
26 Correct 20 ms 1768 KB Output is correct
27 Correct 22 ms 1748 KB Output is correct
28 Correct 20 ms 1744 KB Output is correct
29 Correct 37 ms 3152 KB Output is correct
30 Correct 143 ms 6820 KB Output is correct
31 Correct 215 ms 11004 KB Output is correct
32 Correct 202 ms 10876 KB Output is correct
33 Correct 192 ms 10852 KB Output is correct
34 Correct 180 ms 10852 KB Output is correct
35 Correct 190 ms 10816 KB Output is correct
36 Correct 212 ms 10776 KB Output is correct
37 Correct 205 ms 10820 KB Output is correct
38 Correct 138 ms 7108 KB Output is correct
39 Correct 145 ms 7012 KB Output is correct
40 Correct 129 ms 7180 KB Output is correct
41 Correct 133 ms 7100 KB Output is correct
42 Correct 130 ms 7128 KB Output is correct
43 Correct 130 ms 7100 KB Output is correct
44 Correct 122 ms 7104 KB Output is correct
45 Correct 115 ms 7104 KB Output is correct
46 Correct 120 ms 7168 KB Output is correct
47 Correct 954 ms 34344 KB Output is correct
48 Correct 3746 ms 95752 KB Output is correct
49 Correct 3997 ms 102908 KB Output is correct
50 Correct 3957 ms 103012 KB Output is correct
51 Correct 4109 ms 102924 KB Output is correct
52 Correct 3958 ms 103068 KB Output is correct
53 Correct 3795 ms 102992 KB Output is correct
54 Correct 3259 ms 103168 KB Output is correct
55 Correct 3615 ms 102988 KB Output is correct
56 Correct 3286 ms 103116 KB Output is correct
57 Correct 3551 ms 103328 KB Output is correct
58 Correct 3344 ms 103064 KB Output is correct
59 Correct 3156 ms 95044 KB Output is correct
60 Correct 3199 ms 95220 KB Output is correct
61 Correct 3111 ms 95084 KB Output is correct
62 Correct 2969 ms 91160 KB Output is correct
63 Correct 2748 ms 91152 KB Output is correct
64 Correct 3025 ms 91248 KB Output is correct
65 Correct 2408 ms 87392 KB Output is correct
66 Correct 2454 ms 87384 KB Output is correct
67 Correct 2439 ms 87176 KB Output is correct