#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 1e5 + 01;
vector<ii> rrh;
int f[N], T[N << 2], lazy[N << 2];
void push(int s, int l, int r) {
if (!lazy[s]) return;
T[s] += lazy[s];
if (l != r) {
lazy[s << 1] += lazy[s];
lazy[s << 1 | 1] += lazy[s];
}
lazy[s] = 0;
}
void up(int s, int l, int r, int from, int to, int val) {
push(s, l, r);
if (l > to || r < from) return;
if (from <= l && r <= to) {
lazy[s] += val;
push(s, l, r);
return;
}
int mid = l + r >> 1;
up(s << 1, l, mid, from, to, val);
up(s << 1 | 1, mid + 1, r, from, to, val);
T[s] = max(T[s << 1], T[s << 1 | 1]);
}
int id(int pos, int val) {
return upper_bound(rrh.begin(), rrh.end(), make_pair(val, pos)) - rrh.begin();
}
vector<int> countScans(vector<int> a, vector<int> pos, vector<int> val) {
vector<int> ans(pos.size());
int n = a.size();
for(int i = 0; i < n; i++) rrh.emplace_back(a[i], i);
for(int i = 0; i < pos.size(); i++) rrh.emplace_back(val[i], pos[i]);
sort(rrh.begin(), rrh.end());
rrh.resize(unique(rrh.begin(), rrh.end()) - rrh.begin());
int m = rrh.size();
for(int i = 0; i < n; i++) {
int p = id(i, a[i]);
up(1, 1, m, p, p, i + 1);
up(1, 1, m, p, m, -1);
}
for(int i = 0; i < pos.size(); i++) {
int p = id(pos[i], a[pos[i]]);
up(1, 1, m, p, p, -pos[i] - 1);
up(1, 1, m, p, m, 1);
a[pos[i]] = val[i];
p = id(pos[i], val[i]);
up(1, 1, m, p, p, pos[i] + 1);
up(1, 1, m, p, m, -1);
ans[i] = T[1];
}
return ans;
}
#ifdef ngu
int main() {
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
int n, q; cin >> n >> q;
vector<int> a(n), x(q), 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> ret = countScans(a, x, v);
for(int &j : ret) cout << j << endl;
}
#endif // ngu
Compilation message
bubblesort2.cpp: In function 'void up(int, int, int, int, int, int)':
bubblesort2.cpp:29:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
29 | int mid = l + r >> 1;
| ~~^~~
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:44:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i = 0; i < pos.size(); i++) rrh.emplace_back(val[i], pos[i]);
| ~~^~~~~~~~~~~~
bubblesort2.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i = 0; i < pos.size(); i++) {
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
5 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
496 KB |
Output is correct |
13 |
Correct |
5 ms |
404 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
15 |
Correct |
6 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
468 KB |
Output is correct |
17 |
Correct |
4 ms |
468 KB |
Output is correct |
18 |
Correct |
4 ms |
496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
5 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
496 KB |
Output is correct |
13 |
Correct |
5 ms |
404 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
15 |
Correct |
6 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
468 KB |
Output is correct |
17 |
Correct |
4 ms |
468 KB |
Output is correct |
18 |
Correct |
4 ms |
496 KB |
Output is correct |
19 |
Correct |
17 ms |
980 KB |
Output is correct |
20 |
Correct |
19 ms |
1040 KB |
Output is correct |
21 |
Correct |
18 ms |
1052 KB |
Output is correct |
22 |
Correct |
20 ms |
1048 KB |
Output is correct |
23 |
Correct |
19 ms |
980 KB |
Output is correct |
24 |
Correct |
24 ms |
1060 KB |
Output is correct |
25 |
Correct |
17 ms |
1012 KB |
Output is correct |
26 |
Correct |
16 ms |
980 KB |
Output is correct |
27 |
Correct |
16 ms |
1060 KB |
Output is correct |
28 |
Correct |
16 ms |
1052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
1464 KB |
Output is correct |
2 |
Correct |
83 ms |
2760 KB |
Output is correct |
3 |
Correct |
137 ms |
4644 KB |
Output is correct |
4 |
Correct |
134 ms |
4584 KB |
Output is correct |
5 |
Correct |
152 ms |
4640 KB |
Output is correct |
6 |
Correct |
153 ms |
4640 KB |
Output is correct |
7 |
Correct |
141 ms |
4644 KB |
Output is correct |
8 |
Correct |
126 ms |
4564 KB |
Output is correct |
9 |
Correct |
135 ms |
4584 KB |
Output is correct |
10 |
Correct |
115 ms |
3616 KB |
Output is correct |
11 |
Correct |
105 ms |
3740 KB |
Output is correct |
12 |
Correct |
102 ms |
3624 KB |
Output is correct |
13 |
Correct |
135 ms |
3756 KB |
Output is correct |
14 |
Correct |
116 ms |
3620 KB |
Output is correct |
15 |
Correct |
103 ms |
3496 KB |
Output is correct |
16 |
Correct |
103 ms |
3620 KB |
Output is correct |
17 |
Correct |
108 ms |
3612 KB |
Output is correct |
18 |
Correct |
118 ms |
3620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
5 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
496 KB |
Output is correct |
13 |
Correct |
5 ms |
404 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
15 |
Correct |
6 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
468 KB |
Output is correct |
17 |
Correct |
4 ms |
468 KB |
Output is correct |
18 |
Correct |
4 ms |
496 KB |
Output is correct |
19 |
Correct |
17 ms |
980 KB |
Output is correct |
20 |
Correct |
19 ms |
1040 KB |
Output is correct |
21 |
Correct |
18 ms |
1052 KB |
Output is correct |
22 |
Correct |
20 ms |
1048 KB |
Output is correct |
23 |
Correct |
19 ms |
980 KB |
Output is correct |
24 |
Correct |
24 ms |
1060 KB |
Output is correct |
25 |
Correct |
17 ms |
1012 KB |
Output is correct |
26 |
Correct |
16 ms |
980 KB |
Output is correct |
27 |
Correct |
16 ms |
1060 KB |
Output is correct |
28 |
Correct |
16 ms |
1052 KB |
Output is correct |
29 |
Correct |
31 ms |
1464 KB |
Output is correct |
30 |
Correct |
83 ms |
2760 KB |
Output is correct |
31 |
Correct |
137 ms |
4644 KB |
Output is correct |
32 |
Correct |
134 ms |
4584 KB |
Output is correct |
33 |
Correct |
152 ms |
4640 KB |
Output is correct |
34 |
Correct |
153 ms |
4640 KB |
Output is correct |
35 |
Correct |
141 ms |
4644 KB |
Output is correct |
36 |
Correct |
126 ms |
4564 KB |
Output is correct |
37 |
Correct |
135 ms |
4584 KB |
Output is correct |
38 |
Correct |
115 ms |
3616 KB |
Output is correct |
39 |
Correct |
105 ms |
3740 KB |
Output is correct |
40 |
Correct |
102 ms |
3624 KB |
Output is correct |
41 |
Correct |
135 ms |
3756 KB |
Output is correct |
42 |
Correct |
116 ms |
3620 KB |
Output is correct |
43 |
Correct |
103 ms |
3496 KB |
Output is correct |
44 |
Correct |
103 ms |
3620 KB |
Output is correct |
45 |
Correct |
108 ms |
3612 KB |
Output is correct |
46 |
Correct |
118 ms |
3620 KB |
Output is correct |
47 |
Runtime error |
94 ms |
13632 KB |
Execution killed with signal 11 |
48 |
Halted |
0 ms |
0 KB |
- |