#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int N = (int)5e5 + 5, Q = N, inf = (int)1e9 + 123;
int n, q, order_q[N], order_a[N];
struct It {
struct Node {
int cnt, mx, lz;
Node (int _cnt = 0, int _mx = -inf, int _lz = 0) : cnt(_cnt), mx(_mx), lz(_lz) {}
Node operator+ (const Node &_) const { return Node(cnt + _.cnt, max(mx, _.mx), 0); }
} node[N << 3];
void true_val (int nd, int Left, int Right) {
if (!node[nd].lz) return ;
node[nd].mx += node[nd].lz;
if (Left != Right) {
node[nd << 1].lz += node[nd].lz;
node[nd << 1 | 1].lz += node[nd].lz;
}
node[nd].lz = 0;
}
void upd_rep (int nd, int Left, int Right, int pos, int val_mx, int val_cnt) {
true_val(nd, Left, Right);
if (pos < Left || Right < pos) return ;
if (Left == Right) {
node[nd] = Node(val_cnt, val_mx, 0);
return ;
}
int mid = (Left + Right) >> 1;
upd_rep(nd << 1, Left, mid, pos, val_mx, val_cnt);
upd_rep(nd << 1 | 1, mid + 1, Right, pos, val_mx, val_cnt);
node[nd] = node[nd << 1] + node[nd << 1 | 1];
}
void upd_add (int nd, int Left, int Right, int l, int r, int val) {
true_val(nd, Left, Right);
if (r < Left || Right < l) return ;
if (l <= Left && Right <= r) {
node[nd].lz = val; true_val(nd, Left, Right);
return ;
}
int mid = (Left + Right) >> 1;
upd_add(nd << 1, Left, mid, l, r, val);
upd_add(nd << 1 | 1, mid + 1, Right, l, r, val);
node[nd] = node[nd << 1] + node[nd << 1 | 1];
}
int get_cnt (int nd, int Left, int Right, int l, int r) {
true_val(nd, Left, Right);
if (r < Left || Right < l) return 0;
if (l <= Left && Right <= r) return node[nd].cnt;
int mid = (Left + Right) >> 1;
return get_cnt(nd << 1, Left, mid, l, r) + get_cnt(nd << 1 | 1, mid + 1, Right, l, r);
}
} it;
struct Vec_ele {
int val, pos_a, dstnct;
Vec_ele (int _val = 0, int _pos_a = 0, int _dstnct = 0) : val(_val), pos_a(_pos_a), dstnct(_dstnct) {}
bool operator< (const Vec_ele &_) const { return make_pair(val, pos_a) < make_pair(_.val, _.pos_a); }
};
vector<int> countScans (vector<int> a, vector<int> x, vector<int> v) {
n = (int)a.size(); q = (int)x.size();
vector<Vec_ele> vec;
for (int i = 0; i < n; ++i) vec.pb( Vec_ele(a[i], i, i) );
for (int i = 0; i < q; ++i) vec.pb( Vec_ele(v[i], x[i], i + n) );
sort(vec.begin(), vec.end() );
for (int i = 0; i < (int)vec.size(); ++i) {
int pos_a = vec[i].pos_a, dstnct = vec[i].dstnct;
if (dstnct < n) {
order_a[dstnct] = i;
int up_val = pos_a - it.get_cnt(1, 0, (int)vec.size() - 1, 0, i);
it.upd_rep(1, 0, (int)vec.size() - 1, order_a[dstnct], up_val, 1);
}
else order_q[dstnct - n] = i;
}
vector<int> ret(q);
for (int i = 0; i < q; ++i) {
it.upd_add(1, 0, (int)vec.size() - 1, order_a[ x[i] ], (int)vec.size() - 1, 1);
it.upd_rep(1, 0, (int)vec.size() - 1, order_a[ x[i] ], -inf, 0);
order_a[ x[i] ] = order_q[i];
it.upd_add(1, 0, (int)vec.size() - 1, order_a[ x[i] ], (int)vec.size() - 1, -1);
int up_val = x[i] - it.get_cnt(1, 0, (int)vec.size() - 1, 0, order_a[ x[i] ]);
it.upd_rep(1, 0, (int)vec.size() - 1, order_a[ x[i] ], up_val, 1);
ret[i] = it.node[1].mx;
}
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
47352 KB |
Output is correct |
2 |
Correct |
44 ms |
47344 KB |
Output is correct |
3 |
Correct |
47 ms |
47480 KB |
Output is correct |
4 |
Correct |
47 ms |
47480 KB |
Output is correct |
5 |
Correct |
50 ms |
47676 KB |
Output is correct |
6 |
Correct |
47 ms |
47560 KB |
Output is correct |
7 |
Correct |
55 ms |
47480 KB |
Output is correct |
8 |
Correct |
47 ms |
47480 KB |
Output is correct |
9 |
Correct |
47 ms |
47480 KB |
Output is correct |
10 |
Correct |
47 ms |
47480 KB |
Output is correct |
11 |
Correct |
47 ms |
47480 KB |
Output is correct |
12 |
Correct |
47 ms |
47480 KB |
Output is correct |
13 |
Correct |
55 ms |
47608 KB |
Output is correct |
14 |
Correct |
53 ms |
47480 KB |
Output is correct |
15 |
Correct |
47 ms |
47480 KB |
Output is correct |
16 |
Correct |
54 ms |
47480 KB |
Output is correct |
17 |
Correct |
46 ms |
47480 KB |
Output is correct |
18 |
Correct |
47 ms |
47480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
47352 KB |
Output is correct |
2 |
Correct |
44 ms |
47344 KB |
Output is correct |
3 |
Correct |
47 ms |
47480 KB |
Output is correct |
4 |
Correct |
47 ms |
47480 KB |
Output is correct |
5 |
Correct |
50 ms |
47676 KB |
Output is correct |
6 |
Correct |
47 ms |
47560 KB |
Output is correct |
7 |
Correct |
55 ms |
47480 KB |
Output is correct |
8 |
Correct |
47 ms |
47480 KB |
Output is correct |
9 |
Correct |
47 ms |
47480 KB |
Output is correct |
10 |
Correct |
47 ms |
47480 KB |
Output is correct |
11 |
Correct |
47 ms |
47480 KB |
Output is correct |
12 |
Correct |
47 ms |
47480 KB |
Output is correct |
13 |
Correct |
55 ms |
47608 KB |
Output is correct |
14 |
Correct |
53 ms |
47480 KB |
Output is correct |
15 |
Correct |
47 ms |
47480 KB |
Output is correct |
16 |
Correct |
54 ms |
47480 KB |
Output is correct |
17 |
Correct |
46 ms |
47480 KB |
Output is correct |
18 |
Correct |
47 ms |
47480 KB |
Output is correct |
19 |
Correct |
62 ms |
48000 KB |
Output is correct |
20 |
Correct |
65 ms |
48036 KB |
Output is correct |
21 |
Correct |
62 ms |
48052 KB |
Output is correct |
22 |
Correct |
62 ms |
48028 KB |
Output is correct |
23 |
Correct |
60 ms |
48056 KB |
Output is correct |
24 |
Correct |
61 ms |
48056 KB |
Output is correct |
25 |
Correct |
61 ms |
48056 KB |
Output is correct |
26 |
Correct |
60 ms |
48056 KB |
Output is correct |
27 |
Correct |
59 ms |
48056 KB |
Output is correct |
28 |
Correct |
60 ms |
48056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
48356 KB |
Output is correct |
2 |
Correct |
126 ms |
49520 KB |
Output is correct |
3 |
Correct |
194 ms |
50796 KB |
Output is correct |
4 |
Correct |
178 ms |
50928 KB |
Output is correct |
5 |
Correct |
178 ms |
50848 KB |
Output is correct |
6 |
Correct |
178 ms |
50796 KB |
Output is correct |
7 |
Correct |
178 ms |
50796 KB |
Output is correct |
8 |
Correct |
181 ms |
50924 KB |
Output is correct |
9 |
Correct |
178 ms |
50788 KB |
Output is correct |
10 |
Correct |
168 ms |
50924 KB |
Output is correct |
11 |
Correct |
162 ms |
50872 KB |
Output is correct |
12 |
Correct |
164 ms |
50920 KB |
Output is correct |
13 |
Correct |
162 ms |
50924 KB |
Output is correct |
14 |
Correct |
163 ms |
50924 KB |
Output is correct |
15 |
Correct |
163 ms |
50928 KB |
Output is correct |
16 |
Correct |
157 ms |
50840 KB |
Output is correct |
17 |
Correct |
165 ms |
50908 KB |
Output is correct |
18 |
Correct |
166 ms |
50892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
47352 KB |
Output is correct |
2 |
Correct |
44 ms |
47344 KB |
Output is correct |
3 |
Correct |
47 ms |
47480 KB |
Output is correct |
4 |
Correct |
47 ms |
47480 KB |
Output is correct |
5 |
Correct |
50 ms |
47676 KB |
Output is correct |
6 |
Correct |
47 ms |
47560 KB |
Output is correct |
7 |
Correct |
55 ms |
47480 KB |
Output is correct |
8 |
Correct |
47 ms |
47480 KB |
Output is correct |
9 |
Correct |
47 ms |
47480 KB |
Output is correct |
10 |
Correct |
47 ms |
47480 KB |
Output is correct |
11 |
Correct |
47 ms |
47480 KB |
Output is correct |
12 |
Correct |
47 ms |
47480 KB |
Output is correct |
13 |
Correct |
55 ms |
47608 KB |
Output is correct |
14 |
Correct |
53 ms |
47480 KB |
Output is correct |
15 |
Correct |
47 ms |
47480 KB |
Output is correct |
16 |
Correct |
54 ms |
47480 KB |
Output is correct |
17 |
Correct |
46 ms |
47480 KB |
Output is correct |
18 |
Correct |
47 ms |
47480 KB |
Output is correct |
19 |
Correct |
62 ms |
48000 KB |
Output is correct |
20 |
Correct |
65 ms |
48036 KB |
Output is correct |
21 |
Correct |
62 ms |
48052 KB |
Output is correct |
22 |
Correct |
62 ms |
48028 KB |
Output is correct |
23 |
Correct |
60 ms |
48056 KB |
Output is correct |
24 |
Correct |
61 ms |
48056 KB |
Output is correct |
25 |
Correct |
61 ms |
48056 KB |
Output is correct |
26 |
Correct |
60 ms |
48056 KB |
Output is correct |
27 |
Correct |
59 ms |
48056 KB |
Output is correct |
28 |
Correct |
60 ms |
48056 KB |
Output is correct |
29 |
Correct |
61 ms |
48356 KB |
Output is correct |
30 |
Correct |
126 ms |
49520 KB |
Output is correct |
31 |
Correct |
194 ms |
50796 KB |
Output is correct |
32 |
Correct |
178 ms |
50928 KB |
Output is correct |
33 |
Correct |
178 ms |
50848 KB |
Output is correct |
34 |
Correct |
178 ms |
50796 KB |
Output is correct |
35 |
Correct |
178 ms |
50796 KB |
Output is correct |
36 |
Correct |
181 ms |
50924 KB |
Output is correct |
37 |
Correct |
178 ms |
50788 KB |
Output is correct |
38 |
Correct |
168 ms |
50924 KB |
Output is correct |
39 |
Correct |
162 ms |
50872 KB |
Output is correct |
40 |
Correct |
164 ms |
50920 KB |
Output is correct |
41 |
Correct |
162 ms |
50924 KB |
Output is correct |
42 |
Correct |
163 ms |
50924 KB |
Output is correct |
43 |
Correct |
163 ms |
50928 KB |
Output is correct |
44 |
Correct |
157 ms |
50840 KB |
Output is correct |
45 |
Correct |
165 ms |
50908 KB |
Output is correct |
46 |
Correct |
166 ms |
50892 KB |
Output is correct |
47 |
Correct |
523 ms |
60708 KB |
Output is correct |
48 |
Correct |
1898 ms |
86252 KB |
Output is correct |
49 |
Correct |
2041 ms |
89548 KB |
Output is correct |
50 |
Correct |
2052 ms |
89548 KB |
Output is correct |
51 |
Correct |
2142 ms |
89548 KB |
Output is correct |
52 |
Correct |
2071 ms |
89580 KB |
Output is correct |
53 |
Correct |
2005 ms |
89636 KB |
Output is correct |
54 |
Correct |
1923 ms |
89680 KB |
Output is correct |
55 |
Correct |
1991 ms |
89680 KB |
Output is correct |
56 |
Correct |
1905 ms |
89776 KB |
Output is correct |
57 |
Correct |
1976 ms |
89804 KB |
Output is correct |
58 |
Correct |
1914 ms |
89652 KB |
Output is correct |
59 |
Correct |
1847 ms |
88448 KB |
Output is correct |
60 |
Correct |
1803 ms |
88496 KB |
Output is correct |
61 |
Correct |
1804 ms |
88396 KB |
Output is correct |
62 |
Correct |
1743 ms |
88396 KB |
Output is correct |
63 |
Correct |
1734 ms |
88368 KB |
Output is correct |
64 |
Correct |
1768 ms |
88156 KB |
Output is correct |
65 |
Correct |
1596 ms |
88028 KB |
Output is correct |
66 |
Correct |
1596 ms |
88192 KB |
Output is correct |
67 |
Correct |
1640 ms |
88140 KB |
Output is correct |