#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 50;
const int INF = 1 << 25;
int mx[4 * N], delta[4 * N];
vector<pair<int, int>> D;
void add(int v, int l, int r, int L, int R, int d) {
if (R <= L || R <= l || r <= L) return;
if (l >= L && r <= R) {
mx[v] += d;
delta[v] += d;
return;
}
int m = l + r >> 1;
add(v<<1, l, m, L, R, d);
add(v<<1|1, m, r, L, R, d);
mx[v] = max(mx[v<<1], mx[v<<1|1]) + delta[v];
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
int Q = X.size();
int n = A.size();
for (int i = 0; i < n; i++)
D.emplace_back(A[i], i);
for (int i = 0; i < Q; i++)
D.emplace_back(V[i], X[i]);
sort(D.begin(), D.end());
D.resize(unique(D.begin(), D.end()) - D.begin());
for (int i = 0; i < A.size(); i++) {
int ind = lower_bound(D.begin(), D.end(), make_pair(A[i], i)) - D.begin();
add(1, 0, D.size(), ind, ind + 1, +i);
add(1, 0, D.size(), ind + 1, D.size(), -1);
}
vector<int> answer(Q);
for (int i = 0; i < Q; i++) {
int ind = lower_bound(D.begin(), D.end(), make_pair(A[X[i]], X[i])) - D.begin();
add(1, 0, D.size(), ind, ind + 1, -X[i]);
add(1, 0, D.size(), ind + 1, D.size(), +1);
ind = lower_bound(D.begin(), D.end(), make_pair(V[i], X[i])) - D.begin();
add(1, 0, D.size(), ind, ind + 1, +X[i]);
add(1, 0, D.size(), ind + 1, D.size(), -1);
A[X[i]] = V[i];
answer[i] = max(mx[1], 0);
}
return answer;
}
Compilation message
bubblesort2.cpp: In function 'void add(int, int, int, int, int, int)':
bubblesort2.cpp:17:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
17 | int m = l + r >> 1;
| ~~^~~
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int i = 0; i < A.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
444 KB |
Output is correct |
6 |
Correct |
4 ms |
532 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
448 KB |
Output is correct |
9 |
Correct |
4 ms |
500 KB |
Output is correct |
10 |
Correct |
4 ms |
528 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
444 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
444 KB |
Output is correct |
6 |
Correct |
4 ms |
532 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
448 KB |
Output is correct |
9 |
Correct |
4 ms |
500 KB |
Output is correct |
10 |
Correct |
4 ms |
528 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
444 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
12 ms |
1108 KB |
Output is correct |
20 |
Correct |
19 ms |
1228 KB |
Output is correct |
21 |
Correct |
16 ms |
1224 KB |
Output is correct |
22 |
Correct |
14 ms |
1212 KB |
Output is correct |
23 |
Correct |
14 ms |
1212 KB |
Output is correct |
24 |
Correct |
15 ms |
1192 KB |
Output is correct |
25 |
Correct |
13 ms |
1108 KB |
Output is correct |
26 |
Correct |
14 ms |
1192 KB |
Output is correct |
27 |
Correct |
13 ms |
1152 KB |
Output is correct |
28 |
Correct |
14 ms |
1212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
1540 KB |
Output is correct |
2 |
Correct |
59 ms |
2960 KB |
Output is correct |
3 |
Correct |
106 ms |
5116 KB |
Output is correct |
4 |
Correct |
132 ms |
5036 KB |
Output is correct |
5 |
Correct |
106 ms |
5104 KB |
Output is correct |
6 |
Correct |
118 ms |
4996 KB |
Output is correct |
7 |
Correct |
106 ms |
5104 KB |
Output is correct |
8 |
Correct |
103 ms |
5112 KB |
Output is correct |
9 |
Correct |
103 ms |
5108 KB |
Output is correct |
10 |
Correct |
84 ms |
4032 KB |
Output is correct |
11 |
Correct |
88 ms |
4152 KB |
Output is correct |
12 |
Correct |
83 ms |
4052 KB |
Output is correct |
13 |
Correct |
83 ms |
4068 KB |
Output is correct |
14 |
Correct |
82 ms |
4072 KB |
Output is correct |
15 |
Correct |
84 ms |
4140 KB |
Output is correct |
16 |
Correct |
83 ms |
4032 KB |
Output is correct |
17 |
Correct |
81 ms |
4072 KB |
Output is correct |
18 |
Correct |
80 ms |
4068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
444 KB |
Output is correct |
6 |
Correct |
4 ms |
532 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
448 KB |
Output is correct |
9 |
Correct |
4 ms |
500 KB |
Output is correct |
10 |
Correct |
4 ms |
528 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
444 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
12 ms |
1108 KB |
Output is correct |
20 |
Correct |
19 ms |
1228 KB |
Output is correct |
21 |
Correct |
16 ms |
1224 KB |
Output is correct |
22 |
Correct |
14 ms |
1212 KB |
Output is correct |
23 |
Correct |
14 ms |
1212 KB |
Output is correct |
24 |
Correct |
15 ms |
1192 KB |
Output is correct |
25 |
Correct |
13 ms |
1108 KB |
Output is correct |
26 |
Correct |
14 ms |
1192 KB |
Output is correct |
27 |
Correct |
13 ms |
1152 KB |
Output is correct |
28 |
Correct |
14 ms |
1212 KB |
Output is correct |
29 |
Correct |
20 ms |
1540 KB |
Output is correct |
30 |
Correct |
59 ms |
2960 KB |
Output is correct |
31 |
Correct |
106 ms |
5116 KB |
Output is correct |
32 |
Correct |
132 ms |
5036 KB |
Output is correct |
33 |
Correct |
106 ms |
5104 KB |
Output is correct |
34 |
Correct |
118 ms |
4996 KB |
Output is correct |
35 |
Correct |
106 ms |
5104 KB |
Output is correct |
36 |
Correct |
103 ms |
5112 KB |
Output is correct |
37 |
Correct |
103 ms |
5108 KB |
Output is correct |
38 |
Correct |
84 ms |
4032 KB |
Output is correct |
39 |
Correct |
88 ms |
4152 KB |
Output is correct |
40 |
Correct |
83 ms |
4052 KB |
Output is correct |
41 |
Correct |
83 ms |
4068 KB |
Output is correct |
42 |
Correct |
82 ms |
4072 KB |
Output is correct |
43 |
Correct |
84 ms |
4140 KB |
Output is correct |
44 |
Correct |
83 ms |
4032 KB |
Output is correct |
45 |
Correct |
81 ms |
4072 KB |
Output is correct |
46 |
Correct |
80 ms |
4068 KB |
Output is correct |
47 |
Correct |
384 ms |
18612 KB |
Output is correct |
48 |
Runtime error |
246 ms |
50072 KB |
Execution killed with signal 11 |
49 |
Halted |
0 ms |
0 KB |
- |