#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
const int N = 5e5, inf = 1e9;
int n, q, a[N], x[N], v[N], seg[2][N*8], laz[N*8];
vector<int> b, ans;
vector<pair<int, int>> comp;
void pushDown(int p) {
for (int h : {p*2, p*2+1}) {
seg[0][h] += laz[p];
laz[h] += laz[p];
}
laz[p] = 0;
}
void updateSet(int idx, int x, int p=1, int l=0, int r=n+q-1) {
if (l == r) {
seg[0][p] = x;
if (x == -inf) seg[1][p] = 0;
else seg[1][p] = 1;
return;
}
pushDown(p);
int mid = (l+r) >> 1;
if (idx <= mid) updateSet(idx, x, p*2, l, mid);
else updateSet(idx, x, p*2+1, mid+1, r);
seg[0][p] = max(seg[0][p*2], seg[0][p*2+1]);
seg[1][p] = seg[1][p*2] + seg[1][p*2+1];
}
void updateSum(int idx, int x, int p=1, int l=0, int r=n+q-1) {
if (idx <= l) {
seg[0][p] += x;
laz[p] += x;
return;
}
pushDown(p);
int mid = (l+r) >> 1;
if (idx <= mid) updateSum(idx, x, p*2, l, mid);
updateSum(idx, x, p*2+1, mid+1, r);
seg[0][p] = max(seg[0][p*2], seg[0][p*2+1]);
seg[1][p] = seg[1][p*2] + seg[1][p*2+1];
}
int queryCount(int idx, int p=1, int l=0, int r=n+q-1) {
if (r <= idx) {
return seg[1][p];
}
pushDown(p);
int mid = (l+r) >> 1;
int x = queryCount(idx, p*2, l, mid);
if (mid+1 <= idx) x += queryCount(idx, p*2+1, mid+1, r);
return x;
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
n = A.size();
q = X.size();
comp.resize(n+q);
for (int i = 0; i < n; i++) {
a[i] = A[i];
comp[i] = make_pair(a[i], i);
}
for (int i = 0; i < q; i++) {
x[i] = X[i];
v[i] = V[i];
comp[n+i] = make_pair(v[i], x[i]);
}
sort(all(comp));
comp.erase(unique(all(comp)), comp.end());
b.resize(n);
for (int i = 0; i < n; i++) {
a[i] = lower_bound(all(comp), make_pair(a[i], i)) - comp.begin();
b[i] = a[i];
}
sort(all(b));
for (int i = 0; i < q; i++) {
v[i] = lower_bound(all(comp), make_pair(v[i], x[i])) - comp.begin();
}
memset(seg, 0, sizeof(seg));
memset(laz, 0, sizeof(laz));
for (int i = 0; i < n; i++) {
int idx = lower_bound(all(b), a[i]) - b.begin();
updateSet(a[i], i - idx);
}
ans.resize(q);
for (int i = 0; i < q; i++) {//cerr << i << " a" << endl;
// quito a[x[i]]
updateSum(a[x[i]], 1);
//cerr << i << " aa" << endl;
updateSet(a[x[i]], -inf);
//cerr << i << " b" << endl;
// añado v[i]
int idx = queryCount(v[i]);
updateSum(v[i], -1);
updateSet(v[i], x[i] - idx);
//cerr << i << " c" << endl;
ans[i] = seg[0][1];
//cerr << i << " d" << endl;
a[x[i]] = v[i];
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
47452 KB |
Output is correct |
2 |
Correct |
19 ms |
47328 KB |
Output is correct |
3 |
Correct |
21 ms |
47452 KB |
Output is correct |
4 |
Correct |
21 ms |
47580 KB |
Output is correct |
5 |
Correct |
21 ms |
47440 KB |
Output is correct |
6 |
Correct |
21 ms |
47452 KB |
Output is correct |
7 |
Correct |
21 ms |
47444 KB |
Output is correct |
8 |
Correct |
21 ms |
47452 KB |
Output is correct |
9 |
Correct |
22 ms |
47440 KB |
Output is correct |
10 |
Correct |
21 ms |
47520 KB |
Output is correct |
11 |
Correct |
22 ms |
47536 KB |
Output is correct |
12 |
Correct |
21 ms |
47452 KB |
Output is correct |
13 |
Correct |
22 ms |
47352 KB |
Output is correct |
14 |
Correct |
21 ms |
47380 KB |
Output is correct |
15 |
Correct |
21 ms |
47452 KB |
Output is correct |
16 |
Correct |
27 ms |
47448 KB |
Output is correct |
17 |
Correct |
21 ms |
47452 KB |
Output is correct |
18 |
Correct |
23 ms |
47500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
47452 KB |
Output is correct |
2 |
Correct |
19 ms |
47328 KB |
Output is correct |
3 |
Correct |
21 ms |
47452 KB |
Output is correct |
4 |
Correct |
21 ms |
47580 KB |
Output is correct |
5 |
Correct |
21 ms |
47440 KB |
Output is correct |
6 |
Correct |
21 ms |
47452 KB |
Output is correct |
7 |
Correct |
21 ms |
47444 KB |
Output is correct |
8 |
Correct |
21 ms |
47452 KB |
Output is correct |
9 |
Correct |
22 ms |
47440 KB |
Output is correct |
10 |
Correct |
21 ms |
47520 KB |
Output is correct |
11 |
Correct |
22 ms |
47536 KB |
Output is correct |
12 |
Correct |
21 ms |
47452 KB |
Output is correct |
13 |
Correct |
22 ms |
47352 KB |
Output is correct |
14 |
Correct |
21 ms |
47380 KB |
Output is correct |
15 |
Correct |
21 ms |
47452 KB |
Output is correct |
16 |
Correct |
27 ms |
47448 KB |
Output is correct |
17 |
Correct |
21 ms |
47452 KB |
Output is correct |
18 |
Correct |
23 ms |
47500 KB |
Output is correct |
19 |
Correct |
29 ms |
47964 KB |
Output is correct |
20 |
Correct |
31 ms |
47964 KB |
Output is correct |
21 |
Correct |
30 ms |
47964 KB |
Output is correct |
22 |
Correct |
29 ms |
47956 KB |
Output is correct |
23 |
Correct |
30 ms |
47964 KB |
Output is correct |
24 |
Correct |
29 ms |
47944 KB |
Output is correct |
25 |
Correct |
33 ms |
47992 KB |
Output is correct |
26 |
Correct |
29 ms |
47952 KB |
Output is correct |
27 |
Correct |
30 ms |
47964 KB |
Output is correct |
28 |
Correct |
29 ms |
47952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
48216 KB |
Output is correct |
2 |
Correct |
68 ms |
49536 KB |
Output is correct |
3 |
Correct |
104 ms |
50924 KB |
Output is correct |
4 |
Correct |
103 ms |
50948 KB |
Output is correct |
5 |
Correct |
98 ms |
51024 KB |
Output is correct |
6 |
Correct |
96 ms |
51024 KB |
Output is correct |
7 |
Correct |
91 ms |
50900 KB |
Output is correct |
8 |
Correct |
101 ms |
51028 KB |
Output is correct |
9 |
Correct |
100 ms |
51028 KB |
Output is correct |
10 |
Correct |
87 ms |
51032 KB |
Output is correct |
11 |
Correct |
88 ms |
51076 KB |
Output is correct |
12 |
Correct |
98 ms |
51020 KB |
Output is correct |
13 |
Correct |
84 ms |
51028 KB |
Output is correct |
14 |
Correct |
89 ms |
51024 KB |
Output is correct |
15 |
Correct |
85 ms |
51084 KB |
Output is correct |
16 |
Correct |
80 ms |
51080 KB |
Output is correct |
17 |
Correct |
82 ms |
51024 KB |
Output is correct |
18 |
Correct |
82 ms |
51080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
47452 KB |
Output is correct |
2 |
Correct |
19 ms |
47328 KB |
Output is correct |
3 |
Correct |
21 ms |
47452 KB |
Output is correct |
4 |
Correct |
21 ms |
47580 KB |
Output is correct |
5 |
Correct |
21 ms |
47440 KB |
Output is correct |
6 |
Correct |
21 ms |
47452 KB |
Output is correct |
7 |
Correct |
21 ms |
47444 KB |
Output is correct |
8 |
Correct |
21 ms |
47452 KB |
Output is correct |
9 |
Correct |
22 ms |
47440 KB |
Output is correct |
10 |
Correct |
21 ms |
47520 KB |
Output is correct |
11 |
Correct |
22 ms |
47536 KB |
Output is correct |
12 |
Correct |
21 ms |
47452 KB |
Output is correct |
13 |
Correct |
22 ms |
47352 KB |
Output is correct |
14 |
Correct |
21 ms |
47380 KB |
Output is correct |
15 |
Correct |
21 ms |
47452 KB |
Output is correct |
16 |
Correct |
27 ms |
47448 KB |
Output is correct |
17 |
Correct |
21 ms |
47452 KB |
Output is correct |
18 |
Correct |
23 ms |
47500 KB |
Output is correct |
19 |
Correct |
29 ms |
47964 KB |
Output is correct |
20 |
Correct |
31 ms |
47964 KB |
Output is correct |
21 |
Correct |
30 ms |
47964 KB |
Output is correct |
22 |
Correct |
29 ms |
47956 KB |
Output is correct |
23 |
Correct |
30 ms |
47964 KB |
Output is correct |
24 |
Correct |
29 ms |
47944 KB |
Output is correct |
25 |
Correct |
33 ms |
47992 KB |
Output is correct |
26 |
Correct |
29 ms |
47952 KB |
Output is correct |
27 |
Correct |
30 ms |
47964 KB |
Output is correct |
28 |
Correct |
29 ms |
47952 KB |
Output is correct |
29 |
Correct |
35 ms |
48216 KB |
Output is correct |
30 |
Correct |
68 ms |
49536 KB |
Output is correct |
31 |
Correct |
104 ms |
50924 KB |
Output is correct |
32 |
Correct |
103 ms |
50948 KB |
Output is correct |
33 |
Correct |
98 ms |
51024 KB |
Output is correct |
34 |
Correct |
96 ms |
51024 KB |
Output is correct |
35 |
Correct |
91 ms |
50900 KB |
Output is correct |
36 |
Correct |
101 ms |
51028 KB |
Output is correct |
37 |
Correct |
100 ms |
51028 KB |
Output is correct |
38 |
Correct |
87 ms |
51032 KB |
Output is correct |
39 |
Correct |
88 ms |
51076 KB |
Output is correct |
40 |
Correct |
98 ms |
51020 KB |
Output is correct |
41 |
Correct |
84 ms |
51028 KB |
Output is correct |
42 |
Correct |
89 ms |
51024 KB |
Output is correct |
43 |
Correct |
85 ms |
51084 KB |
Output is correct |
44 |
Correct |
80 ms |
51080 KB |
Output is correct |
45 |
Correct |
82 ms |
51024 KB |
Output is correct |
46 |
Correct |
82 ms |
51080 KB |
Output is correct |
47 |
Correct |
322 ms |
60240 KB |
Output is correct |
48 |
Correct |
1139 ms |
87696 KB |
Output is correct |
49 |
Correct |
1264 ms |
91080 KB |
Output is correct |
50 |
Correct |
1159 ms |
91084 KB |
Output is correct |
51 |
Correct |
1113 ms |
91152 KB |
Output is correct |
52 |
Correct |
1099 ms |
91220 KB |
Output is correct |
53 |
Correct |
1206 ms |
91196 KB |
Output is correct |
54 |
Correct |
1033 ms |
91132 KB |
Output is correct |
55 |
Correct |
1099 ms |
91108 KB |
Output is correct |
56 |
Correct |
997 ms |
91308 KB |
Output is correct |
57 |
Correct |
1112 ms |
91100 KB |
Output is correct |
58 |
Correct |
994 ms |
88660 KB |
Output is correct |
59 |
Correct |
906 ms |
87888 KB |
Output is correct |
60 |
Correct |
927 ms |
87956 KB |
Output is correct |
61 |
Correct |
938 ms |
87776 KB |
Output is correct |
62 |
Correct |
941 ms |
87888 KB |
Output is correct |
63 |
Correct |
937 ms |
87888 KB |
Output is correct |
64 |
Correct |
957 ms |
87892 KB |
Output is correct |
65 |
Correct |
966 ms |
89060 KB |
Output is correct |
66 |
Correct |
907 ms |
89164 KB |
Output is correct |
67 |
Correct |
946 ms |
84408 KB |
Output is correct |