#include "bubblesort2.h"
#include <vector>
#include <algorithm>
#include <map>
#include <iostream>
using namespace std;
#define ll long long
const int MX = 500005;
const ll inf = 696969696969ll;
ll st[MX * 4], lz[MX * 4];
void prop(int nd, int cl, int cr){
if(lz[nd]){
st[nd] += lz[nd];
if(cl != cr)
lz[nd * 2] += lz[nd],
lz[nd * 2 + 1] += lz[nd];
lz[nd] = 0;
}
}
void upd(int nd, int cl, int cr, int lf, int rg, ll val){
prop(nd, cl, cr);
if(rg < cl || cr < lf || lf > rg || cl > cr) return;
if(lf <= cl && cr <= rg){
lz[nd] += val;
prop(nd, cl, cr);
return;
}
upd(nd * 2, cl, (cl + cr) / 2, lf, rg, val);
upd(nd * 2 + 1, (cl + cr) / 2 + 1, cr, lf, rg, val);
st[nd] = max(st[nd * 2], st[nd * 2 + 1]);
}
int que(int nd, int cl, int cr, int lf, int rg){
prop(nd, cl, cr);
if(cl > cr || lf > rg || rg < cl || cr < lf) return 0;
if(lf <= cl && cr <= rg) return st[nd];
return max(
que(nd * 2, cl, (cl + cr) / 2, lf, rg),
que(nd * 2 + 1, (cl + cr) / 2 + 1, cr, lf, rg)
);
}
vector<pair<int, int> > cc;
void ins(int ps, int val){
int i = lower_bound(cc.begin(), cc.end(), make_pair(val, ps)) - cc.begin();
upd(1, 0, cc.size() - 1, i, i, inf + ps);
upd(1, 0, cc.size() - 1, i + 1, cc.size() - 1, -1);
}
void del(int ps, int val){
int i = lower_bound(cc.begin(), cc.end(), make_pair(val, ps)) - cc.begin();
upd(1, 0, cc.size() - 1, i, i, -(inf + ps));
upd(1, 0, cc.size() - 1, i + 1, cc.size() - 1, 1);
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
for(int i = 0; i < A.size(); i ++)
cc.push_back({A[i], i});
sort(cc.begin(), cc.end());
for(int i = 0; i < X.size(); i ++)
cc.push_back({V[i], X[i]});
sort(cc.begin(), cc.end());
cc.erase(unique(cc.begin(), cc.end()), cc.end());
upd(1, 0, cc.size() - 1, 0, cc.size() - 1, -inf);
for(int i = 0; i < A.size(); i ++)
ins(i, A[i]);
vector<int> ans;
for(int i = 0; i < X.size(); i ++){
del(X[i], A[X[i]]);
A[X[i]] = V[i];
ins(X[i], A[X[i]]);
ans.push_back(que(1, 0, cc.size() - 1, 0, cc.size() - 1));
}
return ans;
}
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:64:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i = 0; i < A.size(); i ++)
| ~~^~~~~~~~~~
bubblesort2.cpp:67:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int i = 0; i < X.size(); i ++)
| ~~^~~~~~~~~~
bubblesort2.cpp:74:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int i = 0; i < A.size(); i ++)
| ~~^~~~~~~~~~
bubblesort2.cpp:78:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int i = 0; i < X.size(); i ++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
588 KB |
Output is correct |
4 |
Correct |
6 ms |
600 KB |
Output is correct |
5 |
Correct |
7 ms |
604 KB |
Output is correct |
6 |
Correct |
6 ms |
604 KB |
Output is correct |
7 |
Correct |
6 ms |
540 KB |
Output is correct |
8 |
Correct |
6 ms |
484 KB |
Output is correct |
9 |
Correct |
6 ms |
608 KB |
Output is correct |
10 |
Correct |
5 ms |
580 KB |
Output is correct |
11 |
Correct |
6 ms |
588 KB |
Output is correct |
12 |
Correct |
5 ms |
588 KB |
Output is correct |
13 |
Correct |
5 ms |
580 KB |
Output is correct |
14 |
Correct |
5 ms |
552 KB |
Output is correct |
15 |
Correct |
5 ms |
588 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
6 ms |
588 KB |
Output is correct |
18 |
Correct |
6 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
588 KB |
Output is correct |
4 |
Correct |
6 ms |
600 KB |
Output is correct |
5 |
Correct |
7 ms |
604 KB |
Output is correct |
6 |
Correct |
6 ms |
604 KB |
Output is correct |
7 |
Correct |
6 ms |
540 KB |
Output is correct |
8 |
Correct |
6 ms |
484 KB |
Output is correct |
9 |
Correct |
6 ms |
608 KB |
Output is correct |
10 |
Correct |
5 ms |
580 KB |
Output is correct |
11 |
Correct |
6 ms |
588 KB |
Output is correct |
12 |
Correct |
5 ms |
588 KB |
Output is correct |
13 |
Correct |
5 ms |
580 KB |
Output is correct |
14 |
Correct |
5 ms |
552 KB |
Output is correct |
15 |
Correct |
5 ms |
588 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
6 ms |
588 KB |
Output is correct |
18 |
Correct |
6 ms |
588 KB |
Output is correct |
19 |
Correct |
22 ms |
1420 KB |
Output is correct |
20 |
Correct |
25 ms |
1476 KB |
Output is correct |
21 |
Correct |
25 ms |
1452 KB |
Output is correct |
22 |
Correct |
25 ms |
1480 KB |
Output is correct |
23 |
Correct |
23 ms |
1460 KB |
Output is correct |
24 |
Correct |
28 ms |
1356 KB |
Output is correct |
25 |
Correct |
22 ms |
1420 KB |
Output is correct |
26 |
Correct |
22 ms |
1356 KB |
Output is correct |
27 |
Correct |
21 ms |
1440 KB |
Output is correct |
28 |
Correct |
23 ms |
1404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
2040 KB |
Output is correct |
2 |
Correct |
115 ms |
4012 KB |
Output is correct |
3 |
Correct |
208 ms |
7352 KB |
Output is correct |
4 |
Correct |
207 ms |
7328 KB |
Output is correct |
5 |
Correct |
213 ms |
7468 KB |
Output is correct |
6 |
Correct |
194 ms |
7396 KB |
Output is correct |
7 |
Correct |
186 ms |
7404 KB |
Output is correct |
8 |
Correct |
196 ms |
7344 KB |
Output is correct |
9 |
Correct |
201 ms |
7376 KB |
Output is correct |
10 |
Correct |
143 ms |
5416 KB |
Output is correct |
11 |
Correct |
162 ms |
5364 KB |
Output is correct |
12 |
Correct |
155 ms |
5360 KB |
Output is correct |
13 |
Correct |
140 ms |
5424 KB |
Output is correct |
14 |
Correct |
145 ms |
5348 KB |
Output is correct |
15 |
Correct |
159 ms |
5468 KB |
Output is correct |
16 |
Correct |
143 ms |
5376 KB |
Output is correct |
17 |
Correct |
140 ms |
5304 KB |
Output is correct |
18 |
Correct |
137 ms |
5336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
588 KB |
Output is correct |
4 |
Correct |
6 ms |
600 KB |
Output is correct |
5 |
Correct |
7 ms |
604 KB |
Output is correct |
6 |
Correct |
6 ms |
604 KB |
Output is correct |
7 |
Correct |
6 ms |
540 KB |
Output is correct |
8 |
Correct |
6 ms |
484 KB |
Output is correct |
9 |
Correct |
6 ms |
608 KB |
Output is correct |
10 |
Correct |
5 ms |
580 KB |
Output is correct |
11 |
Correct |
6 ms |
588 KB |
Output is correct |
12 |
Correct |
5 ms |
588 KB |
Output is correct |
13 |
Correct |
5 ms |
580 KB |
Output is correct |
14 |
Correct |
5 ms |
552 KB |
Output is correct |
15 |
Correct |
5 ms |
588 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
6 ms |
588 KB |
Output is correct |
18 |
Correct |
6 ms |
588 KB |
Output is correct |
19 |
Correct |
22 ms |
1420 KB |
Output is correct |
20 |
Correct |
25 ms |
1476 KB |
Output is correct |
21 |
Correct |
25 ms |
1452 KB |
Output is correct |
22 |
Correct |
25 ms |
1480 KB |
Output is correct |
23 |
Correct |
23 ms |
1460 KB |
Output is correct |
24 |
Correct |
28 ms |
1356 KB |
Output is correct |
25 |
Correct |
22 ms |
1420 KB |
Output is correct |
26 |
Correct |
22 ms |
1356 KB |
Output is correct |
27 |
Correct |
21 ms |
1440 KB |
Output is correct |
28 |
Correct |
23 ms |
1404 KB |
Output is correct |
29 |
Correct |
39 ms |
2040 KB |
Output is correct |
30 |
Correct |
115 ms |
4012 KB |
Output is correct |
31 |
Correct |
208 ms |
7352 KB |
Output is correct |
32 |
Correct |
207 ms |
7328 KB |
Output is correct |
33 |
Correct |
213 ms |
7468 KB |
Output is correct |
34 |
Correct |
194 ms |
7396 KB |
Output is correct |
35 |
Correct |
186 ms |
7404 KB |
Output is correct |
36 |
Correct |
196 ms |
7344 KB |
Output is correct |
37 |
Correct |
201 ms |
7376 KB |
Output is correct |
38 |
Correct |
143 ms |
5416 KB |
Output is correct |
39 |
Correct |
162 ms |
5364 KB |
Output is correct |
40 |
Correct |
155 ms |
5360 KB |
Output is correct |
41 |
Correct |
140 ms |
5424 KB |
Output is correct |
42 |
Correct |
145 ms |
5348 KB |
Output is correct |
43 |
Correct |
159 ms |
5468 KB |
Output is correct |
44 |
Correct |
143 ms |
5376 KB |
Output is correct |
45 |
Correct |
140 ms |
5304 KB |
Output is correct |
46 |
Correct |
137 ms |
5336 KB |
Output is correct |
47 |
Correct |
849 ms |
27740 KB |
Output is correct |
48 |
Runtime error |
429 ms |
50620 KB |
Execution killed with signal 11 |
49 |
Halted |
0 ms |
0 KB |
- |