#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3;
int sz, seg[4 * N], lz[4 * N];
void init(int n) {
sz = 1;
while (sz < n) sz <<= 1;
}
void push(int x, int lx, int rx) {
if (!lz[x]) return;
seg[2 * x + 1] += lz[x], seg[2 * x + 2] += lz[x];
lz[2 * x + 1] += lz[x], lz[2 * x + 2] += lz[x];
lz[x] = 0;
}
void upd(int l, int r, int v, int x = 0, int lx = 0, int rx = sz) {
if (lx >= r || rx <= l) return;
if (lx >= l && rx <= r) {
seg[x] += v, lz[x] += v;
return;
}
push(x, lx, rx);
int mid = (lx + rx) >> 1;
upd(l, r, v, 2 * x + 1, lx, mid);
upd(l, r, v, 2 * x + 2, mid, rx);
seg[x] = max(seg[2 * x + 1], seg[2 * x + 2]);
}
vector<int> countScans(vector<int> a, vector<int> x, vector<int> v) {
int n = a.size(), q = x.size(), m;
vector<pair<int, int>> b;
for (int i = 0; i < n; ++i)
b.push_back({a[i], i});
for (int i = 0; i < q; ++i)
b.push_back({v[i], x[i]});
sort(b.begin(), b.end());
b.resize(unique(b.begin(), b.end()) - b.begin());
m = b.size();
for (int i = 0; i < n; ++i)
a[i] = lower_bound(b.begin(), b.end(), make_pair(a[i], i)) - b.begin();
for (int i = 0; i < q; ++i)
v[i] = lower_bound(b.begin(), b.end(), make_pair(v[i], x[i])) - b.begin();
init(m);
for (int i = 0; i < n; ++i) {
upd(a[i], a[i] + 1, i);
upd(a[i] + 1, m, -1);
}
vector<int> ans(q);
for (int i = 0; i < q; ++i) {
upd(a[x[i]], a[x[i]] + 1, -x[i]);
upd(a[x[i]] + 1, m, 1);
a[x[i]] = v[i];
upd(a[x[i]], a[x[i]] + 1, x[i]);
upd(a[x[i]] + 1, m, -1);
ans[i] = seg[0];
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
324 KB |
Output is correct |
2 |
Correct |
3 ms |
316 KB |
Output is correct |
3 |
Correct |
4 ms |
448 KB |
Output is correct |
4 |
Correct |
7 ms |
436 KB |
Output is correct |
5 |
Correct |
4 ms |
424 KB |
Output is correct |
6 |
Correct |
4 ms |
452 KB |
Output is correct |
7 |
Correct |
4 ms |
460 KB |
Output is correct |
8 |
Correct |
4 ms |
460 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
520 KB |
Output is correct |
11 |
Correct |
5 ms |
436 KB |
Output is correct |
12 |
Correct |
4 ms |
460 KB |
Output is correct |
13 |
Correct |
4 ms |
460 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
15 |
Correct |
4 ms |
460 KB |
Output is correct |
16 |
Correct |
4 ms |
476 KB |
Output is correct |
17 |
Correct |
4 ms |
460 KB |
Output is correct |
18 |
Correct |
4 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
324 KB |
Output is correct |
2 |
Correct |
3 ms |
316 KB |
Output is correct |
3 |
Correct |
4 ms |
448 KB |
Output is correct |
4 |
Correct |
7 ms |
436 KB |
Output is correct |
5 |
Correct |
4 ms |
424 KB |
Output is correct |
6 |
Correct |
4 ms |
452 KB |
Output is correct |
7 |
Correct |
4 ms |
460 KB |
Output is correct |
8 |
Correct |
4 ms |
460 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
520 KB |
Output is correct |
11 |
Correct |
5 ms |
436 KB |
Output is correct |
12 |
Correct |
4 ms |
460 KB |
Output is correct |
13 |
Correct |
4 ms |
460 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
15 |
Correct |
4 ms |
460 KB |
Output is correct |
16 |
Correct |
4 ms |
476 KB |
Output is correct |
17 |
Correct |
4 ms |
460 KB |
Output is correct |
18 |
Correct |
4 ms |
460 KB |
Output is correct |
19 |
Correct |
17 ms |
1076 KB |
Output is correct |
20 |
Correct |
16 ms |
1096 KB |
Output is correct |
21 |
Correct |
16 ms |
1100 KB |
Output is correct |
22 |
Correct |
26 ms |
1080 KB |
Output is correct |
23 |
Correct |
17 ms |
1100 KB |
Output is correct |
24 |
Correct |
27 ms |
1084 KB |
Output is correct |
25 |
Correct |
16 ms |
1084 KB |
Output is correct |
26 |
Correct |
17 ms |
1124 KB |
Output is correct |
27 |
Correct |
20 ms |
1100 KB |
Output is correct |
28 |
Correct |
20 ms |
1084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
1464 KB |
Output is correct |
2 |
Correct |
73 ms |
2964 KB |
Output is correct |
3 |
Correct |
134 ms |
4536 KB |
Output is correct |
4 |
Correct |
130 ms |
4520 KB |
Output is correct |
5 |
Correct |
165 ms |
4508 KB |
Output is correct |
6 |
Correct |
131 ms |
4500 KB |
Output is correct |
7 |
Correct |
129 ms |
4564 KB |
Output is correct |
8 |
Correct |
144 ms |
4516 KB |
Output is correct |
9 |
Correct |
146 ms |
4592 KB |
Output is correct |
10 |
Correct |
138 ms |
3928 KB |
Output is correct |
11 |
Correct |
123 ms |
3956 KB |
Output is correct |
12 |
Correct |
146 ms |
3932 KB |
Output is correct |
13 |
Correct |
111 ms |
3940 KB |
Output is correct |
14 |
Correct |
133 ms |
3948 KB |
Output is correct |
15 |
Correct |
104 ms |
3876 KB |
Output is correct |
16 |
Correct |
136 ms |
3904 KB |
Output is correct |
17 |
Correct |
124 ms |
3912 KB |
Output is correct |
18 |
Correct |
106 ms |
3896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
324 KB |
Output is correct |
2 |
Correct |
3 ms |
316 KB |
Output is correct |
3 |
Correct |
4 ms |
448 KB |
Output is correct |
4 |
Correct |
7 ms |
436 KB |
Output is correct |
5 |
Correct |
4 ms |
424 KB |
Output is correct |
6 |
Correct |
4 ms |
452 KB |
Output is correct |
7 |
Correct |
4 ms |
460 KB |
Output is correct |
8 |
Correct |
4 ms |
460 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
520 KB |
Output is correct |
11 |
Correct |
5 ms |
436 KB |
Output is correct |
12 |
Correct |
4 ms |
460 KB |
Output is correct |
13 |
Correct |
4 ms |
460 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
15 |
Correct |
4 ms |
460 KB |
Output is correct |
16 |
Correct |
4 ms |
476 KB |
Output is correct |
17 |
Correct |
4 ms |
460 KB |
Output is correct |
18 |
Correct |
4 ms |
460 KB |
Output is correct |
19 |
Correct |
17 ms |
1076 KB |
Output is correct |
20 |
Correct |
16 ms |
1096 KB |
Output is correct |
21 |
Correct |
16 ms |
1100 KB |
Output is correct |
22 |
Correct |
26 ms |
1080 KB |
Output is correct |
23 |
Correct |
17 ms |
1100 KB |
Output is correct |
24 |
Correct |
27 ms |
1084 KB |
Output is correct |
25 |
Correct |
16 ms |
1084 KB |
Output is correct |
26 |
Correct |
17 ms |
1124 KB |
Output is correct |
27 |
Correct |
20 ms |
1100 KB |
Output is correct |
28 |
Correct |
20 ms |
1084 KB |
Output is correct |
29 |
Correct |
25 ms |
1464 KB |
Output is correct |
30 |
Correct |
73 ms |
2964 KB |
Output is correct |
31 |
Correct |
134 ms |
4536 KB |
Output is correct |
32 |
Correct |
130 ms |
4520 KB |
Output is correct |
33 |
Correct |
165 ms |
4508 KB |
Output is correct |
34 |
Correct |
131 ms |
4500 KB |
Output is correct |
35 |
Correct |
129 ms |
4564 KB |
Output is correct |
36 |
Correct |
144 ms |
4516 KB |
Output is correct |
37 |
Correct |
146 ms |
4592 KB |
Output is correct |
38 |
Correct |
138 ms |
3928 KB |
Output is correct |
39 |
Correct |
123 ms |
3956 KB |
Output is correct |
40 |
Correct |
146 ms |
3932 KB |
Output is correct |
41 |
Correct |
111 ms |
3940 KB |
Output is correct |
42 |
Correct |
133 ms |
3948 KB |
Output is correct |
43 |
Correct |
104 ms |
3876 KB |
Output is correct |
44 |
Correct |
136 ms |
3904 KB |
Output is correct |
45 |
Correct |
124 ms |
3912 KB |
Output is correct |
46 |
Correct |
106 ms |
3896 KB |
Output is correct |
47 |
Correct |
511 ms |
14988 KB |
Output is correct |
48 |
Correct |
1915 ms |
46376 KB |
Output is correct |
49 |
Correct |
1857 ms |
50404 KB |
Output is correct |
50 |
Correct |
1753 ms |
50484 KB |
Output is correct |
51 |
Correct |
1794 ms |
50464 KB |
Output is correct |
52 |
Correct |
1821 ms |
50500 KB |
Output is correct |
53 |
Correct |
1845 ms |
50408 KB |
Output is correct |
54 |
Correct |
1594 ms |
50460 KB |
Output is correct |
55 |
Correct |
1644 ms |
50536 KB |
Output is correct |
56 |
Correct |
1570 ms |
50564 KB |
Output is correct |
57 |
Correct |
1656 ms |
50548 KB |
Output is correct |
58 |
Correct |
1595 ms |
50548 KB |
Output is correct |
59 |
Correct |
1622 ms |
47308 KB |
Output is correct |
60 |
Correct |
1660 ms |
47248 KB |
Output is correct |
61 |
Correct |
1562 ms |
47256 KB |
Output is correct |
62 |
Correct |
1517 ms |
46200 KB |
Output is correct |
63 |
Correct |
1515 ms |
46084 KB |
Output is correct |
64 |
Correct |
1541 ms |
46148 KB |
Output is correct |
65 |
Correct |
1434 ms |
44964 KB |
Output is correct |
66 |
Correct |
1477 ms |
45020 KB |
Output is correct |
67 |
Correct |
1440 ms |
45040 KB |
Output is correct |