#include<bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int N = (1 << 20);
int cnt[2 * N];
int add[2 * N];
vector<int> maxf(2 * N, -inf);
int lb[2 * N];
int rb[2 * N];
void build(int v = 1, int l = 0, int r = N - 1) {
lb[v] = l;
rb[v] = r;
if(l == r) {
return;
}
int m = (l + r) / 2;
build(2 * v, l, m);
build(2 * v + 1, m + 1, r);
}
void setpush(int v, int x) {
maxf[v] += x;
add[v] += x;
}
void push(int v) {
if(!add[v] || lb[v] == rb[v]) return;
setpush(2 * v, add[v]);
setpush(2 * v + 1, add[v]);
add[v] = 0;
}
void update(int ql, int qr, int x, int v = 1) {
if(rb[v] < ql || lb[v] > qr)
return;
if(ql <= lb[v] && rb[v] <= qr) {
setpush(v, x);
return;
}
push(v);
update(ql, qr, x, 2 * v);
update(ql, qr, x, 2 * v + 1);
cnt[v] = cnt[2 * v] + cnt[2 * v + 1];
maxf[v] = max(maxf[2 * v], maxf[2 * v + 1]);
}
int get_cnt(int ql, int qr, int v = 1) {
if(ql > qr || rb[v] < ql || lb[v] > qr)
return 0;
if(ql <= lb[v] && rb[v] <= qr)
return cnt[v];
push(v);
return get_cnt(ql, qr, 2 * v) + get_cnt(ql, qr, 2 * v + 1);
}
void change(int pos, int x, int y, int v = 1) {
if(rb[v] < pos || lb[v] > pos)
return;
if(lb[v] == rb[v]) {
cnt[v] = x;
maxf[v] = y;
return;
}
push(v);
change(pos, x, y, 2 * v);
change(pos, x, y, 2 * v + 1);
cnt[v] = cnt[v * 2] + cnt[2 * v + 1];
maxf[v] = max(maxf[2 * v], maxf[2 * v + 1]);
}
void insert(int pos, int val) {
change(pos, 1, val - get_cnt(0, pos - 1));
update(pos + 1, N - 1, -1);
}
void erase(int pos) {
change(pos, 0, -inf);
update(pos + 1, N - 1, +1);
}
int find(vector<pair<int, int>> &v, pair<int, int> x) {
int l = -1, r = (int)v.size();
while(r - l > 1) {
int m = (l + r) / 2;
if(v[m] < x) l = m;
else r = m;
}
if(r == (int)v.size() || v[r] != x) return -1;
return r;
}
int n, q;
void compress(vector<int> &a, vector<pair<int, int>> &b) {
int n = (int)a.size();
vector<pair<int, int>> mp;
for(int i = 0; i < n; i++) {
mp.push_back(make_pair(a[i], i));
}
for(auto g : b)
mp.push_back(g);
sort(mp.begin(), mp.end());
int m = (int)mp.size();
int w[m];
int k = 0;
for(int i = 0; i < m; i++) {
if(i && mp[i] != mp[i - 1])
w[i] = ++k;
else w[i] = k;
}
for(int i = 0; i < n; i++) {
a[i] = w[find(mp, make_pair(a[i], i))];
}
for(auto &g : b) {
g.first = w[find(mp, g)];
}
mp.clear();
}
vector<int> countScans(vector<int> a, vector<int> X, vector<int> V) {
build();
n = (int)a.size();
q = (int)X.size();
vector<int> res(q);
vector<pair<int, int>> updates;
for(int i = 0; i < q; i++)
updates.push_back({V[i], X[i]});
compress(a, updates);
for(int i = 0; i < n; i++) {
insert(a[i], i);
}
for(int i = 0; i < q; i++) {
int pos = updates[i].second, val = updates[i].first;
erase(a[pos]);
insert(val, pos);
// if(a[pos] < val) update(a[pos] + 1, val, +1);
// else update(val + 1, a[pos], -1);
a[pos] = val;
res[i] = maxf[1];
}
return res;
}
// int main() {
// ios::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
// int n, q;
// cin >> n >> q;
// vector<int> A(n);
// vector<int> X(q);
// vector<int> V(q);
// for(int i = 0; i < n; i++) {
// cin >> A[i];
// }
// for(int i = 0; i < q; i++) {
// cin >> X[i] >> V[i];
// }
// vector<int> res = countScans(A, X, V);
// for(int c : res)
// cout << c << '\n';
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
25044 KB |
Output is correct |
2 |
Correct |
15 ms |
25068 KB |
Output is correct |
3 |
Correct |
18 ms |
25300 KB |
Output is correct |
4 |
Correct |
21 ms |
25304 KB |
Output is correct |
5 |
Correct |
18 ms |
25300 KB |
Output is correct |
6 |
Correct |
18 ms |
25176 KB |
Output is correct |
7 |
Correct |
21 ms |
25308 KB |
Output is correct |
8 |
Correct |
17 ms |
25196 KB |
Output is correct |
9 |
Correct |
19 ms |
25196 KB |
Output is correct |
10 |
Correct |
18 ms |
25252 KB |
Output is correct |
11 |
Correct |
18 ms |
25168 KB |
Output is correct |
12 |
Correct |
18 ms |
25292 KB |
Output is correct |
13 |
Correct |
20 ms |
25220 KB |
Output is correct |
14 |
Correct |
18 ms |
25188 KB |
Output is correct |
15 |
Correct |
18 ms |
25248 KB |
Output is correct |
16 |
Correct |
17 ms |
25220 KB |
Output is correct |
17 |
Correct |
18 ms |
25172 KB |
Output is correct |
18 |
Correct |
21 ms |
25284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
25044 KB |
Output is correct |
2 |
Correct |
15 ms |
25068 KB |
Output is correct |
3 |
Correct |
18 ms |
25300 KB |
Output is correct |
4 |
Correct |
21 ms |
25304 KB |
Output is correct |
5 |
Correct |
18 ms |
25300 KB |
Output is correct |
6 |
Correct |
18 ms |
25176 KB |
Output is correct |
7 |
Correct |
21 ms |
25308 KB |
Output is correct |
8 |
Correct |
17 ms |
25196 KB |
Output is correct |
9 |
Correct |
19 ms |
25196 KB |
Output is correct |
10 |
Correct |
18 ms |
25252 KB |
Output is correct |
11 |
Correct |
18 ms |
25168 KB |
Output is correct |
12 |
Correct |
18 ms |
25292 KB |
Output is correct |
13 |
Correct |
20 ms |
25220 KB |
Output is correct |
14 |
Correct |
18 ms |
25188 KB |
Output is correct |
15 |
Correct |
18 ms |
25248 KB |
Output is correct |
16 |
Correct |
17 ms |
25220 KB |
Output is correct |
17 |
Correct |
18 ms |
25172 KB |
Output is correct |
18 |
Correct |
21 ms |
25284 KB |
Output is correct |
19 |
Correct |
30 ms |
25888 KB |
Output is correct |
20 |
Correct |
33 ms |
25964 KB |
Output is correct |
21 |
Correct |
33 ms |
25896 KB |
Output is correct |
22 |
Correct |
42 ms |
25908 KB |
Output is correct |
23 |
Correct |
33 ms |
25912 KB |
Output is correct |
24 |
Correct |
34 ms |
25868 KB |
Output is correct |
25 |
Correct |
32 ms |
25896 KB |
Output is correct |
26 |
Correct |
35 ms |
25876 KB |
Output is correct |
27 |
Correct |
32 ms |
25892 KB |
Output is correct |
28 |
Correct |
33 ms |
25912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
26180 KB |
Output is correct |
2 |
Correct |
100 ms |
27636 KB |
Output is correct |
3 |
Correct |
149 ms |
29364 KB |
Output is correct |
4 |
Correct |
153 ms |
29432 KB |
Output is correct |
5 |
Correct |
146 ms |
29332 KB |
Output is correct |
6 |
Correct |
155 ms |
29364 KB |
Output is correct |
7 |
Correct |
144 ms |
29380 KB |
Output is correct |
8 |
Correct |
148 ms |
29324 KB |
Output is correct |
9 |
Correct |
144 ms |
29412 KB |
Output is correct |
10 |
Correct |
131 ms |
28756 KB |
Output is correct |
11 |
Correct |
126 ms |
28696 KB |
Output is correct |
12 |
Correct |
125 ms |
28732 KB |
Output is correct |
13 |
Correct |
134 ms |
28748 KB |
Output is correct |
14 |
Correct |
124 ms |
28788 KB |
Output is correct |
15 |
Correct |
124 ms |
28720 KB |
Output is correct |
16 |
Correct |
135 ms |
28732 KB |
Output is correct |
17 |
Correct |
120 ms |
28716 KB |
Output is correct |
18 |
Correct |
119 ms |
28720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
25044 KB |
Output is correct |
2 |
Correct |
15 ms |
25068 KB |
Output is correct |
3 |
Correct |
18 ms |
25300 KB |
Output is correct |
4 |
Correct |
21 ms |
25304 KB |
Output is correct |
5 |
Correct |
18 ms |
25300 KB |
Output is correct |
6 |
Correct |
18 ms |
25176 KB |
Output is correct |
7 |
Correct |
21 ms |
25308 KB |
Output is correct |
8 |
Correct |
17 ms |
25196 KB |
Output is correct |
9 |
Correct |
19 ms |
25196 KB |
Output is correct |
10 |
Correct |
18 ms |
25252 KB |
Output is correct |
11 |
Correct |
18 ms |
25168 KB |
Output is correct |
12 |
Correct |
18 ms |
25292 KB |
Output is correct |
13 |
Correct |
20 ms |
25220 KB |
Output is correct |
14 |
Correct |
18 ms |
25188 KB |
Output is correct |
15 |
Correct |
18 ms |
25248 KB |
Output is correct |
16 |
Correct |
17 ms |
25220 KB |
Output is correct |
17 |
Correct |
18 ms |
25172 KB |
Output is correct |
18 |
Correct |
21 ms |
25284 KB |
Output is correct |
19 |
Correct |
30 ms |
25888 KB |
Output is correct |
20 |
Correct |
33 ms |
25964 KB |
Output is correct |
21 |
Correct |
33 ms |
25896 KB |
Output is correct |
22 |
Correct |
42 ms |
25908 KB |
Output is correct |
23 |
Correct |
33 ms |
25912 KB |
Output is correct |
24 |
Correct |
34 ms |
25868 KB |
Output is correct |
25 |
Correct |
32 ms |
25896 KB |
Output is correct |
26 |
Correct |
35 ms |
25876 KB |
Output is correct |
27 |
Correct |
32 ms |
25892 KB |
Output is correct |
28 |
Correct |
33 ms |
25912 KB |
Output is correct |
29 |
Correct |
43 ms |
26180 KB |
Output is correct |
30 |
Correct |
100 ms |
27636 KB |
Output is correct |
31 |
Correct |
149 ms |
29364 KB |
Output is correct |
32 |
Correct |
153 ms |
29432 KB |
Output is correct |
33 |
Correct |
146 ms |
29332 KB |
Output is correct |
34 |
Correct |
155 ms |
29364 KB |
Output is correct |
35 |
Correct |
144 ms |
29380 KB |
Output is correct |
36 |
Correct |
148 ms |
29324 KB |
Output is correct |
37 |
Correct |
144 ms |
29412 KB |
Output is correct |
38 |
Correct |
131 ms |
28756 KB |
Output is correct |
39 |
Correct |
126 ms |
28696 KB |
Output is correct |
40 |
Correct |
125 ms |
28732 KB |
Output is correct |
41 |
Correct |
134 ms |
28748 KB |
Output is correct |
42 |
Correct |
124 ms |
28788 KB |
Output is correct |
43 |
Correct |
124 ms |
28720 KB |
Output is correct |
44 |
Correct |
135 ms |
28732 KB |
Output is correct |
45 |
Correct |
120 ms |
28716 KB |
Output is correct |
46 |
Correct |
119 ms |
28720 KB |
Output is correct |
47 |
Correct |
477 ms |
39612 KB |
Output is correct |
48 |
Correct |
1982 ms |
71376 KB |
Output is correct |
49 |
Correct |
2165 ms |
75068 KB |
Output is correct |
50 |
Correct |
2206 ms |
75056 KB |
Output is correct |
51 |
Correct |
2127 ms |
75100 KB |
Output is correct |
52 |
Correct |
2197 ms |
75104 KB |
Output is correct |
53 |
Correct |
2185 ms |
75104 KB |
Output is correct |
54 |
Correct |
1997 ms |
75288 KB |
Output is correct |
55 |
Correct |
2146 ms |
75416 KB |
Output is correct |
56 |
Correct |
1922 ms |
75288 KB |
Output is correct |
57 |
Correct |
2082 ms |
75252 KB |
Output is correct |
58 |
Correct |
2020 ms |
75224 KB |
Output is correct |
59 |
Correct |
1867 ms |
72008 KB |
Output is correct |
60 |
Correct |
1799 ms |
72016 KB |
Output is correct |
61 |
Correct |
1824 ms |
71976 KB |
Output is correct |
62 |
Correct |
1745 ms |
70860 KB |
Output is correct |
63 |
Correct |
1779 ms |
70888 KB |
Output is correct |
64 |
Correct |
1769 ms |
70872 KB |
Output is correct |
65 |
Correct |
1650 ms |
69772 KB |
Output is correct |
66 |
Correct |
1609 ms |
69824 KB |
Output is correct |
67 |
Correct |
1665 ms |
69760 KB |
Output is correct |