#include "bubblesort2.h"
#include <bits/stdc++.h>
#define L(n) (n << 1)
#define R(n) (n << 1 | 1)
using namespace std;
int N, Q;
vector<int> ans, tmp;
map<int, int> id;
set<int, greater<int>> con[1000005];
int tree[4000005];
int lazy[4000005];
void unlazy(int n, int l, int r) {
tree[n] += lazy[n];
if(l != r) {
lazy[L(n)] += lazy[n];
lazy[R(n)] += lazy[n];
}
lazy[n] = 0;
}
void tt(int n, int l, int r) {
unlazy(n, l, r);
if(l == r) {
cout << tree[n] << " ";
return;
}
int mid = (l + r) >> 1;
tt(L(n), l, mid);
tt(R(n), mid + 1, r);
}
void update(int n, int l, int r, int ql, int qr, int val) {
// if(n == 1) cout << "up: "<< ql << " " << qr << " " << val << "\n";
unlazy(n, l, r);
if(qr < l || r < ql) return;
if(ql <= l && r <= qr) {
tree[n] += val;
if(l != r) {
lazy[L(n)] += val;
lazy[R(n)] += val;
}
return;
}
int mid = (l + r) >> 1;
update(L(n), l, mid, ql, qr, val);
update(R(n), mid + 1, r, ql, qr, val);
tree[n] = max(tree[L(n)], tree[R(n)]);
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
N = A.size(), Q = X.size();
ans.resize(Q);
tmp = A;
for(int now : V) tmp.push_back(now);
sort(tmp.begin(), tmp.end());
tmp.resize(unique(tmp.begin(), tmp.end()) - tmp.begin());
for(int i = 0; i < tmp.size(); i++) {
id[tmp[i]] = i;
// cout << tmp[i] << " ";
}
// cout << "\n";
int mac = tmp.size() - 1, val, pos;
for(int i = 0; i < N; i++) {
val = id[A[i]];
update(1, 0, mac, val, mac, -1);
if(con[val].empty()) {
update(1, 0, mac, val, val, i + 1);
}else update(1, 0, mac, val, val, i - *con[val].begin());
con[val].insert(i);
}
// cout << tree[1] << "\n";
// tt(1, 0, mac);
// cout << "\n\n";
for(int i = 0; i < Q; i++) {
pos = X[i], val = id[A[pos]];
if(con[val].size() == 1) update(1, 0, mac, val, val, -pos - 1), con[val].erase(pos);
else if(*con[val].begin() == pos) {
con[val].erase(pos);
update(1, 0, mac, val, val, *con[val].begin() - pos);
}else con[val].erase(pos);
update(1, 0, mac, val, mac, 1);
// tt(1, 0, mac);
// cout << "\n";
A[pos] = V[i];
val = id[A[pos]];
// cout << val << " " << A[pos] << "\n";
if(con[val].empty()) update(1, 0, mac, val, val, pos + 1);
else if(*con[val].begin() < pos) {
update(1, 0, mac, val, val, pos - *con[val].begin());
}
con[val].insert(pos);
update(1, 0, mac, val, mac, -1);
// tt(1, 0, mac);
// cout << "\n\n";
ans[i] = tree[1];
}
return ans;
}
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:59:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < tmp.size(); i++) {
~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
47360 KB |
Output is correct |
2 |
Correct |
34 ms |
47488 KB |
Output is correct |
3 |
Correct |
37 ms |
47744 KB |
Output is correct |
4 |
Correct |
36 ms |
47736 KB |
Output is correct |
5 |
Correct |
37 ms |
47864 KB |
Output is correct |
6 |
Correct |
38 ms |
47740 KB |
Output is correct |
7 |
Correct |
43 ms |
47864 KB |
Output is correct |
8 |
Correct |
36 ms |
47744 KB |
Output is correct |
9 |
Correct |
37 ms |
47872 KB |
Output is correct |
10 |
Correct |
36 ms |
47744 KB |
Output is correct |
11 |
Correct |
36 ms |
47864 KB |
Output is correct |
12 |
Correct |
36 ms |
47744 KB |
Output is correct |
13 |
Correct |
36 ms |
47864 KB |
Output is correct |
14 |
Correct |
36 ms |
47744 KB |
Output is correct |
15 |
Correct |
42 ms |
47744 KB |
Output is correct |
16 |
Correct |
35 ms |
47692 KB |
Output is correct |
17 |
Correct |
36 ms |
47740 KB |
Output is correct |
18 |
Correct |
41 ms |
47736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
47360 KB |
Output is correct |
2 |
Correct |
34 ms |
47488 KB |
Output is correct |
3 |
Correct |
37 ms |
47744 KB |
Output is correct |
4 |
Correct |
36 ms |
47736 KB |
Output is correct |
5 |
Correct |
37 ms |
47864 KB |
Output is correct |
6 |
Correct |
38 ms |
47740 KB |
Output is correct |
7 |
Correct |
43 ms |
47864 KB |
Output is correct |
8 |
Correct |
36 ms |
47744 KB |
Output is correct |
9 |
Correct |
37 ms |
47872 KB |
Output is correct |
10 |
Correct |
36 ms |
47744 KB |
Output is correct |
11 |
Correct |
36 ms |
47864 KB |
Output is correct |
12 |
Correct |
36 ms |
47744 KB |
Output is correct |
13 |
Correct |
36 ms |
47864 KB |
Output is correct |
14 |
Correct |
36 ms |
47744 KB |
Output is correct |
15 |
Correct |
42 ms |
47744 KB |
Output is correct |
16 |
Correct |
35 ms |
47692 KB |
Output is correct |
17 |
Correct |
36 ms |
47740 KB |
Output is correct |
18 |
Correct |
41 ms |
47736 KB |
Output is correct |
19 |
Correct |
53 ms |
49016 KB |
Output is correct |
20 |
Correct |
58 ms |
49272 KB |
Output is correct |
21 |
Correct |
58 ms |
49216 KB |
Output is correct |
22 |
Correct |
58 ms |
49272 KB |
Output is correct |
23 |
Correct |
60 ms |
49152 KB |
Output is correct |
24 |
Correct |
55 ms |
49144 KB |
Output is correct |
25 |
Correct |
56 ms |
49016 KB |
Output is correct |
26 |
Correct |
56 ms |
49016 KB |
Output is correct |
27 |
Correct |
59 ms |
49016 KB |
Output is correct |
28 |
Correct |
56 ms |
49016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
49016 KB |
Output is correct |
2 |
Correct |
87 ms |
50652 KB |
Output is correct |
3 |
Correct |
127 ms |
52276 KB |
Output is correct |
4 |
Correct |
138 ms |
52148 KB |
Output is correct |
5 |
Correct |
124 ms |
52276 KB |
Output is correct |
6 |
Correct |
127 ms |
52276 KB |
Output is correct |
7 |
Correct |
121 ms |
52148 KB |
Output is correct |
8 |
Correct |
123 ms |
52276 KB |
Output is correct |
9 |
Correct |
133 ms |
52252 KB |
Output is correct |
10 |
Correct |
110 ms |
52280 KB |
Output is correct |
11 |
Correct |
110 ms |
52276 KB |
Output is correct |
12 |
Correct |
105 ms |
52252 KB |
Output is correct |
13 |
Correct |
105 ms |
52276 KB |
Output is correct |
14 |
Correct |
107 ms |
52280 KB |
Output is correct |
15 |
Correct |
104 ms |
52276 KB |
Output is correct |
16 |
Correct |
104 ms |
52276 KB |
Output is correct |
17 |
Correct |
102 ms |
52276 KB |
Output is correct |
18 |
Correct |
104 ms |
52276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
47360 KB |
Output is correct |
2 |
Correct |
34 ms |
47488 KB |
Output is correct |
3 |
Correct |
37 ms |
47744 KB |
Output is correct |
4 |
Correct |
36 ms |
47736 KB |
Output is correct |
5 |
Correct |
37 ms |
47864 KB |
Output is correct |
6 |
Correct |
38 ms |
47740 KB |
Output is correct |
7 |
Correct |
43 ms |
47864 KB |
Output is correct |
8 |
Correct |
36 ms |
47744 KB |
Output is correct |
9 |
Correct |
37 ms |
47872 KB |
Output is correct |
10 |
Correct |
36 ms |
47744 KB |
Output is correct |
11 |
Correct |
36 ms |
47864 KB |
Output is correct |
12 |
Correct |
36 ms |
47744 KB |
Output is correct |
13 |
Correct |
36 ms |
47864 KB |
Output is correct |
14 |
Correct |
36 ms |
47744 KB |
Output is correct |
15 |
Correct |
42 ms |
47744 KB |
Output is correct |
16 |
Correct |
35 ms |
47692 KB |
Output is correct |
17 |
Correct |
36 ms |
47740 KB |
Output is correct |
18 |
Correct |
41 ms |
47736 KB |
Output is correct |
19 |
Correct |
53 ms |
49016 KB |
Output is correct |
20 |
Correct |
58 ms |
49272 KB |
Output is correct |
21 |
Correct |
58 ms |
49216 KB |
Output is correct |
22 |
Correct |
58 ms |
49272 KB |
Output is correct |
23 |
Correct |
60 ms |
49152 KB |
Output is correct |
24 |
Correct |
55 ms |
49144 KB |
Output is correct |
25 |
Correct |
56 ms |
49016 KB |
Output is correct |
26 |
Correct |
56 ms |
49016 KB |
Output is correct |
27 |
Correct |
59 ms |
49016 KB |
Output is correct |
28 |
Correct |
56 ms |
49016 KB |
Output is correct |
29 |
Correct |
56 ms |
49016 KB |
Output is correct |
30 |
Correct |
87 ms |
50652 KB |
Output is correct |
31 |
Correct |
127 ms |
52276 KB |
Output is correct |
32 |
Correct |
138 ms |
52148 KB |
Output is correct |
33 |
Correct |
124 ms |
52276 KB |
Output is correct |
34 |
Correct |
127 ms |
52276 KB |
Output is correct |
35 |
Correct |
121 ms |
52148 KB |
Output is correct |
36 |
Correct |
123 ms |
52276 KB |
Output is correct |
37 |
Correct |
133 ms |
52252 KB |
Output is correct |
38 |
Correct |
110 ms |
52280 KB |
Output is correct |
39 |
Correct |
110 ms |
52276 KB |
Output is correct |
40 |
Correct |
105 ms |
52252 KB |
Output is correct |
41 |
Correct |
105 ms |
52276 KB |
Output is correct |
42 |
Correct |
107 ms |
52280 KB |
Output is correct |
43 |
Correct |
104 ms |
52276 KB |
Output is correct |
44 |
Correct |
104 ms |
52276 KB |
Output is correct |
45 |
Correct |
102 ms |
52276 KB |
Output is correct |
46 |
Correct |
104 ms |
52276 KB |
Output is correct |
47 |
Correct |
1067 ms |
86448 KB |
Output is correct |
48 |
Correct |
4238 ms |
156992 KB |
Output is correct |
49 |
Correct |
4730 ms |
166732 KB |
Output is correct |
50 |
Correct |
4520 ms |
166660 KB |
Output is correct |
51 |
Correct |
4637 ms |
166692 KB |
Output is correct |
52 |
Correct |
4915 ms |
166768 KB |
Output is correct |
53 |
Correct |
4543 ms |
166844 KB |
Output is correct |
54 |
Correct |
4132 ms |
166672 KB |
Output is correct |
55 |
Correct |
4639 ms |
166908 KB |
Output is correct |
56 |
Correct |
4266 ms |
166960 KB |
Output is correct |
57 |
Correct |
4437 ms |
166868 KB |
Output is correct |
58 |
Correct |
4567 ms |
166740 KB |
Output is correct |
59 |
Correct |
3824 ms |
159832 KB |
Output is correct |
60 |
Correct |
3817 ms |
159868 KB |
Output is correct |
61 |
Correct |
3916 ms |
159856 KB |
Output is correct |
62 |
Correct |
3425 ms |
156596 KB |
Output is correct |
63 |
Correct |
3548 ms |
156772 KB |
Output is correct |
64 |
Correct |
3351 ms |
156872 KB |
Output is correct |
65 |
Correct |
3092 ms |
153564 KB |
Output is correct |
66 |
Correct |
3239 ms |
153592 KB |
Output is correct |
67 |
Correct |
3136 ms |
153684 KB |
Output is correct |