#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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
24920 KB |
Output is correct |
2 |
Correct |
14 ms |
24924 KB |
Output is correct |
3 |
Correct |
13 ms |
25044 KB |
Output is correct |
4 |
Correct |
14 ms |
25112 KB |
Output is correct |
5 |
Correct |
14 ms |
24924 KB |
Output is correct |
6 |
Correct |
13 ms |
24924 KB |
Output is correct |
7 |
Correct |
14 ms |
24924 KB |
Output is correct |
8 |
Correct |
15 ms |
24924 KB |
Output is correct |
9 |
Correct |
13 ms |
24924 KB |
Output is correct |
10 |
Correct |
13 ms |
25180 KB |
Output is correct |
11 |
Correct |
13 ms |
25180 KB |
Output is correct |
12 |
Correct |
13 ms |
25036 KB |
Output is correct |
13 |
Correct |
13 ms |
24924 KB |
Output is correct |
14 |
Correct |
13 ms |
25168 KB |
Output is correct |
15 |
Correct |
13 ms |
24924 KB |
Output is correct |
16 |
Correct |
13 ms |
24920 KB |
Output is correct |
17 |
Correct |
13 ms |
25092 KB |
Output is correct |
18 |
Correct |
13 ms |
24920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
24920 KB |
Output is correct |
2 |
Correct |
14 ms |
24924 KB |
Output is correct |
3 |
Correct |
13 ms |
25044 KB |
Output is correct |
4 |
Correct |
14 ms |
25112 KB |
Output is correct |
5 |
Correct |
14 ms |
24924 KB |
Output is correct |
6 |
Correct |
13 ms |
24924 KB |
Output is correct |
7 |
Correct |
14 ms |
24924 KB |
Output is correct |
8 |
Correct |
15 ms |
24924 KB |
Output is correct |
9 |
Correct |
13 ms |
24924 KB |
Output is correct |
10 |
Correct |
13 ms |
25180 KB |
Output is correct |
11 |
Correct |
13 ms |
25180 KB |
Output is correct |
12 |
Correct |
13 ms |
25036 KB |
Output is correct |
13 |
Correct |
13 ms |
24924 KB |
Output is correct |
14 |
Correct |
13 ms |
25168 KB |
Output is correct |
15 |
Correct |
13 ms |
24924 KB |
Output is correct |
16 |
Correct |
13 ms |
24920 KB |
Output is correct |
17 |
Correct |
13 ms |
25092 KB |
Output is correct |
18 |
Correct |
13 ms |
24920 KB |
Output is correct |
19 |
Correct |
21 ms |
25436 KB |
Output is correct |
20 |
Correct |
21 ms |
25432 KB |
Output is correct |
21 |
Correct |
22 ms |
25436 KB |
Output is correct |
22 |
Correct |
22 ms |
25436 KB |
Output is correct |
23 |
Correct |
21 ms |
25436 KB |
Output is correct |
24 |
Correct |
22 ms |
25436 KB |
Output is correct |
25 |
Correct |
22 ms |
25436 KB |
Output is correct |
26 |
Correct |
21 ms |
25432 KB |
Output is correct |
27 |
Correct |
21 ms |
25432 KB |
Output is correct |
28 |
Correct |
21 ms |
25432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
25556 KB |
Output is correct |
2 |
Correct |
56 ms |
26168 KB |
Output is correct |
3 |
Correct |
86 ms |
27076 KB |
Output is correct |
4 |
Correct |
80 ms |
27080 KB |
Output is correct |
5 |
Correct |
83 ms |
27076 KB |
Output is correct |
6 |
Correct |
79 ms |
27076 KB |
Output is correct |
7 |
Correct |
80 ms |
27072 KB |
Output is correct |
8 |
Correct |
80 ms |
27080 KB |
Output is correct |
9 |
Correct |
83 ms |
27116 KB |
Output is correct |
10 |
Correct |
86 ms |
27112 KB |
Output is correct |
11 |
Correct |
73 ms |
27004 KB |
Output is correct |
12 |
Correct |
75 ms |
27144 KB |
Output is correct |
13 |
Correct |
76 ms |
27088 KB |
Output is correct |
14 |
Correct |
71 ms |
27076 KB |
Output is correct |
15 |
Correct |
67 ms |
27076 KB |
Output is correct |
16 |
Correct |
66 ms |
27084 KB |
Output is correct |
17 |
Correct |
65 ms |
27148 KB |
Output is correct |
18 |
Correct |
64 ms |
27076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
24920 KB |
Output is correct |
2 |
Correct |
14 ms |
24924 KB |
Output is correct |
3 |
Correct |
13 ms |
25044 KB |
Output is correct |
4 |
Correct |
14 ms |
25112 KB |
Output is correct |
5 |
Correct |
14 ms |
24924 KB |
Output is correct |
6 |
Correct |
13 ms |
24924 KB |
Output is correct |
7 |
Correct |
14 ms |
24924 KB |
Output is correct |
8 |
Correct |
15 ms |
24924 KB |
Output is correct |
9 |
Correct |
13 ms |
24924 KB |
Output is correct |
10 |
Correct |
13 ms |
25180 KB |
Output is correct |
11 |
Correct |
13 ms |
25180 KB |
Output is correct |
12 |
Correct |
13 ms |
25036 KB |
Output is correct |
13 |
Correct |
13 ms |
24924 KB |
Output is correct |
14 |
Correct |
13 ms |
25168 KB |
Output is correct |
15 |
Correct |
13 ms |
24924 KB |
Output is correct |
16 |
Correct |
13 ms |
24920 KB |
Output is correct |
17 |
Correct |
13 ms |
25092 KB |
Output is correct |
18 |
Correct |
13 ms |
24920 KB |
Output is correct |
19 |
Correct |
21 ms |
25436 KB |
Output is correct |
20 |
Correct |
21 ms |
25432 KB |
Output is correct |
21 |
Correct |
22 ms |
25436 KB |
Output is correct |
22 |
Correct |
22 ms |
25436 KB |
Output is correct |
23 |
Correct |
21 ms |
25436 KB |
Output is correct |
24 |
Correct |
22 ms |
25436 KB |
Output is correct |
25 |
Correct |
22 ms |
25436 KB |
Output is correct |
26 |
Correct |
21 ms |
25432 KB |
Output is correct |
27 |
Correct |
21 ms |
25432 KB |
Output is correct |
28 |
Correct |
21 ms |
25432 KB |
Output is correct |
29 |
Correct |
21 ms |
25556 KB |
Output is correct |
30 |
Correct |
56 ms |
26168 KB |
Output is correct |
31 |
Correct |
86 ms |
27076 KB |
Output is correct |
32 |
Correct |
80 ms |
27080 KB |
Output is correct |
33 |
Correct |
83 ms |
27076 KB |
Output is correct |
34 |
Correct |
79 ms |
27076 KB |
Output is correct |
35 |
Correct |
80 ms |
27072 KB |
Output is correct |
36 |
Correct |
80 ms |
27080 KB |
Output is correct |
37 |
Correct |
83 ms |
27116 KB |
Output is correct |
38 |
Correct |
86 ms |
27112 KB |
Output is correct |
39 |
Correct |
73 ms |
27004 KB |
Output is correct |
40 |
Correct |
75 ms |
27144 KB |
Output is correct |
41 |
Correct |
76 ms |
27088 KB |
Output is correct |
42 |
Correct |
71 ms |
27076 KB |
Output is correct |
43 |
Correct |
67 ms |
27076 KB |
Output is correct |
44 |
Correct |
66 ms |
27084 KB |
Output is correct |
45 |
Correct |
65 ms |
27148 KB |
Output is correct |
46 |
Correct |
64 ms |
27076 KB |
Output is correct |
47 |
Correct |
252 ms |
31168 KB |
Output is correct |
48 |
Correct |
859 ms |
44892 KB |
Output is correct |
49 |
Correct |
866 ms |
46508 KB |
Output is correct |
50 |
Correct |
878 ms |
46512 KB |
Output is correct |
51 |
Correct |
906 ms |
46512 KB |
Output is correct |
52 |
Correct |
877 ms |
46592 KB |
Output is correct |
53 |
Correct |
900 ms |
46516 KB |
Output is correct |
54 |
Correct |
839 ms |
46512 KB |
Output is correct |
55 |
Correct |
869 ms |
46352 KB |
Output is correct |
56 |
Correct |
849 ms |
46512 KB |
Output is correct |
57 |
Correct |
923 ms |
46508 KB |
Output is correct |
58 |
Correct |
745 ms |
46508 KB |
Output is correct |
59 |
Correct |
740 ms |
46512 KB |
Output is correct |
60 |
Correct |
717 ms |
46528 KB |
Output is correct |
61 |
Correct |
721 ms |
46512 KB |
Output is correct |
62 |
Correct |
756 ms |
46608 KB |
Output is correct |
63 |
Correct |
709 ms |
46812 KB |
Output is correct |
64 |
Correct |
731 ms |
46344 KB |
Output is correct |
65 |
Correct |
685 ms |
46508 KB |
Output is correct |
66 |
Correct |
720 ms |
46356 KB |
Output is correct |
67 |
Correct |
766 ms |
46512 KB |
Output is correct |