#include "bubblesort2.h"
#include <bits/stdc++.h>
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
const int N = 1e6;
int ind[N];
int st[4*N+10], lz[4*N+10] = {0};
int cons(int i, int l, int r){
if(l==r) return st[i] = ind[l];
int m = l+r>>1;
return st[i] = max(cons(i<<1, l, m),cons(i<<1|1, m+1, r));
}
void upd(int i, int l, int r, int a, int v){
if(lz[i]){
st[i]+=lz[i];
if(l!=r){
lz[i<<1]+=lz[i];
lz[i<<1|1] += lz[i];
}
lz[i]=0;
}
if(r<a)return;
if(a<=l){
st[i]+=v;
if(l!=r){
lz[i<<1]+=v;
lz[i<<1|1]+=v;
}
return;
}
int m = l+r>>1;
upd(i<<1, l, m, a, v);
upd(i<<1|1, m+1, r, a, v);
st[i]=max(st[i<<1],st[i<<1|1]);
}
void updind(int i, int l, int r, int iind, int newind){
if(lz[i]){
st[i]+=lz[i];
if(l!=r){
lz[i<<1]+=lz[i];
lz[i<<1|1] += lz[i];
}
lz[i]=0;
}
if(l==r){
st[i] += newind-ind[l];
ind[l] = newind;
return;
}
int m = l+r>>1;
if(iind <= m) updind(i<<1, l, m, iind, newind);
else updind(i<<1|1, m+1, r, iind, newind);
st[i] = max(st[i<<1]+lz[i<<1], st[i<<1|1]+lz[i<<1|1]);
}
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
int n=A.size(), q = X.size();
long long a[n], v[q], tot[n+q];for(int i = 0;i < n;i++) tot[i] = a[i] = (long long)A[i]*n+i;
for(int i = 0;i < q;i++) tot[i+n] = v[i] = (long long)V[i]*n+X[i];
sort(tot, tot+n+q);
fill(ind,ind+N,-1);
for(int i = 0;i < n;i++) {
a[i] = lower_bound(tot, tot+n+q, a[i])-tot;
ind[a[i]]=i;
}
for(int i = 0;i < q;i++) v[i] = lower_bound(tot, tot+n+q, v[i])-tot;
cons(1, 0, N-1);
for(int i = 0;i < n;i++){
upd(1, 0, N-1, a[i]+1, -1);
}
vector<int> ans(q);
for(int _ = 0;_ < q;_++){
int i = X[_];
updind(1, 0, N-1, a[i], -1);
updind(1, 0, N-1, v[_], i);
upd(1, 0, N-1, a[i]+1, 1);
upd(1, 0, N-1, v[_]+1, -1);
a[i]=v[_];
ans[_]=st[1];
}
return ans;
}
Compilation message
bubblesort2.cpp: In function 'int cons(int, int, int)':
bubblesort2.cpp:11:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
11 | int m = l+r>>1;
| ~^~
bubblesort2.cpp: In function 'void upd(int, int, int, int, int)':
bubblesort2.cpp:32:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
32 | int m = l+r>>1;
| ~^~
bubblesort2.cpp: In function 'void updind(int, int, int, int, int)':
bubblesort2.cpp:51:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
51 | int m = l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
14936 KB |
Output is correct |
2 |
Correct |
5 ms |
16988 KB |
Output is correct |
3 |
Correct |
7 ms |
19032 KB |
Output is correct |
4 |
Correct |
6 ms |
15088 KB |
Output is correct |
5 |
Correct |
6 ms |
17168 KB |
Output is correct |
6 |
Correct |
6 ms |
15124 KB |
Output is correct |
7 |
Correct |
6 ms |
15184 KB |
Output is correct |
8 |
Correct |
6 ms |
15120 KB |
Output is correct |
9 |
Correct |
7 ms |
17244 KB |
Output is correct |
10 |
Correct |
6 ms |
15196 KB |
Output is correct |
11 |
Correct |
7 ms |
17240 KB |
Output is correct |
12 |
Correct |
7 ms |
16984 KB |
Output is correct |
13 |
Correct |
6 ms |
15196 KB |
Output is correct |
14 |
Correct |
6 ms |
15196 KB |
Output is correct |
15 |
Correct |
7 ms |
17096 KB |
Output is correct |
16 |
Correct |
6 ms |
15196 KB |
Output is correct |
17 |
Correct |
7 ms |
15096 KB |
Output is correct |
18 |
Correct |
6 ms |
17236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
14936 KB |
Output is correct |
2 |
Correct |
5 ms |
16988 KB |
Output is correct |
3 |
Correct |
7 ms |
19032 KB |
Output is correct |
4 |
Correct |
6 ms |
15088 KB |
Output is correct |
5 |
Correct |
6 ms |
17168 KB |
Output is correct |
6 |
Correct |
6 ms |
15124 KB |
Output is correct |
7 |
Correct |
6 ms |
15184 KB |
Output is correct |
8 |
Correct |
6 ms |
15120 KB |
Output is correct |
9 |
Correct |
7 ms |
17244 KB |
Output is correct |
10 |
Correct |
6 ms |
15196 KB |
Output is correct |
11 |
Correct |
7 ms |
17240 KB |
Output is correct |
12 |
Correct |
7 ms |
16984 KB |
Output is correct |
13 |
Correct |
6 ms |
15196 KB |
Output is correct |
14 |
Correct |
6 ms |
15196 KB |
Output is correct |
15 |
Correct |
7 ms |
17096 KB |
Output is correct |
16 |
Correct |
6 ms |
15196 KB |
Output is correct |
17 |
Correct |
7 ms |
15096 KB |
Output is correct |
18 |
Correct |
6 ms |
17236 KB |
Output is correct |
19 |
Correct |
13 ms |
17500 KB |
Output is correct |
20 |
Correct |
14 ms |
15592 KB |
Output is correct |
21 |
Correct |
13 ms |
15596 KB |
Output is correct |
22 |
Correct |
15 ms |
17604 KB |
Output is correct |
23 |
Correct |
13 ms |
15708 KB |
Output is correct |
24 |
Correct |
13 ms |
15804 KB |
Output is correct |
25 |
Correct |
13 ms |
15708 KB |
Output is correct |
26 |
Correct |
13 ms |
15708 KB |
Output is correct |
27 |
Correct |
13 ms |
15708 KB |
Output is correct |
28 |
Correct |
14 ms |
17756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
17756 KB |
Output is correct |
2 |
Correct |
40 ms |
21392 KB |
Output is correct |
3 |
Correct |
68 ms |
21136 KB |
Output is correct |
4 |
Correct |
69 ms |
22860 KB |
Output is correct |
5 |
Correct |
70 ms |
22864 KB |
Output is correct |
6 |
Correct |
68 ms |
22868 KB |
Output is correct |
7 |
Correct |
68 ms |
20956 KB |
Output is correct |
8 |
Correct |
79 ms |
21088 KB |
Output is correct |
9 |
Correct |
67 ms |
21152 KB |
Output is correct |
10 |
Correct |
66 ms |
21288 KB |
Output is correct |
11 |
Correct |
59 ms |
21072 KB |
Output is correct |
12 |
Correct |
67 ms |
22864 KB |
Output is correct |
13 |
Correct |
57 ms |
22868 KB |
Output is correct |
14 |
Correct |
57 ms |
22904 KB |
Output is correct |
15 |
Correct |
60 ms |
21216 KB |
Output is correct |
16 |
Correct |
58 ms |
21076 KB |
Output is correct |
17 |
Correct |
62 ms |
23056 KB |
Output is correct |
18 |
Correct |
58 ms |
21084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
14936 KB |
Output is correct |
2 |
Correct |
5 ms |
16988 KB |
Output is correct |
3 |
Correct |
7 ms |
19032 KB |
Output is correct |
4 |
Correct |
6 ms |
15088 KB |
Output is correct |
5 |
Correct |
6 ms |
17168 KB |
Output is correct |
6 |
Correct |
6 ms |
15124 KB |
Output is correct |
7 |
Correct |
6 ms |
15184 KB |
Output is correct |
8 |
Correct |
6 ms |
15120 KB |
Output is correct |
9 |
Correct |
7 ms |
17244 KB |
Output is correct |
10 |
Correct |
6 ms |
15196 KB |
Output is correct |
11 |
Correct |
7 ms |
17240 KB |
Output is correct |
12 |
Correct |
7 ms |
16984 KB |
Output is correct |
13 |
Correct |
6 ms |
15196 KB |
Output is correct |
14 |
Correct |
6 ms |
15196 KB |
Output is correct |
15 |
Correct |
7 ms |
17096 KB |
Output is correct |
16 |
Correct |
6 ms |
15196 KB |
Output is correct |
17 |
Correct |
7 ms |
15096 KB |
Output is correct |
18 |
Correct |
6 ms |
17236 KB |
Output is correct |
19 |
Correct |
13 ms |
17500 KB |
Output is correct |
20 |
Correct |
14 ms |
15592 KB |
Output is correct |
21 |
Correct |
13 ms |
15596 KB |
Output is correct |
22 |
Correct |
15 ms |
17604 KB |
Output is correct |
23 |
Correct |
13 ms |
15708 KB |
Output is correct |
24 |
Correct |
13 ms |
15804 KB |
Output is correct |
25 |
Correct |
13 ms |
15708 KB |
Output is correct |
26 |
Correct |
13 ms |
15708 KB |
Output is correct |
27 |
Correct |
13 ms |
15708 KB |
Output is correct |
28 |
Correct |
14 ms |
17756 KB |
Output is correct |
29 |
Correct |
15 ms |
17756 KB |
Output is correct |
30 |
Correct |
40 ms |
21392 KB |
Output is correct |
31 |
Correct |
68 ms |
21136 KB |
Output is correct |
32 |
Correct |
69 ms |
22860 KB |
Output is correct |
33 |
Correct |
70 ms |
22864 KB |
Output is correct |
34 |
Correct |
68 ms |
22868 KB |
Output is correct |
35 |
Correct |
68 ms |
20956 KB |
Output is correct |
36 |
Correct |
79 ms |
21088 KB |
Output is correct |
37 |
Correct |
67 ms |
21152 KB |
Output is correct |
38 |
Correct |
66 ms |
21288 KB |
Output is correct |
39 |
Correct |
59 ms |
21072 KB |
Output is correct |
40 |
Correct |
67 ms |
22864 KB |
Output is correct |
41 |
Correct |
57 ms |
22868 KB |
Output is correct |
42 |
Correct |
57 ms |
22904 KB |
Output is correct |
43 |
Correct |
60 ms |
21216 KB |
Output is correct |
44 |
Correct |
58 ms |
21076 KB |
Output is correct |
45 |
Correct |
62 ms |
23056 KB |
Output is correct |
46 |
Correct |
58 ms |
21084 KB |
Output is correct |
47 |
Correct |
218 ms |
30544 KB |
Output is correct |
48 |
Correct |
769 ms |
61804 KB |
Output is correct |
49 |
Correct |
819 ms |
65360 KB |
Output is correct |
50 |
Correct |
822 ms |
65364 KB |
Output is correct |
51 |
Correct |
806 ms |
65420 KB |
Output is correct |
52 |
Correct |
800 ms |
65452 KB |
Output is correct |
53 |
Correct |
833 ms |
65556 KB |
Output is correct |
54 |
Correct |
782 ms |
65680 KB |
Output is correct |
55 |
Correct |
816 ms |
65616 KB |
Output is correct |
56 |
Correct |
787 ms |
65604 KB |
Output is correct |
57 |
Correct |
830 ms |
65620 KB |
Output is correct |
58 |
Correct |
794 ms |
65620 KB |
Output is correct |
59 |
Correct |
756 ms |
64216 KB |
Output is correct |
60 |
Correct |
741 ms |
64336 KB |
Output is correct |
61 |
Correct |
733 ms |
64148 KB |
Output is correct |
62 |
Correct |
722 ms |
64068 KB |
Output is correct |
63 |
Correct |
727 ms |
64084 KB |
Output is correct |
64 |
Correct |
752 ms |
64148 KB |
Output is correct |
65 |
Correct |
730 ms |
64084 KB |
Output is correct |
66 |
Correct |
699 ms |
63780 KB |
Output is correct |
67 |
Correct |
695 ms |
64084 KB |
Output is correct |