Submission #758542

# Submission time Handle Problem Language Result Execution time Memory
758542 2023-06-14T19:41:06 Z Hanksburger Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
1998 ms 53576 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
int seg[4000005], lazy[4000005];
vector<pair<int, int> > vec;
vector<int> ans;
void push(int i, int l, int r)
{
    if (l<r)
    {
        seg[i*2]+=lazy[i];
        seg[i*2+1]+=lazy[i];
        lazy[i*2]+=lazy[i];
        lazy[i*2+1]+=lazy[i];
        lazy[i]=0;
    }
}
void upd(int i, int l, int r, int ql, int qr, int val)
{
//    cout << "update " << l << ' ' << r << ' ' << ql << ' ' << qr << ' ' << val << '\n';
//    push(i, l, r);
    if (ql<=l && r<=qr)
    {
        seg[i]+=val;
        lazy[i]+=val;
        return;
    }
    int mid=(l+r)/2;
    if (ql<=mid && l<=qr)
        upd(i*2, l, mid, ql, qr, val);
    if (ql<=r && mid+1<=qr)
        upd(i*2+1, mid+1, r, ql, qr, val);
    seg[i]=max(seg[i*2], seg[i*2+1])+lazy[i];
//    cout << "seg[" << i << "] = " << seg[i] << " after considering " << seg[i*2] << " and " << seg[i*2+1] << '\n';
}
vector<int> countScans(vector<int> a, vector<int> x, vector<int> y)
{
    int n=a.size(), m=x.size();
    for (int i=0; i<n; i++)
        vec.push_back({a[i], i});
    for (int i=0; i<m; i++)
        vec.push_back({y[i], x[i]});
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    int sz=vec.size();
//    for (int i=0; i<sz; i++)
//        cout << vec[i].first << ' ' << vec[i].second << '\n';
    for (int i=0; i<n; i++)
    {
        int ind=lower_bound(vec.begin(), vec.end(), make_pair(a[i], i))-vec.begin();
        int ind2=lower_bound(vec.begin(), vec.end(), make_pair(a[i], 0))-vec.begin();
        upd(1, 0, sz-1, ind, ind, i+1);
        upd(1, 0, sz-1, ind2, sz-1, -1);
    }
//    cout << "seg: " << '\n';
//    for (int i=8; i<=15; i++)
//        cout << seg[i] << ' ';
//    cout << '\n';
//    for (int j=1; j<=15; j++)
//            cout << j << ' ' << seg[j] << ' ' << lazy[j] << '\n';
    for (int i=0; i<m; i++)
    {
//        cout << "i=" << i << '\n';
        int ind=lower_bound(vec.begin(), vec.end(), make_pair(a[x[i]], x[i]))-vec.begin();
        int ind2=lower_bound(vec.begin(), vec.end(), make_pair(a[x[i]], 0))-vec.begin();
        upd(1, 0, sz-1, ind, ind, -x[i]-1);
        upd(1, 0, sz-1, ind2, sz-1, 1);
        a[x[i]]=y[i];
        ind=lower_bound(vec.begin(), vec.end(), make_pair(a[x[i]], x[i]))-vec.begin();
        ind2=lower_bound(vec.begin(), vec.end(), make_pair(a[x[i]], 0))-vec.begin();
        upd(1, 0, sz-1, ind, ind, x[i]+1);
        upd(1, 0, sz-1, ind2, sz-1, -1);
        ans.push_back(seg[1]);
//        for (int j=1; j<=15; j++)
//            cout << j << ' ' << seg[j] << ' ' << lazy[j] << '\n';
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
15 Correct 4 ms 468 KB Output is correct
16 Correct 4 ms 468 KB Output is correct
17 Correct 4 ms 468 KB Output is correct
18 Correct 4 ms 496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
15 Correct 4 ms 468 KB Output is correct
16 Correct 4 ms 468 KB Output is correct
17 Correct 4 ms 468 KB Output is correct
18 Correct 4 ms 496 KB Output is correct
19 Correct 14 ms 988 KB Output is correct
20 Correct 17 ms 980 KB Output is correct
21 Correct 16 ms 980 KB Output is correct
22 Correct 16 ms 1060 KB Output is correct
23 Correct 14 ms 980 KB Output is correct
24 Correct 15 ms 1024 KB Output is correct
25 Correct 16 ms 1024 KB Output is correct
26 Correct 15 ms 1020 KB Output is correct
27 Correct 15 ms 1028 KB Output is correct
28 Correct 16 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1452 KB Output is correct
2 Correct 64 ms 2700 KB Output is correct
3 Correct 115 ms 4720 KB Output is correct
4 Correct 121 ms 4708 KB Output is correct
5 Correct 113 ms 4676 KB Output is correct
6 Correct 109 ms 4720 KB Output is correct
7 Correct 118 ms 4664 KB Output is correct
8 Correct 129 ms 4692 KB Output is correct
9 Correct 110 ms 4708 KB Output is correct
10 Correct 81 ms 3640 KB Output is correct
11 Correct 84 ms 3588 KB Output is correct
12 Correct 84 ms 3608 KB Output is correct
13 Correct 84 ms 3648 KB Output is correct
14 Correct 87 ms 3664 KB Output is correct
15 Correct 81 ms 3572 KB Output is correct
16 Correct 89 ms 3592 KB Output is correct
17 Correct 89 ms 3592 KB Output is correct
18 Correct 98 ms 3648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
15 Correct 4 ms 468 KB Output is correct
16 Correct 4 ms 468 KB Output is correct
17 Correct 4 ms 468 KB Output is correct
18 Correct 4 ms 496 KB Output is correct
19 Correct 14 ms 988 KB Output is correct
20 Correct 17 ms 980 KB Output is correct
21 Correct 16 ms 980 KB Output is correct
22 Correct 16 ms 1060 KB Output is correct
23 Correct 14 ms 980 KB Output is correct
24 Correct 15 ms 1024 KB Output is correct
25 Correct 16 ms 1024 KB Output is correct
26 Correct 15 ms 1020 KB Output is correct
27 Correct 15 ms 1028 KB Output is correct
28 Correct 16 ms 980 KB Output is correct
29 Correct 21 ms 1452 KB Output is correct
30 Correct 64 ms 2700 KB Output is correct
31 Correct 115 ms 4720 KB Output is correct
32 Correct 121 ms 4708 KB Output is correct
33 Correct 113 ms 4676 KB Output is correct
34 Correct 109 ms 4720 KB Output is correct
35 Correct 118 ms 4664 KB Output is correct
36 Correct 129 ms 4692 KB Output is correct
37 Correct 110 ms 4708 KB Output is correct
38 Correct 81 ms 3640 KB Output is correct
39 Correct 84 ms 3588 KB Output is correct
40 Correct 84 ms 3608 KB Output is correct
41 Correct 84 ms 3648 KB Output is correct
42 Correct 87 ms 3664 KB Output is correct
43 Correct 81 ms 3572 KB Output is correct
44 Correct 89 ms 3592 KB Output is correct
45 Correct 89 ms 3592 KB Output is correct
46 Correct 98 ms 3648 KB Output is correct
47 Correct 438 ms 15776 KB Output is correct
48 Correct 1672 ms 38676 KB Output is correct
49 Correct 1998 ms 53184 KB Output is correct
50 Correct 1886 ms 53100 KB Output is correct
51 Correct 1888 ms 53188 KB Output is correct
52 Correct 1893 ms 53152 KB Output is correct
53 Correct 1805 ms 53180 KB Output is correct
54 Correct 1758 ms 53424 KB Output is correct
55 Correct 1780 ms 53292 KB Output is correct
56 Correct 1739 ms 53380 KB Output is correct
57 Correct 1896 ms 53576 KB Output is correct
58 Correct 1784 ms 53372 KB Output is correct
59 Correct 1532 ms 52132 KB Output is correct
60 Correct 1614 ms 52192 KB Output is correct
61 Correct 1559 ms 52004 KB Output is correct
62 Correct 1468 ms 52052 KB Output is correct
63 Correct 1464 ms 51820 KB Output is correct
64 Correct 1498 ms 51800 KB Output is correct
65 Correct 1413 ms 51676 KB Output is correct
66 Correct 1366 ms 51836 KB Output is correct
67 Correct 1343 ms 51784 KB Output is correct