Submission #1114221

# Submission time Handle Problem Language Result Execution time Memory
1114221 2024-11-18T11:32:13 Z farica Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
1908 ms 70744 KB
#include <bits/stdc++.h>

using namespace std;
using vi = vector<int>;

vi a, segm, lazy;
vector<pair<int,int>>V;

void propagate(int pos, int l, int r) {
    if(l==r) return;
    int m = (l+r)/2, right = pos + 2 * (m-l+1);
    lazy[pos+1] += lazy[pos];
    lazy[right] += lazy[pos];
    segm[pos+1] += lazy[pos];
    segm[right] += lazy[pos];
    lazy[pos] = 0;
}

void upd(int pos, int l, int r, int L, int R, int val) {
    if(l > R or r < L) return;
    propagate(pos, l, r);
    if(l >= L && r <= R) {
        segm[pos] += val;
        lazy[pos] += val;
        return;
    }
    int m = (l+r)/2, right = pos + 2 * (m-l+1);
    if(L <= m) upd(pos+1, l, m, L, R, val);
    if(R >= m+1) upd(right, m+1, r, L, R, val);
    segm[pos] = max(segm[pos+1], segm[right]);
}

void add(int i, int x) {
    int j = lower_bound(V.begin(), V.end(), make_pair(a[i], i)) - V.begin();
    int j2 = lower_bound(V.begin(), V.end(), make_pair(a[i], -1)) - V.begin();
    upd(0, 0, V.size()-1, j, j, x*(i+1));
    upd(0, 0, V.size()-1, j2, V.size()-1, -x);
}

vi countScans(vi A, vi x, vi y) {
    int n = A.size(), q = x.size();
    vi ans;
    V.clear();
    segm.assign(8*n, 0);
    lazy.assign(8*n, 0);
    a.assign(n, 0);
    for(int i=0; i<n; ++i) {
        a[i] = A[i];
        V.push_back({A[i], i});
    }
    for(int i=0; i<q; ++i) V.push_back({y[i], x[i]});
    sort(V.begin(), V.end());
    V.erase(unique(V.begin(), V.end()), V.end());
    for(int i=0; i<n; ++i) add(i, 1);
    for(int i=0; i<q; ++i) {
        add(x[i], -1);
        a[x[i]] = y[i];
        add(x[i], 1);
        ans.push_back(segm[0]);
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 3 ms 336 KB Output is correct
3 Correct 5 ms 592 KB Output is correct
4 Correct 5 ms 592 KB Output is correct
5 Correct 5 ms 592 KB Output is correct
6 Correct 4 ms 592 KB Output is correct
7 Correct 5 ms 592 KB Output is correct
8 Correct 5 ms 592 KB Output is correct
9 Correct 5 ms 592 KB Output is correct
10 Correct 4 ms 592 KB Output is correct
11 Correct 5 ms 592 KB Output is correct
12 Correct 4 ms 592 KB Output is correct
13 Correct 4 ms 592 KB Output is correct
14 Correct 5 ms 592 KB Output is correct
15 Correct 4 ms 716 KB Output is correct
16 Correct 4 ms 592 KB Output is correct
17 Correct 4 ms 592 KB Output is correct
18 Correct 4 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 3 ms 336 KB Output is correct
3 Correct 5 ms 592 KB Output is correct
4 Correct 5 ms 592 KB Output is correct
5 Correct 5 ms 592 KB Output is correct
6 Correct 4 ms 592 KB Output is correct
7 Correct 5 ms 592 KB Output is correct
8 Correct 5 ms 592 KB Output is correct
9 Correct 5 ms 592 KB Output is correct
10 Correct 4 ms 592 KB Output is correct
11 Correct 5 ms 592 KB Output is correct
12 Correct 4 ms 592 KB Output is correct
13 Correct 4 ms 592 KB Output is correct
14 Correct 5 ms 592 KB Output is correct
15 Correct 4 ms 716 KB Output is correct
16 Correct 4 ms 592 KB Output is correct
17 Correct 4 ms 592 KB Output is correct
18 Correct 4 ms 592 KB Output is correct
19 Correct 15 ms 1360 KB Output is correct
20 Correct 18 ms 1600 KB Output is correct
21 Correct 22 ms 1616 KB Output is correct
22 Correct 18 ms 1616 KB Output is correct
23 Correct 17 ms 1616 KB Output is correct
24 Correct 16 ms 1616 KB Output is correct
25 Correct 16 ms 1360 KB Output is correct
26 Correct 17 ms 1360 KB Output is correct
27 Correct 16 ms 1360 KB Output is correct
28 Correct 16 ms 1576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 2896 KB Output is correct
2 Correct 69 ms 4732 KB Output is correct
3 Correct 115 ms 6600 KB Output is correct
4 Correct 121 ms 6600 KB Output is correct
5 Correct 107 ms 6680 KB Output is correct
6 Correct 105 ms 6688 KB Output is correct
7 Correct 107 ms 6592 KB Output is correct
8 Correct 110 ms 6600 KB Output is correct
9 Correct 103 ms 6600 KB Output is correct
10 Correct 84 ms 6768 KB Output is correct
11 Correct 84 ms 6600 KB Output is correct
12 Correct 88 ms 6600 KB Output is correct
13 Correct 82 ms 6860 KB Output is correct
14 Correct 83 ms 6768 KB Output is correct
15 Correct 82 ms 6600 KB Output is correct
16 Correct 80 ms 6600 KB Output is correct
17 Correct 79 ms 6600 KB Output is correct
18 Correct 81 ms 6600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 3 ms 336 KB Output is correct
3 Correct 5 ms 592 KB Output is correct
4 Correct 5 ms 592 KB Output is correct
5 Correct 5 ms 592 KB Output is correct
6 Correct 4 ms 592 KB Output is correct
7 Correct 5 ms 592 KB Output is correct
8 Correct 5 ms 592 KB Output is correct
9 Correct 5 ms 592 KB Output is correct
10 Correct 4 ms 592 KB Output is correct
11 Correct 5 ms 592 KB Output is correct
12 Correct 4 ms 592 KB Output is correct
13 Correct 4 ms 592 KB Output is correct
14 Correct 5 ms 592 KB Output is correct
15 Correct 4 ms 716 KB Output is correct
16 Correct 4 ms 592 KB Output is correct
17 Correct 4 ms 592 KB Output is correct
18 Correct 4 ms 592 KB Output is correct
19 Correct 15 ms 1360 KB Output is correct
20 Correct 18 ms 1600 KB Output is correct
21 Correct 22 ms 1616 KB Output is correct
22 Correct 18 ms 1616 KB Output is correct
23 Correct 17 ms 1616 KB Output is correct
24 Correct 16 ms 1616 KB Output is correct
25 Correct 16 ms 1360 KB Output is correct
26 Correct 17 ms 1360 KB Output is correct
27 Correct 16 ms 1360 KB Output is correct
28 Correct 16 ms 1576 KB Output is correct
29 Correct 22 ms 2896 KB Output is correct
30 Correct 69 ms 4732 KB Output is correct
31 Correct 115 ms 6600 KB Output is correct
32 Correct 121 ms 6600 KB Output is correct
33 Correct 107 ms 6680 KB Output is correct
34 Correct 105 ms 6688 KB Output is correct
35 Correct 107 ms 6592 KB Output is correct
36 Correct 110 ms 6600 KB Output is correct
37 Correct 103 ms 6600 KB Output is correct
38 Correct 84 ms 6768 KB Output is correct
39 Correct 84 ms 6600 KB Output is correct
40 Correct 88 ms 6600 KB Output is correct
41 Correct 82 ms 6860 KB Output is correct
42 Correct 83 ms 6768 KB Output is correct
43 Correct 82 ms 6600 KB Output is correct
44 Correct 80 ms 6600 KB Output is correct
45 Correct 79 ms 6600 KB Output is correct
46 Correct 81 ms 6600 KB Output is correct
47 Correct 424 ms 24248 KB Output is correct
48 Correct 1751 ms 63812 KB Output is correct
49 Correct 1908 ms 70452 KB Output is correct
50 Correct 1847 ms 70496 KB Output is correct
51 Correct 1817 ms 70744 KB Output is correct
52 Correct 1771 ms 70308 KB Output is correct
53 Correct 1809 ms 70372 KB Output is correct
54 Correct 1571 ms 70568 KB Output is correct
55 Correct 1735 ms 70500 KB Output is correct
56 Correct 1685 ms 70476 KB Output is correct
57 Correct 1823 ms 70668 KB Output is correct
58 Correct 1907 ms 70580 KB Output is correct
59 Correct 1526 ms 69484 KB Output is correct
60 Correct 1583 ms 69144 KB Output is correct
61 Correct 1532 ms 69316 KB Output is correct
62 Correct 1519 ms 69032 KB Output is correct
63 Correct 1540 ms 68980 KB Output is correct
64 Correct 1472 ms 69212 KB Output is correct
65 Correct 1376 ms 69028 KB Output is correct
66 Correct 1382 ms 69032 KB Output is correct
67 Correct 1308 ms 69036 KB Output is correct