#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
/// #pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
const int MOD = 998244353;
const int nx[4] = {-1, 0, 1, 0}, ny[4] = {0, 1, 0, -1};
const int MX = 2000005;
int ST[8000005], lazy[8000005], B[8000005];
void prop(int v, int l, int r) {
if(l == r || lazy[v] == 0)
return;
lazy[v * 2] += lazy[v];
lazy[v * 2 + 1] += lazy[v];
ST[v * 2] += lazy[v];
ST[v * 2 + 1] += lazy[v];
lazy[v] = 0;
}
void update(int v, int l, int r, int lo, int hi, int val) {
if(l > hi || r < lo) return;
if(l >= lo && r <= hi) {
ST[v] += val; lazy[v] += val;
return;
}
prop(v, l, r);
update(v * 2, l, (l + r) / 2, lo, hi, val);
update(v * 2 + 1, (l + r) / 2 + 1, r, lo, hi, val);
ST[v] = max(ST[v * 2], ST[v * 2 + 1]);
}
void build(int v, int l, int r) {
if(l == r) {
ST[v] = B[l];
return;
}
build(v * 2, l, (l + r) / 2);
build(v * 2 + 1, (l + r) / 2 + 1, r);
ST[v] = max(ST[v * 2], ST[v * 2 + 1]);
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
set<pair<int, int>> S; map<pair<int, int>, int> M;
int N = A.size(), Q = X.size();
for(int l = 0; l < N; l++) S.insert({A[l], l});
for(int l = 0; l < Q; l++) S.insert({V[l], X[l]});
int cur = 0;
for(auto u : S) M[u] = cur++;
for(int l = 0; l < N; l++) A[l] = M[{A[l], l}];
for(int l = 0; l < N; l++) B[A[l]] = l;
for(int l = 0; l < Q; l++) V[l] = M[{V[l], X[l]}];
build(1, 0, MX - 1);
for(int l = 0; l < N; l++)
update(1, 0, MX - 1, A[l] + 1, MX - 1, -1);
vector<int> res(Q);
for(int l = 0; l < Q; l++) {
int i = X[l];
int u = V[l], v = A[i];
update(1, 0, MX - 1, v + 1, MX - 1, 1);
update(1, 0, MX - 1, v, v, -i);
update(1, 0, MX - 1, u + 1, MX - 1, -1);
update(1, 0, MX - 1, u, u, i);
res[l] = ST[1];
A[i] = u;
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
16952 KB |
Output is correct |
2 |
Correct |
19 ms |
16980 KB |
Output is correct |
3 |
Correct |
31 ms |
17348 KB |
Output is correct |
4 |
Correct |
37 ms |
17356 KB |
Output is correct |
5 |
Correct |
21 ms |
17364 KB |
Output is correct |
6 |
Correct |
20 ms |
17376 KB |
Output is correct |
7 |
Correct |
21 ms |
17316 KB |
Output is correct |
8 |
Correct |
31 ms |
17308 KB |
Output is correct |
9 |
Correct |
31 ms |
17388 KB |
Output is correct |
10 |
Correct |
19 ms |
17344 KB |
Output is correct |
11 |
Correct |
20 ms |
17236 KB |
Output is correct |
12 |
Correct |
22 ms |
17236 KB |
Output is correct |
13 |
Correct |
22 ms |
17272 KB |
Output is correct |
14 |
Correct |
21 ms |
17320 KB |
Output is correct |
15 |
Correct |
19 ms |
17236 KB |
Output is correct |
16 |
Correct |
23 ms |
17180 KB |
Output is correct |
17 |
Correct |
23 ms |
17228 KB |
Output is correct |
18 |
Correct |
20 ms |
17248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
16952 KB |
Output is correct |
2 |
Correct |
19 ms |
16980 KB |
Output is correct |
3 |
Correct |
31 ms |
17348 KB |
Output is correct |
4 |
Correct |
37 ms |
17356 KB |
Output is correct |
5 |
Correct |
21 ms |
17364 KB |
Output is correct |
6 |
Correct |
20 ms |
17376 KB |
Output is correct |
7 |
Correct |
21 ms |
17316 KB |
Output is correct |
8 |
Correct |
31 ms |
17308 KB |
Output is correct |
9 |
Correct |
31 ms |
17388 KB |
Output is correct |
10 |
Correct |
19 ms |
17344 KB |
Output is correct |
11 |
Correct |
20 ms |
17236 KB |
Output is correct |
12 |
Correct |
22 ms |
17236 KB |
Output is correct |
13 |
Correct |
22 ms |
17272 KB |
Output is correct |
14 |
Correct |
21 ms |
17320 KB |
Output is correct |
15 |
Correct |
19 ms |
17236 KB |
Output is correct |
16 |
Correct |
23 ms |
17180 KB |
Output is correct |
17 |
Correct |
23 ms |
17228 KB |
Output is correct |
18 |
Correct |
20 ms |
17248 KB |
Output is correct |
19 |
Correct |
39 ms |
18900 KB |
Output is correct |
20 |
Correct |
40 ms |
19156 KB |
Output is correct |
21 |
Correct |
40 ms |
19100 KB |
Output is correct |
22 |
Correct |
44 ms |
19104 KB |
Output is correct |
23 |
Correct |
39 ms |
18992 KB |
Output is correct |
24 |
Correct |
45 ms |
18816 KB |
Output is correct |
25 |
Correct |
46 ms |
18768 KB |
Output is correct |
26 |
Correct |
47 ms |
18744 KB |
Output is correct |
27 |
Correct |
41 ms |
18580 KB |
Output is correct |
28 |
Correct |
44 ms |
18648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
20760 KB |
Output is correct |
2 |
Correct |
131 ms |
25540 KB |
Output is correct |
3 |
Correct |
225 ms |
30580 KB |
Output is correct |
4 |
Correct |
211 ms |
30592 KB |
Output is correct |
5 |
Correct |
270 ms |
30436 KB |
Output is correct |
6 |
Correct |
209 ms |
30272 KB |
Output is correct |
7 |
Correct |
225 ms |
30204 KB |
Output is correct |
8 |
Correct |
218 ms |
30352 KB |
Output is correct |
9 |
Correct |
243 ms |
30360 KB |
Output is correct |
10 |
Correct |
146 ms |
25068 KB |
Output is correct |
11 |
Correct |
157 ms |
25176 KB |
Output is correct |
12 |
Correct |
152 ms |
25180 KB |
Output is correct |
13 |
Correct |
173 ms |
25220 KB |
Output is correct |
14 |
Correct |
146 ms |
25132 KB |
Output is correct |
15 |
Correct |
137 ms |
25164 KB |
Output is correct |
16 |
Correct |
137 ms |
25208 KB |
Output is correct |
17 |
Correct |
137 ms |
25184 KB |
Output is correct |
18 |
Correct |
138 ms |
25184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
16952 KB |
Output is correct |
2 |
Correct |
19 ms |
16980 KB |
Output is correct |
3 |
Correct |
31 ms |
17348 KB |
Output is correct |
4 |
Correct |
37 ms |
17356 KB |
Output is correct |
5 |
Correct |
21 ms |
17364 KB |
Output is correct |
6 |
Correct |
20 ms |
17376 KB |
Output is correct |
7 |
Correct |
21 ms |
17316 KB |
Output is correct |
8 |
Correct |
31 ms |
17308 KB |
Output is correct |
9 |
Correct |
31 ms |
17388 KB |
Output is correct |
10 |
Correct |
19 ms |
17344 KB |
Output is correct |
11 |
Correct |
20 ms |
17236 KB |
Output is correct |
12 |
Correct |
22 ms |
17236 KB |
Output is correct |
13 |
Correct |
22 ms |
17272 KB |
Output is correct |
14 |
Correct |
21 ms |
17320 KB |
Output is correct |
15 |
Correct |
19 ms |
17236 KB |
Output is correct |
16 |
Correct |
23 ms |
17180 KB |
Output is correct |
17 |
Correct |
23 ms |
17228 KB |
Output is correct |
18 |
Correct |
20 ms |
17248 KB |
Output is correct |
19 |
Correct |
39 ms |
18900 KB |
Output is correct |
20 |
Correct |
40 ms |
19156 KB |
Output is correct |
21 |
Correct |
40 ms |
19100 KB |
Output is correct |
22 |
Correct |
44 ms |
19104 KB |
Output is correct |
23 |
Correct |
39 ms |
18992 KB |
Output is correct |
24 |
Correct |
45 ms |
18816 KB |
Output is correct |
25 |
Correct |
46 ms |
18768 KB |
Output is correct |
26 |
Correct |
47 ms |
18744 KB |
Output is correct |
27 |
Correct |
41 ms |
18580 KB |
Output is correct |
28 |
Correct |
44 ms |
18648 KB |
Output is correct |
29 |
Correct |
62 ms |
20760 KB |
Output is correct |
30 |
Correct |
131 ms |
25540 KB |
Output is correct |
31 |
Correct |
225 ms |
30580 KB |
Output is correct |
32 |
Correct |
211 ms |
30592 KB |
Output is correct |
33 |
Correct |
270 ms |
30436 KB |
Output is correct |
34 |
Correct |
209 ms |
30272 KB |
Output is correct |
35 |
Correct |
225 ms |
30204 KB |
Output is correct |
36 |
Correct |
218 ms |
30352 KB |
Output is correct |
37 |
Correct |
243 ms |
30360 KB |
Output is correct |
38 |
Correct |
146 ms |
25068 KB |
Output is correct |
39 |
Correct |
157 ms |
25176 KB |
Output is correct |
40 |
Correct |
152 ms |
25180 KB |
Output is correct |
41 |
Correct |
173 ms |
25220 KB |
Output is correct |
42 |
Correct |
146 ms |
25132 KB |
Output is correct |
43 |
Correct |
137 ms |
25164 KB |
Output is correct |
44 |
Correct |
137 ms |
25208 KB |
Output is correct |
45 |
Correct |
137 ms |
25184 KB |
Output is correct |
46 |
Correct |
138 ms |
25184 KB |
Output is correct |
47 |
Correct |
882 ms |
57492 KB |
Output is correct |
48 |
Correct |
3512 ms |
141076 KB |
Output is correct |
49 |
Correct |
3839 ms |
152460 KB |
Output is correct |
50 |
Correct |
3792 ms |
152636 KB |
Output is correct |
51 |
Correct |
3801 ms |
152680 KB |
Output is correct |
52 |
Correct |
3872 ms |
152596 KB |
Output is correct |
53 |
Correct |
3826 ms |
152680 KB |
Output is correct |
54 |
Correct |
3358 ms |
152604 KB |
Output is correct |
55 |
Correct |
3787 ms |
152720 KB |
Output is correct |
56 |
Correct |
3343 ms |
152664 KB |
Output is correct |
57 |
Correct |
3661 ms |
152600 KB |
Output is correct |
58 |
Correct |
3255 ms |
152600 KB |
Output is correct |
59 |
Correct |
2963 ms |
137500 KB |
Output is correct |
60 |
Correct |
2988 ms |
137412 KB |
Output is correct |
61 |
Correct |
2947 ms |
137320 KB |
Output is correct |
62 |
Correct |
2849 ms |
129872 KB |
Output is correct |
63 |
Correct |
2914 ms |
129836 KB |
Output is correct |
64 |
Correct |
2906 ms |
129724 KB |
Output is correct |
65 |
Correct |
2745 ms |
122196 KB |
Output is correct |
66 |
Correct |
2988 ms |
122128 KB |
Output is correct |
67 |
Correct |
2997 ms |
122548 KB |
Output is correct |