#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) {
prop(v, l, r);
if(l > hi || r < lo) return;
if(l >= lo && r <= hi) {
ST[v] += val;
lazy[v] += val; prop(v, l, r);
return;
}
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
16980 KB |
Output is correct |
2 |
Correct |
22 ms |
16932 KB |
Output is correct |
3 |
Correct |
27 ms |
17388 KB |
Output is correct |
4 |
Correct |
25 ms |
17360 KB |
Output is correct |
5 |
Correct |
24 ms |
17348 KB |
Output is correct |
6 |
Correct |
24 ms |
17396 KB |
Output is correct |
7 |
Correct |
29 ms |
17348 KB |
Output is correct |
8 |
Correct |
25 ms |
17364 KB |
Output is correct |
9 |
Correct |
25 ms |
17396 KB |
Output is correct |
10 |
Correct |
24 ms |
17336 KB |
Output is correct |
11 |
Correct |
24 ms |
17328 KB |
Output is correct |
12 |
Correct |
24 ms |
17304 KB |
Output is correct |
13 |
Correct |
24 ms |
17276 KB |
Output is correct |
14 |
Correct |
24 ms |
17268 KB |
Output is correct |
15 |
Correct |
30 ms |
17296 KB |
Output is correct |
16 |
Correct |
24 ms |
17172 KB |
Output is correct |
17 |
Correct |
26 ms |
17288 KB |
Output is correct |
18 |
Correct |
24 ms |
17228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
16980 KB |
Output is correct |
2 |
Correct |
22 ms |
16932 KB |
Output is correct |
3 |
Correct |
27 ms |
17388 KB |
Output is correct |
4 |
Correct |
25 ms |
17360 KB |
Output is correct |
5 |
Correct |
24 ms |
17348 KB |
Output is correct |
6 |
Correct |
24 ms |
17396 KB |
Output is correct |
7 |
Correct |
29 ms |
17348 KB |
Output is correct |
8 |
Correct |
25 ms |
17364 KB |
Output is correct |
9 |
Correct |
25 ms |
17396 KB |
Output is correct |
10 |
Correct |
24 ms |
17336 KB |
Output is correct |
11 |
Correct |
24 ms |
17328 KB |
Output is correct |
12 |
Correct |
24 ms |
17304 KB |
Output is correct |
13 |
Correct |
24 ms |
17276 KB |
Output is correct |
14 |
Correct |
24 ms |
17268 KB |
Output is correct |
15 |
Correct |
30 ms |
17296 KB |
Output is correct |
16 |
Correct |
24 ms |
17172 KB |
Output is correct |
17 |
Correct |
26 ms |
17288 KB |
Output is correct |
18 |
Correct |
24 ms |
17228 KB |
Output is correct |
19 |
Correct |
40 ms |
18880 KB |
Output is correct |
20 |
Correct |
45 ms |
19216 KB |
Output is correct |
21 |
Correct |
43 ms |
19168 KB |
Output is correct |
22 |
Correct |
44 ms |
19156 KB |
Output is correct |
23 |
Correct |
43 ms |
18904 KB |
Output is correct |
24 |
Correct |
48 ms |
18888 KB |
Output is correct |
25 |
Correct |
54 ms |
18768 KB |
Output is correct |
26 |
Correct |
41 ms |
18752 KB |
Output is correct |
27 |
Correct |
40 ms |
18652 KB |
Output is correct |
28 |
Correct |
43 ms |
18740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
20696 KB |
Output is correct |
2 |
Correct |
140 ms |
25748 KB |
Output is correct |
3 |
Correct |
212 ms |
30800 KB |
Output is correct |
4 |
Correct |
214 ms |
31020 KB |
Output is correct |
5 |
Correct |
234 ms |
30756 KB |
Output is correct |
6 |
Correct |
203 ms |
30612 KB |
Output is correct |
7 |
Correct |
215 ms |
30580 KB |
Output is correct |
8 |
Correct |
204 ms |
30624 KB |
Output is correct |
9 |
Correct |
193 ms |
30512 KB |
Output is correct |
10 |
Correct |
175 ms |
25460 KB |
Output is correct |
11 |
Correct |
153 ms |
25472 KB |
Output is correct |
12 |
Correct |
154 ms |
25472 KB |
Output is correct |
13 |
Correct |
160 ms |
25420 KB |
Output is correct |
14 |
Correct |
149 ms |
25420 KB |
Output is correct |
15 |
Correct |
150 ms |
25476 KB |
Output is correct |
16 |
Correct |
155 ms |
25420 KB |
Output is correct |
17 |
Correct |
141 ms |
25480 KB |
Output is correct |
18 |
Correct |
156 ms |
25356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
16980 KB |
Output is correct |
2 |
Correct |
22 ms |
16932 KB |
Output is correct |
3 |
Correct |
27 ms |
17388 KB |
Output is correct |
4 |
Correct |
25 ms |
17360 KB |
Output is correct |
5 |
Correct |
24 ms |
17348 KB |
Output is correct |
6 |
Correct |
24 ms |
17396 KB |
Output is correct |
7 |
Correct |
29 ms |
17348 KB |
Output is correct |
8 |
Correct |
25 ms |
17364 KB |
Output is correct |
9 |
Correct |
25 ms |
17396 KB |
Output is correct |
10 |
Correct |
24 ms |
17336 KB |
Output is correct |
11 |
Correct |
24 ms |
17328 KB |
Output is correct |
12 |
Correct |
24 ms |
17304 KB |
Output is correct |
13 |
Correct |
24 ms |
17276 KB |
Output is correct |
14 |
Correct |
24 ms |
17268 KB |
Output is correct |
15 |
Correct |
30 ms |
17296 KB |
Output is correct |
16 |
Correct |
24 ms |
17172 KB |
Output is correct |
17 |
Correct |
26 ms |
17288 KB |
Output is correct |
18 |
Correct |
24 ms |
17228 KB |
Output is correct |
19 |
Correct |
40 ms |
18880 KB |
Output is correct |
20 |
Correct |
45 ms |
19216 KB |
Output is correct |
21 |
Correct |
43 ms |
19168 KB |
Output is correct |
22 |
Correct |
44 ms |
19156 KB |
Output is correct |
23 |
Correct |
43 ms |
18904 KB |
Output is correct |
24 |
Correct |
48 ms |
18888 KB |
Output is correct |
25 |
Correct |
54 ms |
18768 KB |
Output is correct |
26 |
Correct |
41 ms |
18752 KB |
Output is correct |
27 |
Correct |
40 ms |
18652 KB |
Output is correct |
28 |
Correct |
43 ms |
18740 KB |
Output is correct |
29 |
Correct |
53 ms |
20696 KB |
Output is correct |
30 |
Correct |
140 ms |
25748 KB |
Output is correct |
31 |
Correct |
212 ms |
30800 KB |
Output is correct |
32 |
Correct |
214 ms |
31020 KB |
Output is correct |
33 |
Correct |
234 ms |
30756 KB |
Output is correct |
34 |
Correct |
203 ms |
30612 KB |
Output is correct |
35 |
Correct |
215 ms |
30580 KB |
Output is correct |
36 |
Correct |
204 ms |
30624 KB |
Output is correct |
37 |
Correct |
193 ms |
30512 KB |
Output is correct |
38 |
Correct |
175 ms |
25460 KB |
Output is correct |
39 |
Correct |
153 ms |
25472 KB |
Output is correct |
40 |
Correct |
154 ms |
25472 KB |
Output is correct |
41 |
Correct |
160 ms |
25420 KB |
Output is correct |
42 |
Correct |
149 ms |
25420 KB |
Output is correct |
43 |
Correct |
150 ms |
25476 KB |
Output is correct |
44 |
Correct |
155 ms |
25420 KB |
Output is correct |
45 |
Correct |
141 ms |
25480 KB |
Output is correct |
46 |
Correct |
156 ms |
25356 KB |
Output is correct |
47 |
Correct |
896 ms |
60680 KB |
Output is correct |
48 |
Correct |
3692 ms |
152500 KB |
Output is correct |
49 |
Correct |
4075 ms |
165056 KB |
Output is correct |
50 |
Correct |
4059 ms |
165108 KB |
Output is correct |
51 |
Correct |
4051 ms |
165228 KB |
Output is correct |
52 |
Correct |
3939 ms |
165152 KB |
Output is correct |
53 |
Correct |
3927 ms |
165124 KB |
Output is correct |
54 |
Correct |
3560 ms |
165400 KB |
Output is correct |
55 |
Correct |
3939 ms |
165384 KB |
Output is correct |
56 |
Correct |
3566 ms |
165368 KB |
Output is correct |
57 |
Correct |
3836 ms |
165408 KB |
Output is correct |
58 |
Correct |
3317 ms |
165132 KB |
Output is correct |
59 |
Correct |
3092 ms |
148796 KB |
Output is correct |
60 |
Correct |
3072 ms |
148744 KB |
Output is correct |
61 |
Correct |
3229 ms |
148748 KB |
Output is correct |
62 |
Correct |
3042 ms |
141004 KB |
Output is correct |
63 |
Correct |
3226 ms |
141056 KB |
Output is correct |
64 |
Correct |
3075 ms |
140916 KB |
Output is correct |
65 |
Correct |
2940 ms |
133120 KB |
Output is correct |
66 |
Correct |
2999 ms |
133320 KB |
Output is correct |
67 |
Correct |
3090 ms |
133420 KB |
Output is correct |