Submission #894667

# Submission time Handle Problem Language Result Execution time Memory
894667 2023-12-28T16:04:47 Z lunaTu Bubble Sort 2 (JOI18_bubblesort2) C++17
38 / 100
9000 ms 2060 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#include "bubblesort2.h"
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int N = 5e4 + 1;
int A[N];
int ans[N];

int add(int n, int i, int x) {
    int mx = 0;
    for (int j = i + 1; j < n; j++) {
        if (A[j] < A[i]) ans[j]--;
        if (A[j] < x) ans[j]++;

        mx = max(mx, ans[j]);
    }

    ans[i] = 0;
    for (int j = i - 1; j >= 0; j--) {
        if (A[j] > x) ans[i]++;

        mx = max(mx, ans[j]);
    }

    A[i] = x;
    return max(mx, ans[i]);
}

vector<int> countScans(vector<int> a, vector<int> x, vector<int> v){
    int n = a.size();
    for (int i = 0; i < n; i++) {
        int w = add(n, i, a[i]);
    }

	int q = x.size();

	vector<int> answer(q);

	for (int j = 0; j < q; j++) answer[j] = add(n, x[j], v[j]);

	return answer;
}

Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:47:13: warning: unused variable 'w' [-Wunused-variable]
   47 |         int w = add(n, i, a[i]);
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 22 ms 348 KB Output is correct
4 Correct 22 ms 348 KB Output is correct
5 Correct 17 ms 348 KB Output is correct
6 Correct 10 ms 516 KB Output is correct
7 Correct 12 ms 504 KB Output is correct
8 Correct 14 ms 348 KB Output is correct
9 Correct 18 ms 604 KB Output is correct
10 Correct 13 ms 512 KB Output is correct
11 Correct 13 ms 504 KB Output is correct
12 Correct 13 ms 516 KB Output is correct
13 Correct 12 ms 348 KB Output is correct
14 Correct 12 ms 348 KB Output is correct
15 Correct 12 ms 516 KB Output is correct
16 Correct 11 ms 600 KB Output is correct
17 Correct 11 ms 348 KB Output is correct
18 Correct 10 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 22 ms 348 KB Output is correct
4 Correct 22 ms 348 KB Output is correct
5 Correct 17 ms 348 KB Output is correct
6 Correct 10 ms 516 KB Output is correct
7 Correct 12 ms 504 KB Output is correct
8 Correct 14 ms 348 KB Output is correct
9 Correct 18 ms 604 KB Output is correct
10 Correct 13 ms 512 KB Output is correct
11 Correct 13 ms 504 KB Output is correct
12 Correct 13 ms 516 KB Output is correct
13 Correct 12 ms 348 KB Output is correct
14 Correct 12 ms 348 KB Output is correct
15 Correct 12 ms 516 KB Output is correct
16 Correct 11 ms 600 KB Output is correct
17 Correct 11 ms 348 KB Output is correct
18 Correct 10 ms 348 KB Output is correct
19 Correct 284 ms 668 KB Output is correct
20 Correct 370 ms 604 KB Output is correct
21 Correct 191 ms 604 KB Output is correct
22 Correct 285 ms 664 KB Output is correct
23 Correct 203 ms 664 KB Output is correct
24 Correct 218 ms 600 KB Output is correct
25 Correct 187 ms 600 KB Output is correct
26 Correct 187 ms 600 KB Output is correct
27 Correct 166 ms 704 KB Output is correct
28 Correct 169 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1717 ms 1136 KB Output is correct
2 Correct 6667 ms 1648 KB Output is correct
3 Execution timed out 9067 ms 2060 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 22 ms 348 KB Output is correct
4 Correct 22 ms 348 KB Output is correct
5 Correct 17 ms 348 KB Output is correct
6 Correct 10 ms 516 KB Output is correct
7 Correct 12 ms 504 KB Output is correct
8 Correct 14 ms 348 KB Output is correct
9 Correct 18 ms 604 KB Output is correct
10 Correct 13 ms 512 KB Output is correct
11 Correct 13 ms 504 KB Output is correct
12 Correct 13 ms 516 KB Output is correct
13 Correct 12 ms 348 KB Output is correct
14 Correct 12 ms 348 KB Output is correct
15 Correct 12 ms 516 KB Output is correct
16 Correct 11 ms 600 KB Output is correct
17 Correct 11 ms 348 KB Output is correct
18 Correct 10 ms 348 KB Output is correct
19 Correct 284 ms 668 KB Output is correct
20 Correct 370 ms 604 KB Output is correct
21 Correct 191 ms 604 KB Output is correct
22 Correct 285 ms 664 KB Output is correct
23 Correct 203 ms 664 KB Output is correct
24 Correct 218 ms 600 KB Output is correct
25 Correct 187 ms 600 KB Output is correct
26 Correct 187 ms 600 KB Output is correct
27 Correct 166 ms 704 KB Output is correct
28 Correct 169 ms 860 KB Output is correct
29 Correct 1717 ms 1136 KB Output is correct
30 Correct 6667 ms 1648 KB Output is correct
31 Execution timed out 9067 ms 2060 KB Time limit exceeded
32 Halted 0 ms 0 KB -