#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+5;
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=1, int r=sz(v)){
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*x), upd(j2,sz(v),-x);
}
vi countScans(vi A, vi x, vi y){
int n = sz(A), q = sz(x); vi ans; a.resize(n+1);
for(int i = 1; i <= n; i++) a[i]=A[i-1],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 = 1; 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 |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
320 KB |
Output is correct |
3 |
Correct |
4 ms |
480 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 |
544 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 |
484 KB |
Output is correct |
12 |
Correct |
6 ms |
476 KB |
Output is correct |
13 |
Correct |
4 ms |
512 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
15 |
Correct |
4 ms |
480 KB |
Output is correct |
16 |
Correct |
4 ms |
448 KB |
Output is correct |
17 |
Correct |
4 ms |
476 KB |
Output is correct |
18 |
Correct |
4 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
320 KB |
Output is correct |
3 |
Correct |
4 ms |
480 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 |
544 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 |
484 KB |
Output is correct |
12 |
Correct |
6 ms |
476 KB |
Output is correct |
13 |
Correct |
4 ms |
512 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
15 |
Correct |
4 ms |
480 KB |
Output is correct |
16 |
Correct |
4 ms |
448 KB |
Output is correct |
17 |
Correct |
4 ms |
476 KB |
Output is correct |
18 |
Correct |
4 ms |
468 KB |
Output is correct |
19 |
Correct |
14 ms |
1084 KB |
Output is correct |
20 |
Correct |
16 ms |
1216 KB |
Output is correct |
21 |
Correct |
15 ms |
1244 KB |
Output is correct |
22 |
Correct |
17 ms |
1236 KB |
Output is correct |
23 |
Correct |
15 ms |
1216 KB |
Output is correct |
24 |
Correct |
15 ms |
1108 KB |
Output is correct |
25 |
Correct |
15 ms |
1148 KB |
Output is correct |
26 |
Correct |
17 ms |
1192 KB |
Output is correct |
27 |
Correct |
15 ms |
1136 KB |
Output is correct |
28 |
Correct |
15 ms |
1060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1448 KB |
Output is correct |
2 |
Correct |
65 ms |
3140 KB |
Output is correct |
3 |
Correct |
116 ms |
4956 KB |
Output is correct |
4 |
Correct |
115 ms |
4976 KB |
Output is correct |
5 |
Correct |
118 ms |
4996 KB |
Output is correct |
6 |
Correct |
114 ms |
4968 KB |
Output is correct |
7 |
Correct |
110 ms |
4964 KB |
Output is correct |
8 |
Correct |
112 ms |
5020 KB |
Output is correct |
9 |
Correct |
111 ms |
5092 KB |
Output is correct |
10 |
Correct |
91 ms |
4348 KB |
Output is correct |
11 |
Correct |
100 ms |
4392 KB |
Output is correct |
12 |
Correct |
89 ms |
4416 KB |
Output is correct |
13 |
Correct |
89 ms |
4416 KB |
Output is correct |
14 |
Correct |
91 ms |
4368 KB |
Output is correct |
15 |
Correct |
87 ms |
4384 KB |
Output is correct |
16 |
Correct |
87 ms |
4332 KB |
Output is correct |
17 |
Correct |
91 ms |
4380 KB |
Output is correct |
18 |
Correct |
87 ms |
4320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
320 KB |
Output is correct |
3 |
Correct |
4 ms |
480 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 |
544 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 |
484 KB |
Output is correct |
12 |
Correct |
6 ms |
476 KB |
Output is correct |
13 |
Correct |
4 ms |
512 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
15 |
Correct |
4 ms |
480 KB |
Output is correct |
16 |
Correct |
4 ms |
448 KB |
Output is correct |
17 |
Correct |
4 ms |
476 KB |
Output is correct |
18 |
Correct |
4 ms |
468 KB |
Output is correct |
19 |
Correct |
14 ms |
1084 KB |
Output is correct |
20 |
Correct |
16 ms |
1216 KB |
Output is correct |
21 |
Correct |
15 ms |
1244 KB |
Output is correct |
22 |
Correct |
17 ms |
1236 KB |
Output is correct |
23 |
Correct |
15 ms |
1216 KB |
Output is correct |
24 |
Correct |
15 ms |
1108 KB |
Output is correct |
25 |
Correct |
15 ms |
1148 KB |
Output is correct |
26 |
Correct |
17 ms |
1192 KB |
Output is correct |
27 |
Correct |
15 ms |
1136 KB |
Output is correct |
28 |
Correct |
15 ms |
1060 KB |
Output is correct |
29 |
Correct |
23 ms |
1448 KB |
Output is correct |
30 |
Correct |
65 ms |
3140 KB |
Output is correct |
31 |
Correct |
116 ms |
4956 KB |
Output is correct |
32 |
Correct |
115 ms |
4976 KB |
Output is correct |
33 |
Correct |
118 ms |
4996 KB |
Output is correct |
34 |
Correct |
114 ms |
4968 KB |
Output is correct |
35 |
Correct |
110 ms |
4964 KB |
Output is correct |
36 |
Correct |
112 ms |
5020 KB |
Output is correct |
37 |
Correct |
111 ms |
5092 KB |
Output is correct |
38 |
Correct |
91 ms |
4348 KB |
Output is correct |
39 |
Correct |
100 ms |
4392 KB |
Output is correct |
40 |
Correct |
89 ms |
4416 KB |
Output is correct |
41 |
Correct |
89 ms |
4416 KB |
Output is correct |
42 |
Correct |
91 ms |
4368 KB |
Output is correct |
43 |
Correct |
87 ms |
4384 KB |
Output is correct |
44 |
Correct |
87 ms |
4332 KB |
Output is correct |
45 |
Correct |
91 ms |
4380 KB |
Output is correct |
46 |
Correct |
87 ms |
4320 KB |
Output is correct |
47 |
Correct |
409 ms |
16612 KB |
Output is correct |
48 |
Correct |
1838 ms |
50040 KB |
Output is correct |
49 |
Correct |
2112 ms |
54360 KB |
Output is correct |
50 |
Correct |
2072 ms |
54272 KB |
Output is correct |
51 |
Correct |
2078 ms |
54392 KB |
Output is correct |
52 |
Correct |
2028 ms |
54328 KB |
Output is correct |
53 |
Correct |
2068 ms |
54344 KB |
Output is correct |
54 |
Correct |
1785 ms |
54624 KB |
Output is correct |
55 |
Correct |
1979 ms |
54512 KB |
Output is correct |
56 |
Correct |
1795 ms |
54388 KB |
Output is correct |
57 |
Correct |
1943 ms |
54480 KB |
Output is correct |
58 |
Correct |
1803 ms |
54468 KB |
Output is correct |
59 |
Correct |
1639 ms |
51164 KB |
Output is correct |
60 |
Correct |
1637 ms |
51160 KB |
Output is correct |
61 |
Correct |
1664 ms |
51232 KB |
Output is correct |
62 |
Correct |
1521 ms |
50088 KB |
Output is correct |
63 |
Correct |
1608 ms |
50088 KB |
Output is correct |
64 |
Correct |
1704 ms |
50124 KB |
Output is correct |
65 |
Correct |
1439 ms |
49004 KB |
Output is correct |
66 |
Correct |
1420 ms |
49012 KB |
Output is correct |
67 |
Correct |
1452 ms |
48888 KB |
Output is correct |