#include <bits/stdc++.h>
using namespace std;
#define pb push_back
using vi = vector<int>;
#define mp make_pair
#define lb lower_bound
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
const int mxN = (int)1e6+1;
vi a;
vector<pair<int,int>> v;
int seg[mxN*2], lzy[mxN*2];
void prop(int p, int l, int r){
if(l==r or !lzy[p]) return;
int mid = (l+r)/2; int rp = p+2*(mid-l+1);
lzy[p+1]+=lzy[p], lzy[rp]+=lzy[p];
seg[p+1]+=lzy[p], seg[rp]+=lzy[p], lzy[p]=0;
}
void upd(int i, int j, int vv, int p=0, int l=0, int r=sz(v)-1){
if(i>r or j<l or i>j) return; prop(p,l,r);
if(i<=l and r<=j){ seg[p]+=vv,lzy[p]+=vv; return; }
int mid = (l+r)/2; int rp = p+2*(mid-l+1);
if(i<=mid) upd(i,j,vv,p+1,l,mid);
if(j>mid) upd(i,j,vv,rp,mid+1,r);
seg[p] = max(seg[p+1],seg[rp]);
}
void add(int i, int x){
int j = lb(all(v),mp(a[i],i))-begin(v);
int j2 = lb(all(v),mp(a[i],-1))-begin(v);
upd(j,j,(i+1)*x), upd(j2,sz(v)-1,-x);
}
vi countScans(vi A, vi x, vi y){
int n = sz(A), q = sz(x); vi ans; a=A;
for(int i = 0; i < n; i++) v.pb({A[i],i});
for(int i = 0; i < q; i++) v.pb({y[i],x[i]});
sort(all(v)); v.erase(unique(all(v)),end(v));
for(int i = 0; i < n; i++) add(i,1);
for(int i = 0; i < q; i++)
add(x[i],-1),a[x[i]]=y[i],add(x[i],1),ans.pb(seg[0]);
return ans;
}
Compilation message
bubblesort2.cpp: In function 'void upd(int, int, int, int, int, int)':
bubblesort2.cpp:22:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
22 | if(i>r or j<l or i>j) return; prop(p,l,r);
| ^~
bubblesort2.cpp:22:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
22 | if(i>r or j<l or i>j) return; prop(p,l,r);
| ^~~~
bubblesort2.cpp: In function 'vi countScans(vi, vi, vi)':
bubblesort2.cpp:42:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
42 | for(int i = 0; i < q; i++)
| ^~~
bubblesort2.cpp:44:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
44 | return ans;
| ^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
448 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
4 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 |
4 ms |
440 KB |
Output is correct |
13 |
Correct |
4 ms |
520 KB |
Output is correct |
14 |
Correct |
4 ms |
468 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 |
444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
448 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
4 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 |
4 ms |
440 KB |
Output is correct |
13 |
Correct |
4 ms |
520 KB |
Output is correct |
14 |
Correct |
4 ms |
468 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 |
444 KB |
Output is correct |
19 |
Correct |
15 ms |
1140 KB |
Output is correct |
20 |
Correct |
19 ms |
1212 KB |
Output is correct |
21 |
Correct |
16 ms |
1248 KB |
Output is correct |
22 |
Correct |
17 ms |
1232 KB |
Output is correct |
23 |
Correct |
17 ms |
1184 KB |
Output is correct |
24 |
Correct |
16 ms |
1108 KB |
Output is correct |
25 |
Correct |
20 ms |
1108 KB |
Output is correct |
26 |
Correct |
18 ms |
1148 KB |
Output is correct |
27 |
Correct |
19 ms |
1140 KB |
Output is correct |
28 |
Correct |
15 ms |
1136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1488 KB |
Output is correct |
2 |
Correct |
72 ms |
3136 KB |
Output is correct |
3 |
Correct |
123 ms |
4968 KB |
Output is correct |
4 |
Correct |
117 ms |
4928 KB |
Output is correct |
5 |
Correct |
116 ms |
4984 KB |
Output is correct |
6 |
Correct |
115 ms |
5012 KB |
Output is correct |
7 |
Correct |
118 ms |
5076 KB |
Output is correct |
8 |
Correct |
113 ms |
4972 KB |
Output is correct |
9 |
Correct |
111 ms |
5028 KB |
Output is correct |
10 |
Correct |
87 ms |
4416 KB |
Output is correct |
11 |
Correct |
90 ms |
4396 KB |
Output is correct |
12 |
Correct |
91 ms |
4340 KB |
Output is correct |
13 |
Correct |
89 ms |
4416 KB |
Output is correct |
14 |
Correct |
100 ms |
4328 KB |
Output is correct |
15 |
Correct |
100 ms |
4360 KB |
Output is correct |
16 |
Correct |
91 ms |
4396 KB |
Output is correct |
17 |
Correct |
89 ms |
4392 KB |
Output is correct |
18 |
Correct |
90 ms |
4336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
448 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
4 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 |
4 ms |
440 KB |
Output is correct |
13 |
Correct |
4 ms |
520 KB |
Output is correct |
14 |
Correct |
4 ms |
468 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 |
444 KB |
Output is correct |
19 |
Correct |
15 ms |
1140 KB |
Output is correct |
20 |
Correct |
19 ms |
1212 KB |
Output is correct |
21 |
Correct |
16 ms |
1248 KB |
Output is correct |
22 |
Correct |
17 ms |
1232 KB |
Output is correct |
23 |
Correct |
17 ms |
1184 KB |
Output is correct |
24 |
Correct |
16 ms |
1108 KB |
Output is correct |
25 |
Correct |
20 ms |
1108 KB |
Output is correct |
26 |
Correct |
18 ms |
1148 KB |
Output is correct |
27 |
Correct |
19 ms |
1140 KB |
Output is correct |
28 |
Correct |
15 ms |
1136 KB |
Output is correct |
29 |
Correct |
22 ms |
1488 KB |
Output is correct |
30 |
Correct |
72 ms |
3136 KB |
Output is correct |
31 |
Correct |
123 ms |
4968 KB |
Output is correct |
32 |
Correct |
117 ms |
4928 KB |
Output is correct |
33 |
Correct |
116 ms |
4984 KB |
Output is correct |
34 |
Correct |
115 ms |
5012 KB |
Output is correct |
35 |
Correct |
118 ms |
5076 KB |
Output is correct |
36 |
Correct |
113 ms |
4972 KB |
Output is correct |
37 |
Correct |
111 ms |
5028 KB |
Output is correct |
38 |
Correct |
87 ms |
4416 KB |
Output is correct |
39 |
Correct |
90 ms |
4396 KB |
Output is correct |
40 |
Correct |
91 ms |
4340 KB |
Output is correct |
41 |
Correct |
89 ms |
4416 KB |
Output is correct |
42 |
Correct |
100 ms |
4328 KB |
Output is correct |
43 |
Correct |
100 ms |
4360 KB |
Output is correct |
44 |
Correct |
91 ms |
4396 KB |
Output is correct |
45 |
Correct |
89 ms |
4392 KB |
Output is correct |
46 |
Correct |
90 ms |
4336 KB |
Output is correct |
47 |
Correct |
407 ms |
16604 KB |
Output is correct |
48 |
Correct |
1885 ms |
50164 KB |
Output is correct |
49 |
Correct |
2017 ms |
54420 KB |
Output is correct |
50 |
Correct |
2080 ms |
54356 KB |
Output is correct |
51 |
Correct |
2087 ms |
54332 KB |
Output is correct |
52 |
Correct |
2111 ms |
54364 KB |
Output is correct |
53 |
Correct |
2162 ms |
54312 KB |
Output is correct |
54 |
Correct |
1861 ms |
54504 KB |
Output is correct |
55 |
Correct |
1967 ms |
54500 KB |
Output is correct |
56 |
Correct |
1793 ms |
54564 KB |
Output is correct |
57 |
Correct |
1988 ms |
54780 KB |
Output is correct |
58 |
Correct |
1893 ms |
54412 KB |
Output is correct |
59 |
Correct |
1692 ms |
51220 KB |
Output is correct |
60 |
Correct |
1637 ms |
51256 KB |
Output is correct |
61 |
Correct |
1669 ms |
51224 KB |
Output is correct |
62 |
Correct |
1582 ms |
50108 KB |
Output is correct |
63 |
Correct |
1602 ms |
50108 KB |
Output is correct |
64 |
Correct |
1541 ms |
50088 KB |
Output is correct |
65 |
Correct |
1415 ms |
48984 KB |
Output is correct |
66 |
Correct |
1488 ms |
48972 KB |
Output is correct |
67 |
Correct |
1387 ms |
49104 KB |
Output is correct |