Submission #894681

# Submission time Handle Problem Language Result Execution time Memory
894681 2023-12-28T17:04:20 Z lunaTu Bubble Sort 2 (JOI18_bubblesort2) C++17
60 / 100
1134 ms 44932 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#include "bubblesort2.h"
typedef long long ll;
using namespace std;

const int N = 5e4 + 1;
int A[N];
set<int> d[N];
set<int> s;

int add(int n, int i, int x) {
    d[A[i]].erase(i);
    if (d[A[i]].empty()) s.erase(A[i]);

    d[x].insert(i);
    s.insert(x);

    int mx = 0, sum = 0, p = -1;
    for (auto e : s) {
        int j = *d[e].rbegin();

        sum += d[e].size();
        if (j > p) {
            mx = max(mx, j + 1 - sum);
            p = j;
        }
    }

    A[i] = x;
    //cout << mx << endl;
    return mx;
}

vector<int> countScans(vector<int> a, vector<int> x, vector<int> v) {
    int n = a.size(), q = x.size();

    vector<int> b(n + q);
    for (int i = 0; i < n; i++) {
        b[i] = a[i];
    }
    for (int i = n; i < n + q; i ++) {
        b[i] = v[i - n];
    }
    sort(all(b));

    int cnt = 1;
    map<int, int> r;
    for (auto e : b) {
        if (!r[e]) r[e] = cnt++;
    }

    for (int i = 0; i < n; i++) {
        int e = r[a[i]];
        s.insert(e);
        d[e].insert(i);
        A[i] = e;
    }

	vector<int> answer(q);

	for (int j = 0; j < q; j++) {
        answer[j] = add(n, x[j], r[v[j]]);
        //cout << answer[j] << endl;
	}

	return answer;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2908 KB Output is correct
2 Correct 7 ms 2956 KB Output is correct
3 Correct 37 ms 3268 KB Output is correct
4 Correct 39 ms 3164 KB Output is correct
5 Correct 39 ms 3164 KB Output is correct
6 Correct 36 ms 3164 KB Output is correct
7 Correct 36 ms 3160 KB Output is correct
8 Correct 40 ms 3164 KB Output is correct
9 Correct 38 ms 3160 KB Output is correct
10 Correct 31 ms 3160 KB Output is correct
11 Correct 32 ms 3164 KB Output is correct
12 Correct 31 ms 3164 KB Output is correct
13 Correct 38 ms 3412 KB Output is correct
14 Correct 30 ms 3164 KB Output is correct
15 Correct 31 ms 3164 KB Output is correct
16 Correct 31 ms 3164 KB Output is correct
17 Correct 31 ms 3232 KB Output is correct
18 Correct 30 ms 3208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2908 KB Output is correct
2 Correct 7 ms 2956 KB Output is correct
3 Correct 37 ms 3268 KB Output is correct
4 Correct 39 ms 3164 KB Output is correct
5 Correct 39 ms 3164 KB Output is correct
6 Correct 36 ms 3164 KB Output is correct
7 Correct 36 ms 3160 KB Output is correct
8 Correct 40 ms 3164 KB Output is correct
9 Correct 38 ms 3160 KB Output is correct
10 Correct 31 ms 3160 KB Output is correct
11 Correct 32 ms 3164 KB Output is correct
12 Correct 31 ms 3164 KB Output is correct
13 Correct 38 ms 3412 KB Output is correct
14 Correct 30 ms 3164 KB Output is correct
15 Correct 31 ms 3164 KB Output is correct
16 Correct 31 ms 3164 KB Output is correct
17 Correct 31 ms 3232 KB Output is correct
18 Correct 30 ms 3208 KB Output is correct
19 Correct 853 ms 4548 KB Output is correct
20 Correct 1130 ms 4944 KB Output is correct
21 Correct 1006 ms 4776 KB Output is correct
22 Correct 1134 ms 4772 KB Output is correct
23 Correct 754 ms 4648 KB Output is correct
24 Correct 769 ms 4692 KB Output is correct
25 Correct 771 ms 4440 KB Output is correct
26 Correct 781 ms 4692 KB Output is correct
27 Correct 747 ms 4544 KB Output is correct
28 Correct 767 ms 4544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 4444 KB Output is correct
2 Correct 47 ms 6176 KB Output is correct
3 Correct 74 ms 7500 KB Output is correct
4 Correct 75 ms 7604 KB Output is correct
5 Correct 83 ms 7516 KB Output is correct
6 Correct 76 ms 7448 KB Output is correct
7 Correct 81 ms 7512 KB Output is correct
8 Correct 74 ms 7508 KB Output is correct
9 Correct 76 ms 7508 KB Output is correct
10 Correct 68 ms 7740 KB Output is correct
11 Correct 65 ms 7504 KB Output is correct
12 Correct 65 ms 7516 KB Output is correct
13 Correct 65 ms 7508 KB Output is correct
14 Correct 64 ms 7516 KB Output is correct
15 Correct 74 ms 7456 KB Output is correct
16 Correct 63 ms 7600 KB Output is correct
17 Correct 63 ms 7512 KB Output is correct
18 Correct 61 ms 7516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2908 KB Output is correct
2 Correct 7 ms 2956 KB Output is correct
3 Correct 37 ms 3268 KB Output is correct
4 Correct 39 ms 3164 KB Output is correct
5 Correct 39 ms 3164 KB Output is correct
6 Correct 36 ms 3164 KB Output is correct
7 Correct 36 ms 3160 KB Output is correct
8 Correct 40 ms 3164 KB Output is correct
9 Correct 38 ms 3160 KB Output is correct
10 Correct 31 ms 3160 KB Output is correct
11 Correct 32 ms 3164 KB Output is correct
12 Correct 31 ms 3164 KB Output is correct
13 Correct 38 ms 3412 KB Output is correct
14 Correct 30 ms 3164 KB Output is correct
15 Correct 31 ms 3164 KB Output is correct
16 Correct 31 ms 3164 KB Output is correct
17 Correct 31 ms 3232 KB Output is correct
18 Correct 30 ms 3208 KB Output is correct
19 Correct 853 ms 4548 KB Output is correct
20 Correct 1130 ms 4944 KB Output is correct
21 Correct 1006 ms 4776 KB Output is correct
22 Correct 1134 ms 4772 KB Output is correct
23 Correct 754 ms 4648 KB Output is correct
24 Correct 769 ms 4692 KB Output is correct
25 Correct 771 ms 4440 KB Output is correct
26 Correct 781 ms 4692 KB Output is correct
27 Correct 747 ms 4544 KB Output is correct
28 Correct 767 ms 4544 KB Output is correct
29 Correct 11 ms 4444 KB Output is correct
30 Correct 47 ms 6176 KB Output is correct
31 Correct 74 ms 7500 KB Output is correct
32 Correct 75 ms 7604 KB Output is correct
33 Correct 83 ms 7516 KB Output is correct
34 Correct 76 ms 7448 KB Output is correct
35 Correct 81 ms 7512 KB Output is correct
36 Correct 74 ms 7508 KB Output is correct
37 Correct 76 ms 7508 KB Output is correct
38 Correct 68 ms 7740 KB Output is correct
39 Correct 65 ms 7504 KB Output is correct
40 Correct 65 ms 7516 KB Output is correct
41 Correct 65 ms 7508 KB Output is correct
42 Correct 64 ms 7516 KB Output is correct
43 Correct 74 ms 7456 KB Output is correct
44 Correct 63 ms 7600 KB Output is correct
45 Correct 63 ms 7512 KB Output is correct
46 Correct 61 ms 7516 KB Output is correct
47 Runtime error 143 ms 44932 KB Execution killed with signal 11
48 Halted 0 ms 0 KB -