#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
constexpr int64_t N = 500000, L = 1 << 20;
int32_t T[2 * L][3];
void propagate(size_t k)
{
T[2 * k][0] += T[k][1];
T[2 * k][1] += T[k][1];
T[2 * k + 1][0] += T[k][1];
T[2 * k + 1][1] += T[k][1];
T[k][1] = 0;
}
void increment(size_t i, size_t j, int64_t x, size_t k = 1, size_t a = 0, size_t b = L)
{
if (b <= i || a >= j)
return;
if (i <= a && b <= j)
T[k][0] += x, T[k][1] += x;
else
{
propagate(k);
increment(i, j, x, 2 * k, a, (a + b) / 2);
increment(i, j, x, 2 * k + 1, (a + b) / 2, b);
T[k][0] = max(T[2 * k][0], T[2 * k + 1][0]);
T[k][2] = T[2 * k][2] + T[2 * k + 1][2];
}
}
void update(size_t i, int64_t x, size_t k = 1, size_t a = 0, size_t b = L)
{
if (b - a == 1)
{
T[k][0] = x;
T[k][2] = x != INT32_MIN / 2;
}
else
{
propagate(k);
if (i < (a + b) / 2)
update(i, x, 2 * k, a, (a + b) / 2);
else
update(i, x, 2 * k + 1, (a + b) / 2, b);
T[k][0] = max(T[2 * k][0], T[2 * k + 1][0]);
T[k][2] = T[2 * k][2] + T[2 * k + 1][2];
}
}
int64_t num_elements(size_t i, size_t j, size_t k = 1, size_t a = 0, size_t b = L)
{
if (b <= i || a >= j)
return 0;
if (i <= a && b <= j)
return T[k][2];
return num_elements(i, j, 2 * k, a, (a + b) / 2) +
num_elements(i, j, 2 * k + 1, (a + b) / 2, b);
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V)
{
vector<size_t> coords;
for (size_t i = 0; i < A.size(); i++)
coords.push_back(A[i] * N + i);
for (size_t i = 0; i < X.size(); i++)
coords.push_back(V[i] * N + X[i]);
sort(coords.begin(), coords.end());
coords.resize(unique(coords.begin(), coords.end()) - coords.begin());
for (size_t i = 0; i < A.size(); i++)
A[i] = lower_bound(coords.begin(), coords.end(), A[i] * N + i) - coords.begin();
for (size_t i = 0; i < X.size(); i++)
V[i] = lower_bound(coords.begin(), coords.end(), V[i] * N + X[i]) - coords.begin();
for (size_t i = L; i < 2 * L; i++)
T[i][0] = INT32_MIN / 2;
for (size_t i = 0; i < A.size(); i++)
T[L + A[i]][2] = 1;
for (size_t i = L - 1; i; i--)
T[i][2] = T[2 * i][2] + T[2 * i + 1][2];
for (size_t i = 0; i < A.size(); i++)
T[L + A[i]][0] = (int64_t)i - num_elements(0, A[i]);
for (size_t i = L - 1; i; i--)
T[i][0] = max(T[2 * i][0], T[2 * i + 1][0]);
vector<int> ans(X.size());
for (size_t i = 0; i < X.size(); i++)
{
update(A[X[i]], INT32_MIN / 2);
increment(A[X[i]], L, 1);
A[X[i]] = V[i];
increment(A[X[i]], L, -1);
update(A[X[i]], X[i] - num_elements(0, A[X[i]]));
ans[i] = T[1][0];
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
24924 KB |
Output is correct |
2 |
Correct |
17 ms |
24924 KB |
Output is correct |
3 |
Correct |
14 ms |
24924 KB |
Output is correct |
4 |
Correct |
13 ms |
25164 KB |
Output is correct |
5 |
Correct |
15 ms |
24924 KB |
Output is correct |
6 |
Correct |
13 ms |
24932 KB |
Output is correct |
7 |
Correct |
14 ms |
25164 KB |
Output is correct |
8 |
Correct |
14 ms |
24924 KB |
Output is correct |
9 |
Correct |
15 ms |
24924 KB |
Output is correct |
10 |
Correct |
14 ms |
24924 KB |
Output is correct |
11 |
Correct |
14 ms |
25176 KB |
Output is correct |
12 |
Correct |
14 ms |
24924 KB |
Output is correct |
13 |
Correct |
14 ms |
24984 KB |
Output is correct |
14 |
Correct |
18 ms |
24924 KB |
Output is correct |
15 |
Correct |
16 ms |
25180 KB |
Output is correct |
16 |
Correct |
13 ms |
24924 KB |
Output is correct |
17 |
Correct |
13 ms |
25180 KB |
Output is correct |
18 |
Correct |
13 ms |
25124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
24924 KB |
Output is correct |
2 |
Correct |
17 ms |
24924 KB |
Output is correct |
3 |
Correct |
14 ms |
24924 KB |
Output is correct |
4 |
Correct |
13 ms |
25164 KB |
Output is correct |
5 |
Correct |
15 ms |
24924 KB |
Output is correct |
6 |
Correct |
13 ms |
24932 KB |
Output is correct |
7 |
Correct |
14 ms |
25164 KB |
Output is correct |
8 |
Correct |
14 ms |
24924 KB |
Output is correct |
9 |
Correct |
15 ms |
24924 KB |
Output is correct |
10 |
Correct |
14 ms |
24924 KB |
Output is correct |
11 |
Correct |
14 ms |
25176 KB |
Output is correct |
12 |
Correct |
14 ms |
24924 KB |
Output is correct |
13 |
Correct |
14 ms |
24984 KB |
Output is correct |
14 |
Correct |
18 ms |
24924 KB |
Output is correct |
15 |
Correct |
16 ms |
25180 KB |
Output is correct |
16 |
Correct |
13 ms |
24924 KB |
Output is correct |
17 |
Correct |
13 ms |
25180 KB |
Output is correct |
18 |
Correct |
13 ms |
25124 KB |
Output is correct |
19 |
Correct |
22 ms |
25360 KB |
Output is correct |
20 |
Correct |
23 ms |
25436 KB |
Output is correct |
21 |
Correct |
21 ms |
25312 KB |
Output is correct |
22 |
Correct |
22 ms |
25436 KB |
Output is correct |
23 |
Correct |
23 ms |
25436 KB |
Output is correct |
24 |
Correct |
21 ms |
25432 KB |
Output is correct |
25 |
Correct |
21 ms |
25504 KB |
Output is correct |
26 |
Correct |
22 ms |
25436 KB |
Output is correct |
27 |
Correct |
23 ms |
25416 KB |
Output is correct |
28 |
Correct |
21 ms |
25436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
25556 KB |
Output is correct |
2 |
Correct |
50 ms |
26324 KB |
Output is correct |
3 |
Correct |
82 ms |
27076 KB |
Output is correct |
4 |
Correct |
81 ms |
27120 KB |
Output is correct |
5 |
Correct |
83 ms |
27080 KB |
Output is correct |
6 |
Correct |
80 ms |
27076 KB |
Output is correct |
7 |
Correct |
83 ms |
27004 KB |
Output is correct |
8 |
Correct |
81 ms |
27076 KB |
Output is correct |
9 |
Correct |
80 ms |
27076 KB |
Output is correct |
10 |
Correct |
73 ms |
27068 KB |
Output is correct |
11 |
Correct |
74 ms |
27076 KB |
Output is correct |
12 |
Correct |
71 ms |
27076 KB |
Output is correct |
13 |
Correct |
69 ms |
27156 KB |
Output is correct |
14 |
Correct |
69 ms |
27080 KB |
Output is correct |
15 |
Correct |
74 ms |
27084 KB |
Output is correct |
16 |
Correct |
79 ms |
27080 KB |
Output is correct |
17 |
Correct |
70 ms |
27084 KB |
Output is correct |
18 |
Correct |
67 ms |
27088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
24924 KB |
Output is correct |
2 |
Correct |
17 ms |
24924 KB |
Output is correct |
3 |
Correct |
14 ms |
24924 KB |
Output is correct |
4 |
Correct |
13 ms |
25164 KB |
Output is correct |
5 |
Correct |
15 ms |
24924 KB |
Output is correct |
6 |
Correct |
13 ms |
24932 KB |
Output is correct |
7 |
Correct |
14 ms |
25164 KB |
Output is correct |
8 |
Correct |
14 ms |
24924 KB |
Output is correct |
9 |
Correct |
15 ms |
24924 KB |
Output is correct |
10 |
Correct |
14 ms |
24924 KB |
Output is correct |
11 |
Correct |
14 ms |
25176 KB |
Output is correct |
12 |
Correct |
14 ms |
24924 KB |
Output is correct |
13 |
Correct |
14 ms |
24984 KB |
Output is correct |
14 |
Correct |
18 ms |
24924 KB |
Output is correct |
15 |
Correct |
16 ms |
25180 KB |
Output is correct |
16 |
Correct |
13 ms |
24924 KB |
Output is correct |
17 |
Correct |
13 ms |
25180 KB |
Output is correct |
18 |
Correct |
13 ms |
25124 KB |
Output is correct |
19 |
Correct |
22 ms |
25360 KB |
Output is correct |
20 |
Correct |
23 ms |
25436 KB |
Output is correct |
21 |
Correct |
21 ms |
25312 KB |
Output is correct |
22 |
Correct |
22 ms |
25436 KB |
Output is correct |
23 |
Correct |
23 ms |
25436 KB |
Output is correct |
24 |
Correct |
21 ms |
25432 KB |
Output is correct |
25 |
Correct |
21 ms |
25504 KB |
Output is correct |
26 |
Correct |
22 ms |
25436 KB |
Output is correct |
27 |
Correct |
23 ms |
25416 KB |
Output is correct |
28 |
Correct |
21 ms |
25436 KB |
Output is correct |
29 |
Correct |
21 ms |
25556 KB |
Output is correct |
30 |
Correct |
50 ms |
26324 KB |
Output is correct |
31 |
Correct |
82 ms |
27076 KB |
Output is correct |
32 |
Correct |
81 ms |
27120 KB |
Output is correct |
33 |
Correct |
83 ms |
27080 KB |
Output is correct |
34 |
Correct |
80 ms |
27076 KB |
Output is correct |
35 |
Correct |
83 ms |
27004 KB |
Output is correct |
36 |
Correct |
81 ms |
27076 KB |
Output is correct |
37 |
Correct |
80 ms |
27076 KB |
Output is correct |
38 |
Correct |
73 ms |
27068 KB |
Output is correct |
39 |
Correct |
74 ms |
27076 KB |
Output is correct |
40 |
Correct |
71 ms |
27076 KB |
Output is correct |
41 |
Correct |
69 ms |
27156 KB |
Output is correct |
42 |
Correct |
69 ms |
27080 KB |
Output is correct |
43 |
Correct |
74 ms |
27084 KB |
Output is correct |
44 |
Correct |
79 ms |
27080 KB |
Output is correct |
45 |
Correct |
70 ms |
27084 KB |
Output is correct |
46 |
Correct |
67 ms |
27088 KB |
Output is correct |
47 |
Correct |
249 ms |
31140 KB |
Output is correct |
48 |
Correct |
889 ms |
44972 KB |
Output is correct |
49 |
Correct |
948 ms |
46508 KB |
Output is correct |
50 |
Correct |
973 ms |
46508 KB |
Output is correct |
51 |
Correct |
899 ms |
46528 KB |
Output is correct |
52 |
Correct |
939 ms |
46512 KB |
Output is correct |
53 |
Correct |
863 ms |
46512 KB |
Output is correct |
54 |
Correct |
920 ms |
46512 KB |
Output is correct |
55 |
Correct |
891 ms |
46768 KB |
Output is correct |
56 |
Correct |
925 ms |
46508 KB |
Output is correct |
57 |
Correct |
942 ms |
46524 KB |
Output is correct |
58 |
Correct |
920 ms |
46508 KB |
Output is correct |
59 |
Correct |
832 ms |
46596 KB |
Output is correct |
60 |
Correct |
821 ms |
46524 KB |
Output is correct |
61 |
Correct |
785 ms |
46512 KB |
Output is correct |
62 |
Correct |
817 ms |
46508 KB |
Output is correct |
63 |
Correct |
828 ms |
46696 KB |
Output is correct |
64 |
Correct |
832 ms |
46512 KB |
Output is correct |
65 |
Correct |
789 ms |
46524 KB |
Output is correct |
66 |
Correct |
745 ms |
46508 KB |
Output is correct |
67 |
Correct |
747 ms |
46508 KB |
Output is correct |