#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 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 |
4 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
852 KB |
Output is correct |
4 |
Correct |
5 ms |
852 KB |
Output is correct |
5 |
Correct |
5 ms |
852 KB |
Output is correct |
6 |
Correct |
5 ms |
836 KB |
Output is correct |
7 |
Correct |
5 ms |
896 KB |
Output is correct |
8 |
Correct |
6 ms |
848 KB |
Output is correct |
9 |
Correct |
5 ms |
836 KB |
Output is correct |
10 |
Correct |
5 ms |
724 KB |
Output is correct |
11 |
Correct |
5 ms |
724 KB |
Output is correct |
12 |
Correct |
5 ms |
708 KB |
Output is correct |
13 |
Correct |
5 ms |
712 KB |
Output is correct |
14 |
Correct |
5 ms |
724 KB |
Output is correct |
15 |
Correct |
4 ms |
724 KB |
Output is correct |
16 |
Correct |
5 ms |
724 KB |
Output is correct |
17 |
Correct |
4 ms |
740 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 |
4 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
852 KB |
Output is correct |
4 |
Correct |
5 ms |
852 KB |
Output is correct |
5 |
Correct |
5 ms |
852 KB |
Output is correct |
6 |
Correct |
5 ms |
836 KB |
Output is correct |
7 |
Correct |
5 ms |
896 KB |
Output is correct |
8 |
Correct |
6 ms |
848 KB |
Output is correct |
9 |
Correct |
5 ms |
836 KB |
Output is correct |
10 |
Correct |
5 ms |
724 KB |
Output is correct |
11 |
Correct |
5 ms |
724 KB |
Output is correct |
12 |
Correct |
5 ms |
708 KB |
Output is correct |
13 |
Correct |
5 ms |
712 KB |
Output is correct |
14 |
Correct |
5 ms |
724 KB |
Output is correct |
15 |
Correct |
4 ms |
724 KB |
Output is correct |
16 |
Correct |
5 ms |
724 KB |
Output is correct |
17 |
Correct |
4 ms |
740 KB |
Output is correct |
18 |
Correct |
4 ms |
724 KB |
Output is correct |
19 |
Correct |
24 ms |
2176 KB |
Output is correct |
20 |
Correct |
31 ms |
2372 KB |
Output is correct |
21 |
Correct |
27 ms |
2388 KB |
Output is correct |
22 |
Correct |
24 ms |
2368 KB |
Output is correct |
23 |
Correct |
27 ms |
2232 KB |
Output is correct |
24 |
Correct |
24 ms |
2260 KB |
Output is correct |
25 |
Correct |
21 ms |
2152 KB |
Output is correct |
26 |
Correct |
21 ms |
2196 KB |
Output is correct |
27 |
Correct |
19 ms |
2116 KB |
Output is correct |
28 |
Correct |
21 ms |
2108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
3792 KB |
Output is correct |
2 |
Correct |
121 ms |
8024 KB |
Output is correct |
3 |
Correct |
217 ms |
13580 KB |
Output is correct |
4 |
Correct |
234 ms |
13712 KB |
Output is correct |
5 |
Correct |
211 ms |
13472 KB |
Output is correct |
6 |
Correct |
213 ms |
13432 KB |
Output is correct |
7 |
Correct |
236 ms |
13488 KB |
Output is correct |
8 |
Correct |
244 ms |
13440 KB |
Output is correct |
9 |
Correct |
231 ms |
13656 KB |
Output is correct |
10 |
Correct |
141 ms |
8824 KB |
Output is correct |
11 |
Correct |
142 ms |
8932 KB |
Output is correct |
12 |
Correct |
141 ms |
8844 KB |
Output is correct |
13 |
Correct |
145 ms |
8816 KB |
Output is correct |
14 |
Correct |
127 ms |
8800 KB |
Output is correct |
15 |
Correct |
129 ms |
8836 KB |
Output is correct |
16 |
Correct |
128 ms |
8752 KB |
Output is correct |
17 |
Correct |
123 ms |
8780 KB |
Output is correct |
18 |
Correct |
119 ms |
8768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
4 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
852 KB |
Output is correct |
4 |
Correct |
5 ms |
852 KB |
Output is correct |
5 |
Correct |
5 ms |
852 KB |
Output is correct |
6 |
Correct |
5 ms |
836 KB |
Output is correct |
7 |
Correct |
5 ms |
896 KB |
Output is correct |
8 |
Correct |
6 ms |
848 KB |
Output is correct |
9 |
Correct |
5 ms |
836 KB |
Output is correct |
10 |
Correct |
5 ms |
724 KB |
Output is correct |
11 |
Correct |
5 ms |
724 KB |
Output is correct |
12 |
Correct |
5 ms |
708 KB |
Output is correct |
13 |
Correct |
5 ms |
712 KB |
Output is correct |
14 |
Correct |
5 ms |
724 KB |
Output is correct |
15 |
Correct |
4 ms |
724 KB |
Output is correct |
16 |
Correct |
5 ms |
724 KB |
Output is correct |
17 |
Correct |
4 ms |
740 KB |
Output is correct |
18 |
Correct |
4 ms |
724 KB |
Output is correct |
19 |
Correct |
24 ms |
2176 KB |
Output is correct |
20 |
Correct |
31 ms |
2372 KB |
Output is correct |
21 |
Correct |
27 ms |
2388 KB |
Output is correct |
22 |
Correct |
24 ms |
2368 KB |
Output is correct |
23 |
Correct |
27 ms |
2232 KB |
Output is correct |
24 |
Correct |
24 ms |
2260 KB |
Output is correct |
25 |
Correct |
21 ms |
2152 KB |
Output is correct |
26 |
Correct |
21 ms |
2196 KB |
Output is correct |
27 |
Correct |
19 ms |
2116 KB |
Output is correct |
28 |
Correct |
21 ms |
2108 KB |
Output is correct |
29 |
Correct |
37 ms |
3792 KB |
Output is correct |
30 |
Correct |
121 ms |
8024 KB |
Output is correct |
31 |
Correct |
217 ms |
13580 KB |
Output is correct |
32 |
Correct |
234 ms |
13712 KB |
Output is correct |
33 |
Correct |
211 ms |
13472 KB |
Output is correct |
34 |
Correct |
213 ms |
13432 KB |
Output is correct |
35 |
Correct |
236 ms |
13488 KB |
Output is correct |
36 |
Correct |
244 ms |
13440 KB |
Output is correct |
37 |
Correct |
231 ms |
13656 KB |
Output is correct |
38 |
Correct |
141 ms |
8824 KB |
Output is correct |
39 |
Correct |
142 ms |
8932 KB |
Output is correct |
40 |
Correct |
141 ms |
8844 KB |
Output is correct |
41 |
Correct |
145 ms |
8816 KB |
Output is correct |
42 |
Correct |
127 ms |
8800 KB |
Output is correct |
43 |
Correct |
129 ms |
8836 KB |
Output is correct |
44 |
Correct |
128 ms |
8752 KB |
Output is correct |
45 |
Correct |
123 ms |
8780 KB |
Output is correct |
46 |
Correct |
119 ms |
8768 KB |
Output is correct |
47 |
Correct |
1046 ms |
46364 KB |
Output is correct |
48 |
Runtime error |
661 ms |
195084 KB |
Execution killed with signal 11 |
49 |
Halted |
0 ms |
0 KB |
- |