Submission #374791

# Submission time Handle Problem Language Result Execution time Memory
374791 2021-03-08T07:36:07 Z valerikk Bubble Sort 2 (JOI18_bubblesort2) C++17
60 / 100
9000 ms 30372 KB
/*
    doing virtual contest
    start: 10:00
    finish: 14:00
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

vector<int> countScans(vector<int> a, vector<int> x, vector<int> v) {
    int n = (int)a.size(), q = (int)x.size();
    vector<int> all;
    for (int i = 0; i < n; ++i) all.push_back(a[i]);
    for (int i = 0; i < q; ++i) all.push_back(v[i]);
    sort(all.begin(), all.end());
    all.erase(unique(all.begin(), all.end()), all.end());
    for (int i = 0; i < n; ++i) a[i] = lower_bound(all.begin(), all.end(), a[i]) - all.begin();
    for (int i = 0; i < q; ++i) v[i] = lower_bound(all.begin(), all.end(), v[i]) - all.begin();
    vector<set<int>> st((int)all.size());
    for (int i = 0; i < n; ++i) st[a[i]].insert(i);
    vector<int> s;
    for (int j = 0; j < q; ++j) {
        st[a[x[j]]].erase(x[j]);
        a[x[j]] = v[j];
        st[v[j]].insert(x[j]);
        int cnt = 0, ans = 0;
        for (int i = 0; i < (int)all.size(); ++i) {
            if (!st[i].empty()) ans = max(ans, *st[i].rbegin() - cnt - (int)st[i].size() + 1);
            cnt += (int)st[i].size();
        }
        s.push_back(ans);
    }
    return s;
}

#ifdef LOCAL
int main() {
    freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    vector<int> x(q), v(q);
    for (int i = 0; i < q; ++i) cin >> x[i] >> v[i];
    auto s = countScans(a, x, v);
    for (int i = 0; i < q; ++i) cout << s[i] << '\n';
    return 0;
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 4 ms 364 KB Output is correct
2 Correct 10 ms 492 KB Output is correct
3 Correct 52 ms 748 KB Output is correct
4 Correct 53 ms 748 KB Output is correct
5 Correct 51 ms 768 KB Output is correct
6 Correct 45 ms 748 KB Output is correct
7 Correct 47 ms 876 KB Output is correct
8 Correct 49 ms 748 KB Output is correct
9 Correct 52 ms 748 KB Output is correct
10 Correct 36 ms 620 KB Output is correct
11 Correct 36 ms 620 KB Output is correct
12 Correct 37 ms 768 KB Output is correct
13 Correct 35 ms 620 KB Output is correct
14 Correct 35 ms 748 KB Output is correct
15 Correct 34 ms 728 KB Output is correct
16 Correct 33 ms 620 KB Output is correct
17 Correct 33 ms 620 KB Output is correct
18 Correct 38 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 364 KB Output is correct
2 Correct 10 ms 492 KB Output is correct
3 Correct 52 ms 748 KB Output is correct
4 Correct 53 ms 748 KB Output is correct
5 Correct 51 ms 768 KB Output is correct
6 Correct 45 ms 748 KB Output is correct
7 Correct 47 ms 876 KB Output is correct
8 Correct 49 ms 748 KB Output is correct
9 Correct 52 ms 748 KB Output is correct
10 Correct 36 ms 620 KB Output is correct
11 Correct 36 ms 620 KB Output is correct
12 Correct 37 ms 768 KB Output is correct
13 Correct 35 ms 620 KB Output is correct
14 Correct 35 ms 748 KB Output is correct
15 Correct 34 ms 728 KB Output is correct
16 Correct 33 ms 620 KB Output is correct
17 Correct 33 ms 620 KB Output is correct
18 Correct 38 ms 620 KB Output is correct
19 Correct 685 ms 1900 KB Output is correct
20 Correct 903 ms 2060 KB Output is correct
21 Correct 806 ms 2176 KB Output is correct
22 Correct 883 ms 1900 KB Output is correct
23 Correct 620 ms 1644 KB Output is correct
24 Correct 620 ms 1644 KB Output is correct
25 Correct 593 ms 1772 KB Output is correct
26 Correct 603 ms 1644 KB Output is correct
27 Correct 553 ms 1784 KB Output is correct
28 Correct 553 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 2028 KB Output is correct
2 Correct 53 ms 3432 KB Output is correct
3 Correct 97 ms 5220 KB Output is correct
4 Correct 101 ms 5348 KB Output is correct
5 Correct 98 ms 5348 KB Output is correct
6 Correct 92 ms 5220 KB Output is correct
7 Correct 98 ms 5368 KB Output is correct
8 Correct 95 ms 5220 KB Output is correct
9 Correct 99 ms 5220 KB Output is correct
10 Correct 74 ms 5348 KB Output is correct
11 Correct 76 ms 5348 KB Output is correct
12 Correct 74 ms 5348 KB Output is correct
13 Correct 71 ms 5348 KB Output is correct
14 Correct 69 ms 5348 KB Output is correct
15 Correct 69 ms 5316 KB Output is correct
16 Correct 64 ms 5348 KB Output is correct
17 Correct 66 ms 5348 KB Output is correct
18 Correct 64 ms 5348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 364 KB Output is correct
2 Correct 10 ms 492 KB Output is correct
3 Correct 52 ms 748 KB Output is correct
4 Correct 53 ms 748 KB Output is correct
5 Correct 51 ms 768 KB Output is correct
6 Correct 45 ms 748 KB Output is correct
7 Correct 47 ms 876 KB Output is correct
8 Correct 49 ms 748 KB Output is correct
9 Correct 52 ms 748 KB Output is correct
10 Correct 36 ms 620 KB Output is correct
11 Correct 36 ms 620 KB Output is correct
12 Correct 37 ms 768 KB Output is correct
13 Correct 35 ms 620 KB Output is correct
14 Correct 35 ms 748 KB Output is correct
15 Correct 34 ms 728 KB Output is correct
16 Correct 33 ms 620 KB Output is correct
17 Correct 33 ms 620 KB Output is correct
18 Correct 38 ms 620 KB Output is correct
19 Correct 685 ms 1900 KB Output is correct
20 Correct 903 ms 2060 KB Output is correct
21 Correct 806 ms 2176 KB Output is correct
22 Correct 883 ms 1900 KB Output is correct
23 Correct 620 ms 1644 KB Output is correct
24 Correct 620 ms 1644 KB Output is correct
25 Correct 593 ms 1772 KB Output is correct
26 Correct 603 ms 1644 KB Output is correct
27 Correct 553 ms 1784 KB Output is correct
28 Correct 553 ms 1644 KB Output is correct
29 Correct 15 ms 2028 KB Output is correct
30 Correct 53 ms 3432 KB Output is correct
31 Correct 97 ms 5220 KB Output is correct
32 Correct 101 ms 5348 KB Output is correct
33 Correct 98 ms 5348 KB Output is correct
34 Correct 92 ms 5220 KB Output is correct
35 Correct 98 ms 5368 KB Output is correct
36 Correct 95 ms 5220 KB Output is correct
37 Correct 99 ms 5220 KB Output is correct
38 Correct 74 ms 5348 KB Output is correct
39 Correct 76 ms 5348 KB Output is correct
40 Correct 74 ms 5348 KB Output is correct
41 Correct 71 ms 5348 KB Output is correct
42 Correct 69 ms 5348 KB Output is correct
43 Correct 69 ms 5316 KB Output is correct
44 Correct 64 ms 5348 KB Output is correct
45 Correct 66 ms 5348 KB Output is correct
46 Correct 64 ms 5348 KB Output is correct
47 Execution timed out 9059 ms 30372 KB Time limit exceeded
48 Halted 0 ms 0 KB -