#include <bits/stdc++.h>
using namespace std;
#define ar array
#define sz(v) int(std::size(v))
using i64 = long long;
using pii = pair<int, int>;
const int INF = 1e9;
struct segt {
int l, r;
segt *lc = NULL, *rc = NULL;
int x, lz;
segt(int l, int r) : l(l), r(r) {
x = -INF, lz = 0;
if (l < r) {
int m = (l + r) / 2;
lc = new segt(l, m);
rc = new segt(m + 1, r);
}
}
void put(int v) {
x += v;
lz += v;
}
void push() {
if (lz != 0)
lc->put(lz), rc->put(lz), lz = 0;
}
void add(int ql, int qr, int v) {
if (ql <= l && qr >= r) put(v);
else {
push();
if (qr <= lc->r) lc->add(ql, qr, v);
else if (ql >= rc->l) rc->add(ql, qr, v);
else lc->add(ql, qr, v), rc->add(ql, qr, v);
x = max(lc->x, rc->x);
}
}
};
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
vector<pii> v;
for (int i = 0; i < sz(A); i++) v.push_back({A[i], i});
for (int i = 0; i < sz(X); i++) v.push_back({V[i], X[i]});
sort(begin(v), end(v));
v.erase(unique(begin(v), end(v)), end(v));
segt *tree = new segt(0, sz(v) - 1);
auto del = [&](int i) {
int p = lower_bound(begin(v), end(v), pii{A[i], i}) - begin(v);
tree->add(p, p, -INF - i);
if (p + 1 < sz(v)) tree->add(p + 1, sz(v) - 1, 1);
};
auto ins = [&](int i) {
int p = lower_bound(begin(v), end(v), pii{A[i], i}) - begin(v);
tree->add(p, p, INF + i);
if (p + 1 < sz(v)) tree->add(p + 1, sz(v) - 1, -1);
};
for (int i = 0; i < sz(A); i++) ins(i);
vector<int> ans(sz(X));
for (int i = 0; i < sz(X); i++) {
int p = X[i];
del(p);
A[p] = V[i];
ins(p);
ans[i] = tree->x;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
3 ms |
860 KB |
Output is correct |
4 |
Correct |
4 ms |
700 KB |
Output is correct |
5 |
Correct |
3 ms |
856 KB |
Output is correct |
6 |
Correct |
3 ms |
860 KB |
Output is correct |
7 |
Correct |
3 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
860 KB |
Output is correct |
9 |
Correct |
3 ms |
860 KB |
Output is correct |
10 |
Correct |
3 ms |
860 KB |
Output is correct |
11 |
Correct |
4 ms |
1016 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
3 ms |
856 KB |
Output is correct |
14 |
Correct |
3 ms |
1112 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
3 ms |
860 KB |
Output is correct |
4 |
Correct |
4 ms |
700 KB |
Output is correct |
5 |
Correct |
3 ms |
856 KB |
Output is correct |
6 |
Correct |
3 ms |
860 KB |
Output is correct |
7 |
Correct |
3 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
860 KB |
Output is correct |
9 |
Correct |
3 ms |
860 KB |
Output is correct |
10 |
Correct |
3 ms |
860 KB |
Output is correct |
11 |
Correct |
4 ms |
1016 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
3 ms |
856 KB |
Output is correct |
14 |
Correct |
3 ms |
1112 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
3 ms |
604 KB |
Output is correct |
19 |
Correct |
12 ms |
2140 KB |
Output is correct |
20 |
Correct |
15 ms |
2396 KB |
Output is correct |
21 |
Correct |
14 ms |
2396 KB |
Output is correct |
22 |
Correct |
14 ms |
2396 KB |
Output is correct |
23 |
Correct |
13 ms |
2140 KB |
Output is correct |
24 |
Correct |
13 ms |
2140 KB |
Output is correct |
25 |
Correct |
12 ms |
2112 KB |
Output is correct |
26 |
Correct |
12 ms |
2136 KB |
Output is correct |
27 |
Correct |
12 ms |
1884 KB |
Output is correct |
28 |
Correct |
12 ms |
1880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
3800 KB |
Output is correct |
2 |
Correct |
57 ms |
7968 KB |
Output is correct |
3 |
Correct |
107 ms |
12228 KB |
Output is correct |
4 |
Correct |
106 ms |
12380 KB |
Output is correct |
5 |
Correct |
103 ms |
12384 KB |
Output is correct |
6 |
Correct |
110 ms |
12232 KB |
Output is correct |
7 |
Correct |
105 ms |
12048 KB |
Output is correct |
8 |
Correct |
101 ms |
12052 KB |
Output is correct |
9 |
Correct |
114 ms |
12076 KB |
Output is correct |
10 |
Correct |
89 ms |
8132 KB |
Output is correct |
11 |
Correct |
73 ms |
8140 KB |
Output is correct |
12 |
Correct |
73 ms |
8120 KB |
Output is correct |
13 |
Correct |
71 ms |
8308 KB |
Output is correct |
14 |
Correct |
75 ms |
8648 KB |
Output is correct |
15 |
Correct |
71 ms |
8140 KB |
Output is correct |
16 |
Correct |
84 ms |
8136 KB |
Output is correct |
17 |
Correct |
72 ms |
8284 KB |
Output is correct |
18 |
Correct |
67 ms |
8136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
3 ms |
860 KB |
Output is correct |
4 |
Correct |
4 ms |
700 KB |
Output is correct |
5 |
Correct |
3 ms |
856 KB |
Output is correct |
6 |
Correct |
3 ms |
860 KB |
Output is correct |
7 |
Correct |
3 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
860 KB |
Output is correct |
9 |
Correct |
3 ms |
860 KB |
Output is correct |
10 |
Correct |
3 ms |
860 KB |
Output is correct |
11 |
Correct |
4 ms |
1016 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
3 ms |
856 KB |
Output is correct |
14 |
Correct |
3 ms |
1112 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
3 ms |
604 KB |
Output is correct |
19 |
Correct |
12 ms |
2140 KB |
Output is correct |
20 |
Correct |
15 ms |
2396 KB |
Output is correct |
21 |
Correct |
14 ms |
2396 KB |
Output is correct |
22 |
Correct |
14 ms |
2396 KB |
Output is correct |
23 |
Correct |
13 ms |
2140 KB |
Output is correct |
24 |
Correct |
13 ms |
2140 KB |
Output is correct |
25 |
Correct |
12 ms |
2112 KB |
Output is correct |
26 |
Correct |
12 ms |
2136 KB |
Output is correct |
27 |
Correct |
12 ms |
1884 KB |
Output is correct |
28 |
Correct |
12 ms |
1880 KB |
Output is correct |
29 |
Correct |
21 ms |
3800 KB |
Output is correct |
30 |
Correct |
57 ms |
7968 KB |
Output is correct |
31 |
Correct |
107 ms |
12228 KB |
Output is correct |
32 |
Correct |
106 ms |
12380 KB |
Output is correct |
33 |
Correct |
103 ms |
12384 KB |
Output is correct |
34 |
Correct |
110 ms |
12232 KB |
Output is correct |
35 |
Correct |
105 ms |
12048 KB |
Output is correct |
36 |
Correct |
101 ms |
12052 KB |
Output is correct |
37 |
Correct |
114 ms |
12076 KB |
Output is correct |
38 |
Correct |
89 ms |
8132 KB |
Output is correct |
39 |
Correct |
73 ms |
8140 KB |
Output is correct |
40 |
Correct |
73 ms |
8120 KB |
Output is correct |
41 |
Correct |
71 ms |
8308 KB |
Output is correct |
42 |
Correct |
75 ms |
8648 KB |
Output is correct |
43 |
Correct |
71 ms |
8140 KB |
Output is correct |
44 |
Correct |
84 ms |
8136 KB |
Output is correct |
45 |
Correct |
72 ms |
8284 KB |
Output is correct |
46 |
Correct |
67 ms |
8136 KB |
Output is correct |
47 |
Correct |
452 ms |
37560 KB |
Output is correct |
48 |
Correct |
1970 ms |
115652 KB |
Output is correct |
49 |
Correct |
2155 ms |
125872 KB |
Output is correct |
50 |
Correct |
2173 ms |
125732 KB |
Output is correct |
51 |
Correct |
2187 ms |
125876 KB |
Output is correct |
52 |
Correct |
2196 ms |
125936 KB |
Output is correct |
53 |
Correct |
2143 ms |
126064 KB |
Output is correct |
54 |
Correct |
1959 ms |
125724 KB |
Output is correct |
55 |
Correct |
2121 ms |
125724 KB |
Output is correct |
56 |
Correct |
1915 ms |
125872 KB |
Output is correct |
57 |
Correct |
2008 ms |
125872 KB |
Output is correct |
58 |
Correct |
1918 ms |
125944 KB |
Output is correct |
59 |
Correct |
1731 ms |
113332 KB |
Output is correct |
60 |
Correct |
1660 ms |
113572 KB |
Output is correct |
61 |
Correct |
1680 ms |
113144 KB |
Output is correct |
62 |
Correct |
1527 ms |
107336 KB |
Output is correct |
63 |
Correct |
1514 ms |
107444 KB |
Output is correct |
64 |
Correct |
1528 ms |
107396 KB |
Output is correct |
65 |
Correct |
1401 ms |
101364 KB |
Output is correct |
66 |
Correct |
1435 ms |
101224 KB |
Output is correct |
67 |
Correct |
1397 ms |
101296 KB |
Output is correct |