#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 12, inf = 1e8;
int n, m, L[maxn * 4], R[maxn * 4], num[maxn * 4], mx[maxn * 4];
vector <int> ans;
vector <pair<int, int>> pos;
map <pair<int, int>, int> cnv;
void make_tree(int l, int r, int ind){
int mid = (l + r) / 2;
L[ind] = l;
R[ind] = r;
if(l == r)
return;
make_tree(l, mid, ind * 2);
make_tree(mid + 1, r, ind * 2 + 1);
}
void update_tree(int l, int r, int u, int k){
if(r < L[u] || R[u] < l)
return;
if(l <= L[u] && R[u] <= r){
num[u] += k;
mx[u] += k;
return;
}
update_tree(l, r, u * 2, k);
update_tree(l, r, u * 2 + 1, k);
mx[u] = max(mx[u * 2], mx[u * 2 + 1]) + num[u];
}
int get_max(int l, int r, int u){
if(r < L[u] || R[u] < l)
return 0;
if(l <= L[u] && R[u] <= r)
return mx[u];
return max(get_max(l, r, u * 2), get_max(l, r, u * 2 + 1)) + num[u];
}
void set_tree(int l, int k){
int x = get_max(l, l, 1);
update_tree(l, l, 1, k - x);
}
vector <int> countScans(vector <int> a, vector <int> y, vector <int> x){
n = a.size();
m = x.size();
for(int i = 0; i < m; i++)
pos.push_back(make_pair(x[i], y[i]));
for(int i = 0; i < n; i++)
pos.push_back(make_pair(a[i], i));
sort(pos.begin(), pos.end());
int len = 1;
for(auto i: pos)
if(cnv[i] == 0){
cnv[i] = len;
len += 1;
}
make_tree(0, len, 1);
for(int i = 0; i < n; i++){
int now = cnv[make_pair(a[i], i)];
update_tree(now + 1, len, 1, -1);
update_tree(now, now, 1, i);
// cout << now + 1 << ' ' << len << endl;
// cout << now << endl << endl;
}
// cout << get_max(0, len, 1) << endl;
// cout << endl;
for(int i = 0; i < m; i++){
int now = cnv[make_pair(a[y[i]], y[i])];
update_tree(now + 1, len, 1, 1);
update_tree(now, now, 1, -y[i]);
now = cnv[make_pair(x[i], y[i])];
update_tree(now + 1, len, 1, -1);
update_tree(now, now, 1, y[i]);
a[y[i]] = x[i];
ans.push_back(get_max(0, len, 1));
}
return ans;
}
/*
int main(){
vector <int> a, x, y;
int n, m;
cin >> n >> m;
for(int i = 0; i < n; i++){
int b;
cin >> b;
a.push_back(b);
}
for(int i = 0; i < m; i++){
int b, c;
cin >> b >> c;
x.push_back(b);
y.push_back(c);
}
countScans(a, x, y);
for(int i: ans)
cout << i << ' ';
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
724 KB |
Output is correct |
4 |
Correct |
5 ms |
784 KB |
Output is correct |
5 |
Correct |
7 ms |
724 KB |
Output is correct |
6 |
Correct |
5 ms |
724 KB |
Output is correct |
7 |
Correct |
5 ms |
724 KB |
Output is correct |
8 |
Correct |
5 ms |
724 KB |
Output is correct |
9 |
Correct |
5 ms |
724 KB |
Output is correct |
10 |
Correct |
4 ms |
724 KB |
Output is correct |
11 |
Correct |
5 ms |
724 KB |
Output is correct |
12 |
Correct |
5 ms |
724 KB |
Output is correct |
13 |
Correct |
5 ms |
724 KB |
Output is correct |
14 |
Correct |
4 ms |
724 KB |
Output is correct |
15 |
Correct |
5 ms |
724 KB |
Output is correct |
16 |
Correct |
5 ms |
724 KB |
Output is correct |
17 |
Correct |
4 ms |
724 KB |
Output is correct |
18 |
Correct |
4 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
724 KB |
Output is correct |
4 |
Correct |
5 ms |
784 KB |
Output is correct |
5 |
Correct |
7 ms |
724 KB |
Output is correct |
6 |
Correct |
5 ms |
724 KB |
Output is correct |
7 |
Correct |
5 ms |
724 KB |
Output is correct |
8 |
Correct |
5 ms |
724 KB |
Output is correct |
9 |
Correct |
5 ms |
724 KB |
Output is correct |
10 |
Correct |
4 ms |
724 KB |
Output is correct |
11 |
Correct |
5 ms |
724 KB |
Output is correct |
12 |
Correct |
5 ms |
724 KB |
Output is correct |
13 |
Correct |
5 ms |
724 KB |
Output is correct |
14 |
Correct |
4 ms |
724 KB |
Output is correct |
15 |
Correct |
5 ms |
724 KB |
Output is correct |
16 |
Correct |
5 ms |
724 KB |
Output is correct |
17 |
Correct |
4 ms |
724 KB |
Output is correct |
18 |
Correct |
4 ms |
724 KB |
Output is correct |
19 |
Correct |
20 ms |
2004 KB |
Output is correct |
20 |
Correct |
26 ms |
2208 KB |
Output is correct |
21 |
Correct |
25 ms |
2420 KB |
Output is correct |
22 |
Correct |
23 ms |
2168 KB |
Output is correct |
23 |
Correct |
20 ms |
2104 KB |
Output is correct |
24 |
Correct |
21 ms |
2044 KB |
Output is correct |
25 |
Correct |
22 ms |
2040 KB |
Output is correct |
26 |
Correct |
22 ms |
1996 KB |
Output is correct |
27 |
Correct |
20 ms |
2004 KB |
Output is correct |
28 |
Correct |
19 ms |
2040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
3700 KB |
Output is correct |
2 |
Correct |
121 ms |
7704 KB |
Output is correct |
3 |
Correct |
244 ms |
13012 KB |
Output is correct |
4 |
Correct |
241 ms |
13004 KB |
Output is correct |
5 |
Correct |
259 ms |
12996 KB |
Output is correct |
6 |
Correct |
243 ms |
12900 KB |
Output is correct |
7 |
Correct |
210 ms |
12892 KB |
Output is correct |
8 |
Correct |
212 ms |
12912 KB |
Output is correct |
9 |
Correct |
237 ms |
12912 KB |
Output is correct |
10 |
Correct |
140 ms |
8120 KB |
Output is correct |
11 |
Correct |
130 ms |
8128 KB |
Output is correct |
12 |
Correct |
131 ms |
8208 KB |
Output is correct |
13 |
Correct |
144 ms |
8096 KB |
Output is correct |
14 |
Correct |
127 ms |
8184 KB |
Output is correct |
15 |
Correct |
129 ms |
8192 KB |
Output is correct |
16 |
Correct |
118 ms |
8132 KB |
Output is correct |
17 |
Correct |
118 ms |
8296 KB |
Output is correct |
18 |
Correct |
128 ms |
8112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
724 KB |
Output is correct |
4 |
Correct |
5 ms |
784 KB |
Output is correct |
5 |
Correct |
7 ms |
724 KB |
Output is correct |
6 |
Correct |
5 ms |
724 KB |
Output is correct |
7 |
Correct |
5 ms |
724 KB |
Output is correct |
8 |
Correct |
5 ms |
724 KB |
Output is correct |
9 |
Correct |
5 ms |
724 KB |
Output is correct |
10 |
Correct |
4 ms |
724 KB |
Output is correct |
11 |
Correct |
5 ms |
724 KB |
Output is correct |
12 |
Correct |
5 ms |
724 KB |
Output is correct |
13 |
Correct |
5 ms |
724 KB |
Output is correct |
14 |
Correct |
4 ms |
724 KB |
Output is correct |
15 |
Correct |
5 ms |
724 KB |
Output is correct |
16 |
Correct |
5 ms |
724 KB |
Output is correct |
17 |
Correct |
4 ms |
724 KB |
Output is correct |
18 |
Correct |
4 ms |
724 KB |
Output is correct |
19 |
Correct |
20 ms |
2004 KB |
Output is correct |
20 |
Correct |
26 ms |
2208 KB |
Output is correct |
21 |
Correct |
25 ms |
2420 KB |
Output is correct |
22 |
Correct |
23 ms |
2168 KB |
Output is correct |
23 |
Correct |
20 ms |
2104 KB |
Output is correct |
24 |
Correct |
21 ms |
2044 KB |
Output is correct |
25 |
Correct |
22 ms |
2040 KB |
Output is correct |
26 |
Correct |
22 ms |
1996 KB |
Output is correct |
27 |
Correct |
20 ms |
2004 KB |
Output is correct |
28 |
Correct |
19 ms |
2040 KB |
Output is correct |
29 |
Correct |
42 ms |
3700 KB |
Output is correct |
30 |
Correct |
121 ms |
7704 KB |
Output is correct |
31 |
Correct |
244 ms |
13012 KB |
Output is correct |
32 |
Correct |
241 ms |
13004 KB |
Output is correct |
33 |
Correct |
259 ms |
12996 KB |
Output is correct |
34 |
Correct |
243 ms |
12900 KB |
Output is correct |
35 |
Correct |
210 ms |
12892 KB |
Output is correct |
36 |
Correct |
212 ms |
12912 KB |
Output is correct |
37 |
Correct |
237 ms |
12912 KB |
Output is correct |
38 |
Correct |
140 ms |
8120 KB |
Output is correct |
39 |
Correct |
130 ms |
8128 KB |
Output is correct |
40 |
Correct |
131 ms |
8208 KB |
Output is correct |
41 |
Correct |
144 ms |
8096 KB |
Output is correct |
42 |
Correct |
127 ms |
8184 KB |
Output is correct |
43 |
Correct |
129 ms |
8192 KB |
Output is correct |
44 |
Correct |
118 ms |
8132 KB |
Output is correct |
45 |
Correct |
118 ms |
8296 KB |
Output is correct |
46 |
Correct |
128 ms |
8112 KB |
Output is correct |
47 |
Correct |
1024 ms |
42780 KB |
Output is correct |
48 |
Correct |
3914 ms |
112220 KB |
Output is correct |
49 |
Correct |
4304 ms |
132296 KB |
Output is correct |
50 |
Correct |
4155 ms |
132300 KB |
Output is correct |
51 |
Correct |
4325 ms |
132320 KB |
Output is correct |
52 |
Correct |
4256 ms |
132404 KB |
Output is correct |
53 |
Correct |
4389 ms |
132300 KB |
Output is correct |
54 |
Correct |
3869 ms |
132388 KB |
Output is correct |
55 |
Correct |
4059 ms |
132444 KB |
Output is correct |
56 |
Correct |
3694 ms |
132404 KB |
Output is correct |
57 |
Correct |
3915 ms |
132660 KB |
Output is correct |
58 |
Correct |
3697 ms |
132660 KB |
Output is correct |
59 |
Correct |
3265 ms |
123420 KB |
Output is correct |
60 |
Correct |
3316 ms |
123328 KB |
Output is correct |
61 |
Correct |
3334 ms |
123256 KB |
Output is correct |
62 |
Correct |
3134 ms |
119264 KB |
Output is correct |
63 |
Correct |
2958 ms |
119116 KB |
Output is correct |
64 |
Correct |
3015 ms |
119184 KB |
Output is correct |
65 |
Correct |
2773 ms |
115112 KB |
Output is correct |
66 |
Correct |
2768 ms |
115532 KB |
Output is correct |
67 |
Correct |
2763 ms |
115164 KB |
Output is correct |