#pragma GCC optimize("O3")
#include "bubblesort2.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pii pair<int, int>
#define piii pair<pii, int>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
const int MAXN = 1e6 + 5;
const int INF = 1e9 + 7;
int cid[MAXN], B[MAXN];
int n = 0, q = 0;
oset ind;
pii arr[MAXN], C[MAXN];
int tre[MAXN * 4], lazy[MAXN * 4], updVal[MAXN];
void build(int l, int r, int k) {
lazy[k] = 0;
if (l == r) {
tre[k] = -INF;
return;
}
int m = (l + r) / 2;
build(l, m, k * 2);
build(m + 1, r, k * 2 + 1);
tre[k] = max(tre[k*2], tre[k*2+1]);
}
void upd(int l, int r, int k, int a, int b, int v, int fl) {
if (lazy[k] != 0) {
tre[k] += lazy[k];
if (l != r) {
lazy[k*2] += lazy[k];
lazy[k*2+1] += lazy[k];
}
lazy[k] = 0;
}
if (a > b)
return;
if (r < a || b < l)
return;
if (a <= l && r <= b) {
if (l == r && fl == 1)
tre[k] = v;
else
tre[k] += v;
if (l != r)
lazy[k*2] += v, lazy[k*2+1] += v;
return;
}
int m = (l + r) / 2;
upd(l, m, k*2, a, b, v, fl);
upd(m + 1, r, k*2+1, a, b, v, fl);
tre[k] = max(tre[k*2], tre[k*2+1]);
}
vi countScans(vi A, vi X, vi V)
{
vi ans;
n = A.size(), q = X.size();
for (int i = 0; i < n; i++)
{
B[i] = A[i];
arr[i] = {A[i], i};
C[i] = arr[i];
ind.insert({A[i], i});
cid[i] = i;
}
sort(cid, cid + n, [&A](int l, int r) -> bool {
if (A[l] == A[r])
return l < r;
return A[l] < A[r];
});
for (int i = 0; i < q; i++) {
ind.erase({B[X[i]], X[i]});
B[X[i]] = V[i];
ind.insert({B[X[i]], X[i]});
int r = ind.order_of_key({B[X[i]], X[i]});
arr[i + n] = {B[X[i]], X[i]};
updVal[i + n] = X[i] - r;
}
for (int i = 0; i < n; i++) B[i] = A[i];
sort(arr, arr + n + q);
build(0, n + q - 1, 1);
sort(C, C + n);
for (int i = 0; i < n; i++) {
int l = lower_bound(arr, arr + n + q, C[i]) - arr;
upd(0, n + q - 1, 1, l, l, cid[i] - i, 1);
}
for (int i = n; i < n + q; i++) {
int l = lower_bound(arr, arr + n + q, mp(B[X[i-n]], X[i-n])) - arr;
B[X[i-n]] = V[i-n];
int r = lower_bound(arr, arr + n + q, mp(B[X[i-n]], X[i-n])) - arr;
upd(0, n + q - 1, 1, l, l, -INF, 1);
upd(0, n + q - 1, 1, r, r, updVal[i], 1);
if (l < r) upd(0, n + q - 1, 1, l + 1, r - 1, 1, 0);
else upd(0, n + q - 1, 1, r + 1, l - 1, -1, 0);
ans.pb(tre[1]);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
9 ms |
768 KB |
Output is correct |
4 |
Correct |
11 ms |
768 KB |
Output is correct |
5 |
Correct |
7 ms |
640 KB |
Output is correct |
6 |
Correct |
8 ms |
768 KB |
Output is correct |
7 |
Correct |
10 ms |
768 KB |
Output is correct |
8 |
Correct |
8 ms |
768 KB |
Output is correct |
9 |
Correct |
8 ms |
768 KB |
Output is correct |
10 |
Correct |
8 ms |
768 KB |
Output is correct |
11 |
Correct |
11 ms |
768 KB |
Output is correct |
12 |
Correct |
8 ms |
768 KB |
Output is correct |
13 |
Correct |
10 ms |
768 KB |
Output is correct |
14 |
Correct |
9 ms |
896 KB |
Output is correct |
15 |
Correct |
9 ms |
768 KB |
Output is correct |
16 |
Correct |
9 ms |
768 KB |
Output is correct |
17 |
Correct |
9 ms |
768 KB |
Output is correct |
18 |
Correct |
10 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
9 ms |
768 KB |
Output is correct |
4 |
Correct |
11 ms |
768 KB |
Output is correct |
5 |
Correct |
7 ms |
640 KB |
Output is correct |
6 |
Correct |
8 ms |
768 KB |
Output is correct |
7 |
Correct |
10 ms |
768 KB |
Output is correct |
8 |
Correct |
8 ms |
768 KB |
Output is correct |
9 |
Correct |
8 ms |
768 KB |
Output is correct |
10 |
Correct |
8 ms |
768 KB |
Output is correct |
11 |
Correct |
11 ms |
768 KB |
Output is correct |
12 |
Correct |
8 ms |
768 KB |
Output is correct |
13 |
Correct |
10 ms |
768 KB |
Output is correct |
14 |
Correct |
9 ms |
896 KB |
Output is correct |
15 |
Correct |
9 ms |
768 KB |
Output is correct |
16 |
Correct |
9 ms |
768 KB |
Output is correct |
17 |
Correct |
9 ms |
768 KB |
Output is correct |
18 |
Correct |
10 ms |
768 KB |
Output is correct |
19 |
Correct |
32 ms |
1764 KB |
Output is correct |
20 |
Correct |
30 ms |
1864 KB |
Output is correct |
21 |
Correct |
28 ms |
1912 KB |
Output is correct |
22 |
Correct |
32 ms |
1912 KB |
Output is correct |
23 |
Correct |
42 ms |
1912 KB |
Output is correct |
24 |
Correct |
30 ms |
1912 KB |
Output is correct |
25 |
Correct |
31 ms |
1852 KB |
Output is correct |
26 |
Correct |
38 ms |
1892 KB |
Output is correct |
27 |
Correct |
27 ms |
1912 KB |
Output is correct |
28 |
Correct |
28 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
3708 KB |
Output is correct |
2 |
Correct |
123 ms |
6392 KB |
Output is correct |
3 |
Correct |
266 ms |
9468 KB |
Output is correct |
4 |
Correct |
258 ms |
9528 KB |
Output is correct |
5 |
Correct |
229 ms |
9464 KB |
Output is correct |
6 |
Correct |
268 ms |
9468 KB |
Output is correct |
7 |
Correct |
268 ms |
9668 KB |
Output is correct |
8 |
Correct |
289 ms |
9488 KB |
Output is correct |
9 |
Correct |
263 ms |
9500 KB |
Output is correct |
10 |
Correct |
227 ms |
9604 KB |
Output is correct |
11 |
Correct |
218 ms |
9772 KB |
Output is correct |
12 |
Correct |
208 ms |
9632 KB |
Output is correct |
13 |
Correct |
204 ms |
9556 KB |
Output is correct |
14 |
Correct |
220 ms |
9676 KB |
Output is correct |
15 |
Correct |
235 ms |
9592 KB |
Output is correct |
16 |
Correct |
196 ms |
9592 KB |
Output is correct |
17 |
Correct |
199 ms |
9464 KB |
Output is correct |
18 |
Correct |
197 ms |
9592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
9 ms |
768 KB |
Output is correct |
4 |
Correct |
11 ms |
768 KB |
Output is correct |
5 |
Correct |
7 ms |
640 KB |
Output is correct |
6 |
Correct |
8 ms |
768 KB |
Output is correct |
7 |
Correct |
10 ms |
768 KB |
Output is correct |
8 |
Correct |
8 ms |
768 KB |
Output is correct |
9 |
Correct |
8 ms |
768 KB |
Output is correct |
10 |
Correct |
8 ms |
768 KB |
Output is correct |
11 |
Correct |
11 ms |
768 KB |
Output is correct |
12 |
Correct |
8 ms |
768 KB |
Output is correct |
13 |
Correct |
10 ms |
768 KB |
Output is correct |
14 |
Correct |
9 ms |
896 KB |
Output is correct |
15 |
Correct |
9 ms |
768 KB |
Output is correct |
16 |
Correct |
9 ms |
768 KB |
Output is correct |
17 |
Correct |
9 ms |
768 KB |
Output is correct |
18 |
Correct |
10 ms |
768 KB |
Output is correct |
19 |
Correct |
32 ms |
1764 KB |
Output is correct |
20 |
Correct |
30 ms |
1864 KB |
Output is correct |
21 |
Correct |
28 ms |
1912 KB |
Output is correct |
22 |
Correct |
32 ms |
1912 KB |
Output is correct |
23 |
Correct |
42 ms |
1912 KB |
Output is correct |
24 |
Correct |
30 ms |
1912 KB |
Output is correct |
25 |
Correct |
31 ms |
1852 KB |
Output is correct |
26 |
Correct |
38 ms |
1892 KB |
Output is correct |
27 |
Correct |
27 ms |
1912 KB |
Output is correct |
28 |
Correct |
28 ms |
1920 KB |
Output is correct |
29 |
Correct |
41 ms |
3708 KB |
Output is correct |
30 |
Correct |
123 ms |
6392 KB |
Output is correct |
31 |
Correct |
266 ms |
9468 KB |
Output is correct |
32 |
Correct |
258 ms |
9528 KB |
Output is correct |
33 |
Correct |
229 ms |
9464 KB |
Output is correct |
34 |
Correct |
268 ms |
9468 KB |
Output is correct |
35 |
Correct |
268 ms |
9668 KB |
Output is correct |
36 |
Correct |
289 ms |
9488 KB |
Output is correct |
37 |
Correct |
263 ms |
9500 KB |
Output is correct |
38 |
Correct |
227 ms |
9604 KB |
Output is correct |
39 |
Correct |
218 ms |
9772 KB |
Output is correct |
40 |
Correct |
208 ms |
9632 KB |
Output is correct |
41 |
Correct |
204 ms |
9556 KB |
Output is correct |
42 |
Correct |
220 ms |
9676 KB |
Output is correct |
43 |
Correct |
235 ms |
9592 KB |
Output is correct |
44 |
Correct |
196 ms |
9592 KB |
Output is correct |
45 |
Correct |
199 ms |
9464 KB |
Output is correct |
46 |
Correct |
197 ms |
9592 KB |
Output is correct |
47 |
Correct |
1206 ms |
32184 KB |
Output is correct |
48 |
Correct |
5066 ms |
84464 KB |
Output is correct |
49 |
Correct |
5656 ms |
92716 KB |
Output is correct |
50 |
Correct |
5481 ms |
92632 KB |
Output is correct |
51 |
Correct |
5504 ms |
92676 KB |
Output is correct |
52 |
Correct |
5577 ms |
92736 KB |
Output is correct |
53 |
Correct |
5032 ms |
92756 KB |
Output is correct |
54 |
Correct |
5307 ms |
92884 KB |
Output is correct |
55 |
Correct |
4984 ms |
92884 KB |
Output is correct |
56 |
Correct |
4547 ms |
92848 KB |
Output is correct |
57 |
Correct |
5199 ms |
92872 KB |
Output is correct |
58 |
Correct |
5154 ms |
92760 KB |
Output is correct |
59 |
Correct |
4244 ms |
91504 KB |
Output is correct |
60 |
Correct |
4316 ms |
91440 KB |
Output is correct |
61 |
Correct |
4019 ms |
91492 KB |
Output is correct |
62 |
Correct |
3978 ms |
91196 KB |
Output is correct |
63 |
Correct |
3803 ms |
91260 KB |
Output is correct |
64 |
Correct |
4113 ms |
91304 KB |
Output is correct |
65 |
Correct |
3610 ms |
91224 KB |
Output is correct |
66 |
Correct |
3586 ms |
91208 KB |
Output is correct |
67 |
Correct |
3689 ms |
91208 KB |
Output is correct |