#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 1e6 + 01;
vector<ii> rrh;
int 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++) {
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
500 KB |
Output is correct |
4 |
Correct |
5 ms |
468 KB |
Output is correct |
5 |
Correct |
5 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
504 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
7 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
5 ms |
468 KB |
Output is correct |
14 |
Correct |
6 ms |
496 KB |
Output is correct |
15 |
Correct |
4 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 |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
500 KB |
Output is correct |
4 |
Correct |
5 ms |
468 KB |
Output is correct |
5 |
Correct |
5 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
504 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
7 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
5 ms |
468 KB |
Output is correct |
14 |
Correct |
6 ms |
496 KB |
Output is correct |
15 |
Correct |
4 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 |
468 KB |
Output is correct |
19 |
Correct |
20 ms |
980 KB |
Output is correct |
20 |
Correct |
25 ms |
1036 KB |
Output is correct |
21 |
Correct |
19 ms |
1056 KB |
Output is correct |
22 |
Correct |
17 ms |
1060 KB |
Output is correct |
23 |
Correct |
19 ms |
1052 KB |
Output is correct |
24 |
Correct |
17 ms |
1048 KB |
Output is correct |
25 |
Correct |
20 ms |
1068 KB |
Output is correct |
26 |
Correct |
16 ms |
980 KB |
Output is correct |
27 |
Correct |
16 ms |
1084 KB |
Output is correct |
28 |
Correct |
16 ms |
1056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1452 KB |
Output is correct |
2 |
Correct |
75 ms |
2764 KB |
Output is correct |
3 |
Correct |
131 ms |
4616 KB |
Output is correct |
4 |
Correct |
196 ms |
4556 KB |
Output is correct |
5 |
Correct |
143 ms |
4672 KB |
Output is correct |
6 |
Correct |
130 ms |
4648 KB |
Output is correct |
7 |
Correct |
148 ms |
4544 KB |
Output is correct |
8 |
Correct |
151 ms |
4660 KB |
Output is correct |
9 |
Correct |
131 ms |
4660 KB |
Output is correct |
10 |
Correct |
104 ms |
3624 KB |
Output is correct |
11 |
Correct |
103 ms |
3544 KB |
Output is correct |
12 |
Correct |
109 ms |
3496 KB |
Output is correct |
13 |
Correct |
116 ms |
3660 KB |
Output is correct |
14 |
Correct |
122 ms |
3572 KB |
Output is correct |
15 |
Correct |
119 ms |
3628 KB |
Output is correct |
16 |
Correct |
99 ms |
3536 KB |
Output is correct |
17 |
Correct |
101 ms |
3556 KB |
Output is correct |
18 |
Correct |
109 ms |
3632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
500 KB |
Output is correct |
4 |
Correct |
5 ms |
468 KB |
Output is correct |
5 |
Correct |
5 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
504 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
7 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
5 ms |
468 KB |
Output is correct |
14 |
Correct |
6 ms |
496 KB |
Output is correct |
15 |
Correct |
4 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 |
468 KB |
Output is correct |
19 |
Correct |
20 ms |
980 KB |
Output is correct |
20 |
Correct |
25 ms |
1036 KB |
Output is correct |
21 |
Correct |
19 ms |
1056 KB |
Output is correct |
22 |
Correct |
17 ms |
1060 KB |
Output is correct |
23 |
Correct |
19 ms |
1052 KB |
Output is correct |
24 |
Correct |
17 ms |
1048 KB |
Output is correct |
25 |
Correct |
20 ms |
1068 KB |
Output is correct |
26 |
Correct |
16 ms |
980 KB |
Output is correct |
27 |
Correct |
16 ms |
1084 KB |
Output is correct |
28 |
Correct |
16 ms |
1056 KB |
Output is correct |
29 |
Correct |
23 ms |
1452 KB |
Output is correct |
30 |
Correct |
75 ms |
2764 KB |
Output is correct |
31 |
Correct |
131 ms |
4616 KB |
Output is correct |
32 |
Correct |
196 ms |
4556 KB |
Output is correct |
33 |
Correct |
143 ms |
4672 KB |
Output is correct |
34 |
Correct |
130 ms |
4648 KB |
Output is correct |
35 |
Correct |
148 ms |
4544 KB |
Output is correct |
36 |
Correct |
151 ms |
4660 KB |
Output is correct |
37 |
Correct |
131 ms |
4660 KB |
Output is correct |
38 |
Correct |
104 ms |
3624 KB |
Output is correct |
39 |
Correct |
103 ms |
3544 KB |
Output is correct |
40 |
Correct |
109 ms |
3496 KB |
Output is correct |
41 |
Correct |
116 ms |
3660 KB |
Output is correct |
42 |
Correct |
122 ms |
3572 KB |
Output is correct |
43 |
Correct |
119 ms |
3628 KB |
Output is correct |
44 |
Correct |
99 ms |
3536 KB |
Output is correct |
45 |
Correct |
101 ms |
3556 KB |
Output is correct |
46 |
Correct |
109 ms |
3632 KB |
Output is correct |
47 |
Correct |
509 ms |
14944 KB |
Output is correct |
48 |
Correct |
2087 ms |
48704 KB |
Output is correct |
49 |
Correct |
2250 ms |
51296 KB |
Output is correct |
50 |
Correct |
2197 ms |
51296 KB |
Output is correct |
51 |
Correct |
2219 ms |
51304 KB |
Output is correct |
52 |
Correct |
2259 ms |
51292 KB |
Output is correct |
53 |
Correct |
2176 ms |
51368 KB |
Output is correct |
54 |
Correct |
2041 ms |
51560 KB |
Output is correct |
55 |
Correct |
2192 ms |
51488 KB |
Output is correct |
56 |
Correct |
1978 ms |
51656 KB |
Output is correct |
57 |
Correct |
2112 ms |
51540 KB |
Output is correct |
58 |
Correct |
2106 ms |
51464 KB |
Output is correct |
59 |
Correct |
1859 ms |
50124 KB |
Output is correct |
60 |
Correct |
1825 ms |
50116 KB |
Output is correct |
61 |
Correct |
1867 ms |
50116 KB |
Output is correct |
62 |
Correct |
1869 ms |
49976 KB |
Output is correct |
63 |
Correct |
1723 ms |
49972 KB |
Output is correct |
64 |
Correct |
1761 ms |
49972 KB |
Output is correct |
65 |
Correct |
1757 ms |
49832 KB |
Output is correct |
66 |
Correct |
1652 ms |
49828 KB |
Output is correct |
67 |
Correct |
1749 ms |
49836 KB |
Output is correct |