#include "bubblesort2.h"
#include <vector>
#include <algorithm>
#include <map>
#include <iostream>
using namespace std;
#define ll long long
const int MX = 1000005;
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 |
5 ms |
460 KB |
Output is correct |
4 |
Correct |
5 ms |
460 KB |
Output is correct |
5 |
Correct |
6 ms |
460 KB |
Output is correct |
6 |
Correct |
5 ms |
460 KB |
Output is correct |
7 |
Correct |
5 ms |
548 KB |
Output is correct |
8 |
Correct |
5 ms |
460 KB |
Output is correct |
9 |
Correct |
5 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
460 KB |
Output is correct |
11 |
Correct |
5 ms |
464 KB |
Output is correct |
12 |
Correct |
5 ms |
460 KB |
Output is correct |
13 |
Correct |
5 ms |
460 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
15 |
Correct |
5 ms |
460 KB |
Output is correct |
16 |
Correct |
6 ms |
460 KB |
Output is correct |
17 |
Correct |
5 ms |
460 KB |
Output is correct |
18 |
Correct |
5 ms |
460 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 |
5 ms |
460 KB |
Output is correct |
4 |
Correct |
5 ms |
460 KB |
Output is correct |
5 |
Correct |
6 ms |
460 KB |
Output is correct |
6 |
Correct |
5 ms |
460 KB |
Output is correct |
7 |
Correct |
5 ms |
548 KB |
Output is correct |
8 |
Correct |
5 ms |
460 KB |
Output is correct |
9 |
Correct |
5 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
460 KB |
Output is correct |
11 |
Correct |
5 ms |
464 KB |
Output is correct |
12 |
Correct |
5 ms |
460 KB |
Output is correct |
13 |
Correct |
5 ms |
460 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
15 |
Correct |
5 ms |
460 KB |
Output is correct |
16 |
Correct |
6 ms |
460 KB |
Output is correct |
17 |
Correct |
5 ms |
460 KB |
Output is correct |
18 |
Correct |
5 ms |
460 KB |
Output is correct |
19 |
Correct |
21 ms |
1236 KB |
Output is correct |
20 |
Correct |
24 ms |
1280 KB |
Output is correct |
21 |
Correct |
23 ms |
1280 KB |
Output is correct |
22 |
Correct |
31 ms |
1272 KB |
Output is correct |
23 |
Correct |
22 ms |
1228 KB |
Output is correct |
24 |
Correct |
22 ms |
1280 KB |
Output is correct |
25 |
Correct |
22 ms |
1228 KB |
Output is correct |
26 |
Correct |
22 ms |
1228 KB |
Output is correct |
27 |
Correct |
20 ms |
1228 KB |
Output is correct |
28 |
Correct |
21 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
1944 KB |
Output is correct |
2 |
Correct |
104 ms |
3764 KB |
Output is correct |
3 |
Correct |
186 ms |
6768 KB |
Output is correct |
4 |
Correct |
185 ms |
6712 KB |
Output is correct |
5 |
Correct |
179 ms |
6712 KB |
Output is correct |
6 |
Correct |
189 ms |
6768 KB |
Output is correct |
7 |
Correct |
179 ms |
6876 KB |
Output is correct |
8 |
Correct |
183 ms |
6728 KB |
Output is correct |
9 |
Correct |
179 ms |
6864 KB |
Output is correct |
10 |
Correct |
141 ms |
4724 KB |
Output is correct |
11 |
Correct |
140 ms |
4668 KB |
Output is correct |
12 |
Correct |
144 ms |
4664 KB |
Output is correct |
13 |
Correct |
138 ms |
4812 KB |
Output is correct |
14 |
Correct |
139 ms |
4664 KB |
Output is correct |
15 |
Correct |
138 ms |
4676 KB |
Output is correct |
16 |
Correct |
138 ms |
4664 KB |
Output is correct |
17 |
Correct |
133 ms |
4696 KB |
Output is correct |
18 |
Correct |
133 ms |
4776 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 |
5 ms |
460 KB |
Output is correct |
4 |
Correct |
5 ms |
460 KB |
Output is correct |
5 |
Correct |
6 ms |
460 KB |
Output is correct |
6 |
Correct |
5 ms |
460 KB |
Output is correct |
7 |
Correct |
5 ms |
548 KB |
Output is correct |
8 |
Correct |
5 ms |
460 KB |
Output is correct |
9 |
Correct |
5 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
460 KB |
Output is correct |
11 |
Correct |
5 ms |
464 KB |
Output is correct |
12 |
Correct |
5 ms |
460 KB |
Output is correct |
13 |
Correct |
5 ms |
460 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
15 |
Correct |
5 ms |
460 KB |
Output is correct |
16 |
Correct |
6 ms |
460 KB |
Output is correct |
17 |
Correct |
5 ms |
460 KB |
Output is correct |
18 |
Correct |
5 ms |
460 KB |
Output is correct |
19 |
Correct |
21 ms |
1236 KB |
Output is correct |
20 |
Correct |
24 ms |
1280 KB |
Output is correct |
21 |
Correct |
23 ms |
1280 KB |
Output is correct |
22 |
Correct |
31 ms |
1272 KB |
Output is correct |
23 |
Correct |
22 ms |
1228 KB |
Output is correct |
24 |
Correct |
22 ms |
1280 KB |
Output is correct |
25 |
Correct |
22 ms |
1228 KB |
Output is correct |
26 |
Correct |
22 ms |
1228 KB |
Output is correct |
27 |
Correct |
20 ms |
1228 KB |
Output is correct |
28 |
Correct |
21 ms |
1228 KB |
Output is correct |
29 |
Correct |
35 ms |
1944 KB |
Output is correct |
30 |
Correct |
104 ms |
3764 KB |
Output is correct |
31 |
Correct |
186 ms |
6768 KB |
Output is correct |
32 |
Correct |
185 ms |
6712 KB |
Output is correct |
33 |
Correct |
179 ms |
6712 KB |
Output is correct |
34 |
Correct |
189 ms |
6768 KB |
Output is correct |
35 |
Correct |
179 ms |
6876 KB |
Output is correct |
36 |
Correct |
183 ms |
6728 KB |
Output is correct |
37 |
Correct |
179 ms |
6864 KB |
Output is correct |
38 |
Correct |
141 ms |
4724 KB |
Output is correct |
39 |
Correct |
140 ms |
4668 KB |
Output is correct |
40 |
Correct |
144 ms |
4664 KB |
Output is correct |
41 |
Correct |
138 ms |
4812 KB |
Output is correct |
42 |
Correct |
139 ms |
4664 KB |
Output is correct |
43 |
Correct |
138 ms |
4676 KB |
Output is correct |
44 |
Correct |
138 ms |
4664 KB |
Output is correct |
45 |
Correct |
133 ms |
4696 KB |
Output is correct |
46 |
Correct |
133 ms |
4776 KB |
Output is correct |
47 |
Correct |
756 ms |
24044 KB |
Output is correct |
48 |
Correct |
3137 ms |
55104 KB |
Output is correct |
49 |
Correct |
3393 ms |
69676 KB |
Output is correct |
50 |
Correct |
3416 ms |
69568 KB |
Output is correct |
51 |
Correct |
3447 ms |
69628 KB |
Output is correct |
52 |
Correct |
3476 ms |
69592 KB |
Output is correct |
53 |
Correct |
3484 ms |
69588 KB |
Output is correct |
54 |
Correct |
3101 ms |
69792 KB |
Output is correct |
55 |
Correct |
3293 ms |
69820 KB |
Output is correct |
56 |
Correct |
3074 ms |
69896 KB |
Output is correct |
57 |
Correct |
3192 ms |
69732 KB |
Output is correct |
58 |
Correct |
3030 ms |
69720 KB |
Output is correct |
59 |
Correct |
2694 ms |
68324 KB |
Output is correct |
60 |
Correct |
2672 ms |
68332 KB |
Output is correct |
61 |
Correct |
2642 ms |
68404 KB |
Output is correct |
62 |
Correct |
2526 ms |
68224 KB |
Output is correct |
63 |
Correct |
2497 ms |
68260 KB |
Output is correct |
64 |
Correct |
2503 ms |
68188 KB |
Output is correct |
65 |
Correct |
2253 ms |
68156 KB |
Output is correct |
66 |
Correct |
2296 ms |
68084 KB |
Output is correct |
67 |
Correct |
2280 ms |
68184 KB |
Output is correct |