// http://s3-ap-northeast-1.amazonaws.com/data.cms.ioi-jp.org/open-2018/2018-open-bubblesort2-sol-en.pdf
#include<iostream>
#include<algorithm>
#include<vector>
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define ff first
#define ss second
const int N = 5e5 + 5, SZ = 1 << 21, inf = 1e9 + 7;
int n, q, nq;
int seg[SZ], laz[SZ];
void upd(int u, int l, int r, int a, int b, int v) {
if (a <= l && r <= b) {
seg[u] += v;
laz[u] += v;
return;
}
int m = (l + r) >> 1, u1 = u << 1, u2 = u1 | 1;
if (laz[u]) {
seg[u1] += laz[u];
seg[u2] += laz[u];
laz[u1] += laz[u];
laz[u2] += laz[u];
laz[u] = 0;
}
if (a <= m) upd(u1, l, m, a, b, v);
if (m < b) upd(u2, m + 1, r, a, b, v);
seg[u] = max(seg[u1], seg[u2]);
}
void compress(vector<int> &a, const vector<int> &x, vector<int> &v) {
vector<pii> b;
for (int i = 0; i < n; ++i) b.emplace_back(a[i], i);
for (int i = 0; i < q; ++i) b.emplace_back(v[i], x[i]);
sort(all(b));
b.resize(unique(all(b)) - b.begin());
for (int i = 0; i < n; ++i) a[i] = lower_bound(all(b), pii(a[i], i)) - b.begin();
for (int i = 0; i < q; ++i) v[i] = lower_bound(all(b), pii(v[i], x[i])) - b.begin();
}
vector<int> countScans(vector<int> a, vector<int> x, vector<int> v) {
n = a.size(), q = x.size(), nq = n + q - 1;
compress(a, x, v);
upd(1, 0, nq, 0, nq, -inf);
for (int i = 0; i < n; ++i) {
upd(1, 0, nq, a[i], a[i], inf + i);
upd(1, 0, nq, a[i] + 1, nq, -1);
}
vector<int> ans;
for (int i = 0, j; i < q; ++i) {
j = x[i];
upd(1, 0, nq, a[j], a[j], -inf - j);
upd(1, 0, nq, a[j] + 1, nq, 1);
a[j] = v[i];
upd(1, 0, nq, a[j], a[j], inf + j);
upd(1, 0, nq, a[j] + 1, nq, -1);
ans.push_back(seg[1]);
}
return ans;
}
/** /\_/\
* (= ._.)
* / >0 \>1
**/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
444 KB |
Output is correct |
4 |
Correct |
3 ms |
436 KB |
Output is correct |
5 |
Correct |
4 ms |
412 KB |
Output is correct |
6 |
Correct |
4 ms |
428 KB |
Output is correct |
7 |
Correct |
3 ms |
472 KB |
Output is correct |
8 |
Correct |
3 ms |
444 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
444 KB |
Output is correct |
11 |
Correct |
3 ms |
460 KB |
Output is correct |
12 |
Correct |
3 ms |
460 KB |
Output is correct |
13 |
Correct |
3 ms |
460 KB |
Output is correct |
14 |
Correct |
4 ms |
440 KB |
Output is correct |
15 |
Correct |
3 ms |
460 KB |
Output is correct |
16 |
Correct |
3 ms |
460 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
444 KB |
Output is correct |
4 |
Correct |
3 ms |
436 KB |
Output is correct |
5 |
Correct |
4 ms |
412 KB |
Output is correct |
6 |
Correct |
4 ms |
428 KB |
Output is correct |
7 |
Correct |
3 ms |
472 KB |
Output is correct |
8 |
Correct |
3 ms |
444 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
444 KB |
Output is correct |
11 |
Correct |
3 ms |
460 KB |
Output is correct |
12 |
Correct |
3 ms |
460 KB |
Output is correct |
13 |
Correct |
3 ms |
460 KB |
Output is correct |
14 |
Correct |
4 ms |
440 KB |
Output is correct |
15 |
Correct |
3 ms |
460 KB |
Output is correct |
16 |
Correct |
3 ms |
460 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
3 ms |
460 KB |
Output is correct |
19 |
Correct |
12 ms |
1092 KB |
Output is correct |
20 |
Correct |
16 ms |
1100 KB |
Output is correct |
21 |
Correct |
13 ms |
1088 KB |
Output is correct |
22 |
Correct |
13 ms |
1100 KB |
Output is correct |
23 |
Correct |
13 ms |
984 KB |
Output is correct |
24 |
Correct |
19 ms |
952 KB |
Output is correct |
25 |
Correct |
14 ms |
1012 KB |
Output is correct |
26 |
Correct |
12 ms |
988 KB |
Output is correct |
27 |
Correct |
12 ms |
1000 KB |
Output is correct |
28 |
Correct |
12 ms |
956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1288 KB |
Output is correct |
2 |
Correct |
58 ms |
2472 KB |
Output is correct |
3 |
Correct |
99 ms |
4496 KB |
Output is correct |
4 |
Correct |
110 ms |
4520 KB |
Output is correct |
5 |
Correct |
106 ms |
4480 KB |
Output is correct |
6 |
Correct |
97 ms |
4496 KB |
Output is correct |
7 |
Correct |
108 ms |
4536 KB |
Output is correct |
8 |
Correct |
101 ms |
4504 KB |
Output is correct |
9 |
Correct |
101 ms |
4500 KB |
Output is correct |
10 |
Correct |
87 ms |
3652 KB |
Output is correct |
11 |
Correct |
86 ms |
3748 KB |
Output is correct |
12 |
Correct |
87 ms |
3660 KB |
Output is correct |
13 |
Correct |
86 ms |
3700 KB |
Output is correct |
14 |
Correct |
83 ms |
3644 KB |
Output is correct |
15 |
Correct |
103 ms |
3640 KB |
Output is correct |
16 |
Correct |
85 ms |
3680 KB |
Output is correct |
17 |
Correct |
82 ms |
3756 KB |
Output is correct |
18 |
Correct |
81 ms |
3644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
444 KB |
Output is correct |
4 |
Correct |
3 ms |
436 KB |
Output is correct |
5 |
Correct |
4 ms |
412 KB |
Output is correct |
6 |
Correct |
4 ms |
428 KB |
Output is correct |
7 |
Correct |
3 ms |
472 KB |
Output is correct |
8 |
Correct |
3 ms |
444 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
444 KB |
Output is correct |
11 |
Correct |
3 ms |
460 KB |
Output is correct |
12 |
Correct |
3 ms |
460 KB |
Output is correct |
13 |
Correct |
3 ms |
460 KB |
Output is correct |
14 |
Correct |
4 ms |
440 KB |
Output is correct |
15 |
Correct |
3 ms |
460 KB |
Output is correct |
16 |
Correct |
3 ms |
460 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
3 ms |
460 KB |
Output is correct |
19 |
Correct |
12 ms |
1092 KB |
Output is correct |
20 |
Correct |
16 ms |
1100 KB |
Output is correct |
21 |
Correct |
13 ms |
1088 KB |
Output is correct |
22 |
Correct |
13 ms |
1100 KB |
Output is correct |
23 |
Correct |
13 ms |
984 KB |
Output is correct |
24 |
Correct |
19 ms |
952 KB |
Output is correct |
25 |
Correct |
14 ms |
1012 KB |
Output is correct |
26 |
Correct |
12 ms |
988 KB |
Output is correct |
27 |
Correct |
12 ms |
1000 KB |
Output is correct |
28 |
Correct |
12 ms |
956 KB |
Output is correct |
29 |
Correct |
19 ms |
1288 KB |
Output is correct |
30 |
Correct |
58 ms |
2472 KB |
Output is correct |
31 |
Correct |
99 ms |
4496 KB |
Output is correct |
32 |
Correct |
110 ms |
4520 KB |
Output is correct |
33 |
Correct |
106 ms |
4480 KB |
Output is correct |
34 |
Correct |
97 ms |
4496 KB |
Output is correct |
35 |
Correct |
108 ms |
4536 KB |
Output is correct |
36 |
Correct |
101 ms |
4504 KB |
Output is correct |
37 |
Correct |
101 ms |
4500 KB |
Output is correct |
38 |
Correct |
87 ms |
3652 KB |
Output is correct |
39 |
Correct |
86 ms |
3748 KB |
Output is correct |
40 |
Correct |
87 ms |
3660 KB |
Output is correct |
41 |
Correct |
86 ms |
3700 KB |
Output is correct |
42 |
Correct |
83 ms |
3644 KB |
Output is correct |
43 |
Correct |
103 ms |
3640 KB |
Output is correct |
44 |
Correct |
85 ms |
3680 KB |
Output is correct |
45 |
Correct |
82 ms |
3756 KB |
Output is correct |
46 |
Correct |
81 ms |
3644 KB |
Output is correct |
47 |
Correct |
434 ms |
15020 KB |
Output is correct |
48 |
Correct |
1467 ms |
43332 KB |
Output is correct |
49 |
Correct |
1470 ms |
45304 KB |
Output is correct |
50 |
Correct |
1460 ms |
45440 KB |
Output is correct |
51 |
Correct |
1451 ms |
45260 KB |
Output is correct |
52 |
Correct |
1513 ms |
45384 KB |
Output is correct |
53 |
Correct |
1453 ms |
45384 KB |
Output is correct |
54 |
Correct |
1349 ms |
45436 KB |
Output is correct |
55 |
Correct |
1391 ms |
45620 KB |
Output is correct |
56 |
Correct |
1370 ms |
45440 KB |
Output is correct |
57 |
Correct |
1412 ms |
45580 KB |
Output is correct |
58 |
Correct |
1386 ms |
45340 KB |
Output is correct |
59 |
Correct |
1290 ms |
42236 KB |
Output is correct |
60 |
Correct |
1323 ms |
42056 KB |
Output is correct |
61 |
Correct |
1382 ms |
42124 KB |
Output is correct |
62 |
Correct |
1415 ms |
40896 KB |
Output is correct |
63 |
Correct |
1235 ms |
40968 KB |
Output is correct |
64 |
Correct |
1233 ms |
40988 KB |
Output is correct |
65 |
Correct |
1145 ms |
39760 KB |
Output is correct |
66 |
Correct |
1165 ms |
39728 KB |
Output is correct |
67 |
Correct |
1124 ms |
39876 KB |
Output is correct |