#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 |
47208 KB |
Output is correct |
2 |
Correct |
19 ms |
47448 KB |
Output is correct |
3 |
Correct |
21 ms |
47452 KB |
Output is correct |
4 |
Correct |
20 ms |
47432 KB |
Output is correct |
5 |
Correct |
20 ms |
47448 KB |
Output is correct |
6 |
Correct |
21 ms |
47452 KB |
Output is correct |
7 |
Correct |
21 ms |
47452 KB |
Output is correct |
8 |
Correct |
21 ms |
47452 KB |
Output is correct |
9 |
Correct |
19 ms |
47444 KB |
Output is correct |
10 |
Correct |
22 ms |
47448 KB |
Output is correct |
11 |
Correct |
20 ms |
47464 KB |
Output is correct |
12 |
Correct |
21 ms |
47452 KB |
Output is correct |
13 |
Correct |
23 ms |
47444 KB |
Output is correct |
14 |
Correct |
21 ms |
47452 KB |
Output is correct |
15 |
Correct |
22 ms |
47508 KB |
Output is correct |
16 |
Correct |
23 ms |
47548 KB |
Output is correct |
17 |
Correct |
22 ms |
47452 KB |
Output is correct |
18 |
Correct |
21 ms |
47516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
47208 KB |
Output is correct |
2 |
Correct |
19 ms |
47448 KB |
Output is correct |
3 |
Correct |
21 ms |
47452 KB |
Output is correct |
4 |
Correct |
20 ms |
47432 KB |
Output is correct |
5 |
Correct |
20 ms |
47448 KB |
Output is correct |
6 |
Correct |
21 ms |
47452 KB |
Output is correct |
7 |
Correct |
21 ms |
47452 KB |
Output is correct |
8 |
Correct |
21 ms |
47452 KB |
Output is correct |
9 |
Correct |
19 ms |
47444 KB |
Output is correct |
10 |
Correct |
22 ms |
47448 KB |
Output is correct |
11 |
Correct |
20 ms |
47464 KB |
Output is correct |
12 |
Correct |
21 ms |
47452 KB |
Output is correct |
13 |
Correct |
23 ms |
47444 KB |
Output is correct |
14 |
Correct |
21 ms |
47452 KB |
Output is correct |
15 |
Correct |
22 ms |
47508 KB |
Output is correct |
16 |
Correct |
23 ms |
47548 KB |
Output is correct |
17 |
Correct |
22 ms |
47452 KB |
Output is correct |
18 |
Correct |
21 ms |
47516 KB |
Output is correct |
19 |
Correct |
27 ms |
47944 KB |
Output is correct |
20 |
Correct |
31 ms |
47956 KB |
Output is correct |
21 |
Correct |
28 ms |
47960 KB |
Output is correct |
22 |
Correct |
32 ms |
48072 KB |
Output is correct |
23 |
Correct |
28 ms |
48052 KB |
Output is correct |
24 |
Correct |
31 ms |
47956 KB |
Output is correct |
25 |
Correct |
27 ms |
47920 KB |
Output is correct |
26 |
Correct |
27 ms |
47964 KB |
Output is correct |
27 |
Correct |
26 ms |
47952 KB |
Output is correct |
28 |
Correct |
28 ms |
47964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
47964 KB |
Output is correct |
2 |
Correct |
58 ms |
49228 KB |
Output is correct |
3 |
Correct |
96 ms |
50872 KB |
Output is correct |
4 |
Correct |
94 ms |
50984 KB |
Output is correct |
5 |
Correct |
93 ms |
51028 KB |
Output is correct |
6 |
Correct |
93 ms |
51028 KB |
Output is correct |
7 |
Correct |
88 ms |
51028 KB |
Output is correct |
8 |
Correct |
90 ms |
50916 KB |
Output is correct |
9 |
Correct |
90 ms |
51024 KB |
Output is correct |
10 |
Correct |
79 ms |
51128 KB |
Output is correct |
11 |
Correct |
83 ms |
51024 KB |
Output is correct |
12 |
Correct |
85 ms |
51172 KB |
Output is correct |
13 |
Correct |
74 ms |
51136 KB |
Output is correct |
14 |
Correct |
74 ms |
51024 KB |
Output is correct |
15 |
Correct |
76 ms |
51028 KB |
Output is correct |
16 |
Correct |
76 ms |
51076 KB |
Output is correct |
17 |
Correct |
72 ms |
51024 KB |
Output is correct |
18 |
Correct |
82 ms |
51028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
47208 KB |
Output is correct |
2 |
Correct |
19 ms |
47448 KB |
Output is correct |
3 |
Correct |
21 ms |
47452 KB |
Output is correct |
4 |
Correct |
20 ms |
47432 KB |
Output is correct |
5 |
Correct |
20 ms |
47448 KB |
Output is correct |
6 |
Correct |
21 ms |
47452 KB |
Output is correct |
7 |
Correct |
21 ms |
47452 KB |
Output is correct |
8 |
Correct |
21 ms |
47452 KB |
Output is correct |
9 |
Correct |
19 ms |
47444 KB |
Output is correct |
10 |
Correct |
22 ms |
47448 KB |
Output is correct |
11 |
Correct |
20 ms |
47464 KB |
Output is correct |
12 |
Correct |
21 ms |
47452 KB |
Output is correct |
13 |
Correct |
23 ms |
47444 KB |
Output is correct |
14 |
Correct |
21 ms |
47452 KB |
Output is correct |
15 |
Correct |
22 ms |
47508 KB |
Output is correct |
16 |
Correct |
23 ms |
47548 KB |
Output is correct |
17 |
Correct |
22 ms |
47452 KB |
Output is correct |
18 |
Correct |
21 ms |
47516 KB |
Output is correct |
19 |
Correct |
27 ms |
47944 KB |
Output is correct |
20 |
Correct |
31 ms |
47956 KB |
Output is correct |
21 |
Correct |
28 ms |
47960 KB |
Output is correct |
22 |
Correct |
32 ms |
48072 KB |
Output is correct |
23 |
Correct |
28 ms |
48052 KB |
Output is correct |
24 |
Correct |
31 ms |
47956 KB |
Output is correct |
25 |
Correct |
27 ms |
47920 KB |
Output is correct |
26 |
Correct |
27 ms |
47964 KB |
Output is correct |
27 |
Correct |
26 ms |
47952 KB |
Output is correct |
28 |
Correct |
28 ms |
47964 KB |
Output is correct |
29 |
Correct |
32 ms |
47964 KB |
Output is correct |
30 |
Correct |
58 ms |
49228 KB |
Output is correct |
31 |
Correct |
96 ms |
50872 KB |
Output is correct |
32 |
Correct |
94 ms |
50984 KB |
Output is correct |
33 |
Correct |
93 ms |
51028 KB |
Output is correct |
34 |
Correct |
93 ms |
51028 KB |
Output is correct |
35 |
Correct |
88 ms |
51028 KB |
Output is correct |
36 |
Correct |
90 ms |
50916 KB |
Output is correct |
37 |
Correct |
90 ms |
51024 KB |
Output is correct |
38 |
Correct |
79 ms |
51128 KB |
Output is correct |
39 |
Correct |
83 ms |
51024 KB |
Output is correct |
40 |
Correct |
85 ms |
51172 KB |
Output is correct |
41 |
Correct |
74 ms |
51136 KB |
Output is correct |
42 |
Correct |
74 ms |
51024 KB |
Output is correct |
43 |
Correct |
76 ms |
51028 KB |
Output is correct |
44 |
Correct |
76 ms |
51076 KB |
Output is correct |
45 |
Correct |
72 ms |
51024 KB |
Output is correct |
46 |
Correct |
82 ms |
51028 KB |
Output is correct |
47 |
Correct |
286 ms |
60104 KB |
Output is correct |
48 |
Correct |
1068 ms |
88400 KB |
Output is correct |
49 |
Correct |
1107 ms |
91468 KB |
Output is correct |
50 |
Correct |
1281 ms |
91456 KB |
Output is correct |
51 |
Correct |
1165 ms |
91436 KB |
Output is correct |
52 |
Correct |
1124 ms |
91472 KB |
Output is correct |
53 |
Correct |
1169 ms |
91472 KB |
Output is correct |
54 |
Correct |
1006 ms |
91596 KB |
Output is correct |
55 |
Correct |
1161 ms |
91724 KB |
Output is correct |
56 |
Correct |
1036 ms |
91736 KB |
Output is correct |
57 |
Correct |
1112 ms |
91620 KB |
Output is correct |
58 |
Correct |
981 ms |
91728 KB |
Output is correct |
59 |
Correct |
979 ms |
90400 KB |
Output is correct |
60 |
Correct |
960 ms |
90408 KB |
Output is correct |
61 |
Correct |
979 ms |
90196 KB |
Output is correct |
62 |
Correct |
918 ms |
90196 KB |
Output is correct |
63 |
Correct |
988 ms |
90196 KB |
Output is correct |
64 |
Correct |
907 ms |
90192 KB |
Output is correct |
65 |
Correct |
885 ms |
90200 KB |
Output is correct |
66 |
Correct |
911 ms |
90072 KB |
Output is correct |
67 |
Correct |
903 ms |
89960 KB |
Output is correct |