#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#include "bubblesort2.h"
#include<bits/stdc++.h>
using namespace std;
int n,q;
int kaf=(1<<20);
struct segment{
struct node{
int maxa,lazy;
node(){
maxa=lazy=0;
}
};
node seg[(1<<21)];
void calc(int i){
if(i>=kaf){
seg[i].maxa+=seg[i].lazy;
seg[i].lazy=0;
return ;
}
seg[i].maxa=max(seg[(i<<1)].maxa+seg[(i<<1)].lazy,seg[(i<<1)^1].maxa+seg[(i<<1)^1].lazy);
}
void shift(int i){
if(i>=kaf){
calc(i);
return ;
}
seg[(i<<1)].lazy+=seg[i].lazy;
seg[(i<<1)^1].lazy+=seg[i].lazy;
seg[i].lazy=0;
return ;
}
void upd(int i,int l,int r,int tl,int tr,int w){
if(l>r||l>tr||r<tl||tl>tr){
return ;
}
if(l>=tl&&r<=tr){
seg[i].lazy+=w;
shift(i);
calc(i);
return ;
}
int m=(l+r)>>1;
shift(i);
upd((i<<1),l,m,tl,tr,w);
upd((i<<1)^1,m+1,r,tl,tr,w);
calc(i);
}
}seg;
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
n=A.size(),q=X.size();
vector<pair<int,int>>allind;
for(int i=0;i<n;i++){
allind.push_back(make_pair(A[i],i));
}
for(int i=0;i<q;i++){
allind.push_back(make_pair(V[i],X[i]));
}
sort(allind.begin(),allind.end());
allind.resize(unique(allind.begin(),allind.end())-allind.begin());
int sz=allind.size();
for(int i=0;i<n;i++){
int p=lower_bound(allind.begin(),allind.end(),make_pair(A[i],i))-allind.begin();
seg.upd(1,0,kaf-1,p,p,i);
seg.upd(1,0,kaf-1,p+1,sz,-1);
}
vector<int>res(q);
for(int i=0;i<q;i++){
int ind=X[i],val=V[i],p=lower_bound(allind.begin(),allind.end(),make_pair(A[ind],ind))-allind.begin();
seg.upd(1,0,kaf-1,p,p,-ind);
seg.upd(1,0,kaf-1,p+1,sz,1);
A[ind]=val;
p=lower_bound(allind.begin(),allind.end(),make_pair(val,ind))-allind.begin();
seg.upd(1,0,kaf-1,p,p,ind);
seg.upd(1,0,kaf-1,p+1,sz,-1);
res[i]=seg.seg[1].maxa>0?seg.seg[1].maxa:0;
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
16728 KB |
Output is correct |
2 |
Correct |
8 ms |
16732 KB |
Output is correct |
3 |
Correct |
10 ms |
16732 KB |
Output is correct |
4 |
Correct |
10 ms |
16732 KB |
Output is correct |
5 |
Correct |
10 ms |
16744 KB |
Output is correct |
6 |
Correct |
10 ms |
16728 KB |
Output is correct |
7 |
Correct |
10 ms |
16728 KB |
Output is correct |
8 |
Correct |
10 ms |
16732 KB |
Output is correct |
9 |
Correct |
10 ms |
16852 KB |
Output is correct |
10 |
Correct |
10 ms |
16732 KB |
Output is correct |
11 |
Correct |
10 ms |
16740 KB |
Output is correct |
12 |
Correct |
10 ms |
16732 KB |
Output is correct |
13 |
Correct |
10 ms |
16732 KB |
Output is correct |
14 |
Correct |
10 ms |
16732 KB |
Output is correct |
15 |
Correct |
10 ms |
16728 KB |
Output is correct |
16 |
Correct |
12 ms |
16988 KB |
Output is correct |
17 |
Correct |
10 ms |
16732 KB |
Output is correct |
18 |
Correct |
10 ms |
16728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
16728 KB |
Output is correct |
2 |
Correct |
8 ms |
16732 KB |
Output is correct |
3 |
Correct |
10 ms |
16732 KB |
Output is correct |
4 |
Correct |
10 ms |
16732 KB |
Output is correct |
5 |
Correct |
10 ms |
16744 KB |
Output is correct |
6 |
Correct |
10 ms |
16728 KB |
Output is correct |
7 |
Correct |
10 ms |
16728 KB |
Output is correct |
8 |
Correct |
10 ms |
16732 KB |
Output is correct |
9 |
Correct |
10 ms |
16852 KB |
Output is correct |
10 |
Correct |
10 ms |
16732 KB |
Output is correct |
11 |
Correct |
10 ms |
16740 KB |
Output is correct |
12 |
Correct |
10 ms |
16732 KB |
Output is correct |
13 |
Correct |
10 ms |
16732 KB |
Output is correct |
14 |
Correct |
10 ms |
16732 KB |
Output is correct |
15 |
Correct |
10 ms |
16728 KB |
Output is correct |
16 |
Correct |
12 ms |
16988 KB |
Output is correct |
17 |
Correct |
10 ms |
16732 KB |
Output is correct |
18 |
Correct |
10 ms |
16728 KB |
Output is correct |
19 |
Correct |
24 ms |
17184 KB |
Output is correct |
20 |
Correct |
24 ms |
17184 KB |
Output is correct |
21 |
Correct |
23 ms |
17496 KB |
Output is correct |
22 |
Correct |
24 ms |
17244 KB |
Output is correct |
23 |
Correct |
23 ms |
17240 KB |
Output is correct |
24 |
Correct |
24 ms |
17244 KB |
Output is correct |
25 |
Correct |
23 ms |
17240 KB |
Output is correct |
26 |
Correct |
23 ms |
17244 KB |
Output is correct |
27 |
Correct |
23 ms |
17240 KB |
Output is correct |
28 |
Correct |
23 ms |
17244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
17500 KB |
Output is correct |
2 |
Correct |
80 ms |
18136 KB |
Output is correct |
3 |
Correct |
136 ms |
19152 KB |
Output is correct |
4 |
Correct |
125 ms |
19152 KB |
Output is correct |
5 |
Correct |
130 ms |
19156 KB |
Output is correct |
6 |
Correct |
128 ms |
19148 KB |
Output is correct |
7 |
Correct |
127 ms |
19156 KB |
Output is correct |
8 |
Correct |
128 ms |
19156 KB |
Output is correct |
9 |
Correct |
122 ms |
19152 KB |
Output is correct |
10 |
Correct |
114 ms |
19156 KB |
Output is correct |
11 |
Correct |
116 ms |
19156 KB |
Output is correct |
12 |
Correct |
113 ms |
18940 KB |
Output is correct |
13 |
Correct |
112 ms |
19156 KB |
Output is correct |
14 |
Correct |
108 ms |
19156 KB |
Output is correct |
15 |
Correct |
109 ms |
19156 KB |
Output is correct |
16 |
Correct |
111 ms |
19156 KB |
Output is correct |
17 |
Correct |
107 ms |
19144 KB |
Output is correct |
18 |
Correct |
106 ms |
19156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
16728 KB |
Output is correct |
2 |
Correct |
8 ms |
16732 KB |
Output is correct |
3 |
Correct |
10 ms |
16732 KB |
Output is correct |
4 |
Correct |
10 ms |
16732 KB |
Output is correct |
5 |
Correct |
10 ms |
16744 KB |
Output is correct |
6 |
Correct |
10 ms |
16728 KB |
Output is correct |
7 |
Correct |
10 ms |
16728 KB |
Output is correct |
8 |
Correct |
10 ms |
16732 KB |
Output is correct |
9 |
Correct |
10 ms |
16852 KB |
Output is correct |
10 |
Correct |
10 ms |
16732 KB |
Output is correct |
11 |
Correct |
10 ms |
16740 KB |
Output is correct |
12 |
Correct |
10 ms |
16732 KB |
Output is correct |
13 |
Correct |
10 ms |
16732 KB |
Output is correct |
14 |
Correct |
10 ms |
16732 KB |
Output is correct |
15 |
Correct |
10 ms |
16728 KB |
Output is correct |
16 |
Correct |
12 ms |
16988 KB |
Output is correct |
17 |
Correct |
10 ms |
16732 KB |
Output is correct |
18 |
Correct |
10 ms |
16728 KB |
Output is correct |
19 |
Correct |
24 ms |
17184 KB |
Output is correct |
20 |
Correct |
24 ms |
17184 KB |
Output is correct |
21 |
Correct |
23 ms |
17496 KB |
Output is correct |
22 |
Correct |
24 ms |
17244 KB |
Output is correct |
23 |
Correct |
23 ms |
17240 KB |
Output is correct |
24 |
Correct |
24 ms |
17244 KB |
Output is correct |
25 |
Correct |
23 ms |
17240 KB |
Output is correct |
26 |
Correct |
23 ms |
17244 KB |
Output is correct |
27 |
Correct |
23 ms |
17240 KB |
Output is correct |
28 |
Correct |
23 ms |
17244 KB |
Output is correct |
29 |
Correct |
30 ms |
17500 KB |
Output is correct |
30 |
Correct |
80 ms |
18136 KB |
Output is correct |
31 |
Correct |
136 ms |
19152 KB |
Output is correct |
32 |
Correct |
125 ms |
19152 KB |
Output is correct |
33 |
Correct |
130 ms |
19156 KB |
Output is correct |
34 |
Correct |
128 ms |
19148 KB |
Output is correct |
35 |
Correct |
127 ms |
19156 KB |
Output is correct |
36 |
Correct |
128 ms |
19156 KB |
Output is correct |
37 |
Correct |
122 ms |
19152 KB |
Output is correct |
38 |
Correct |
114 ms |
19156 KB |
Output is correct |
39 |
Correct |
116 ms |
19156 KB |
Output is correct |
40 |
Correct |
113 ms |
18940 KB |
Output is correct |
41 |
Correct |
112 ms |
19156 KB |
Output is correct |
42 |
Correct |
108 ms |
19156 KB |
Output is correct |
43 |
Correct |
109 ms |
19156 KB |
Output is correct |
44 |
Correct |
111 ms |
19156 KB |
Output is correct |
45 |
Correct |
107 ms |
19144 KB |
Output is correct |
46 |
Correct |
106 ms |
19156 KB |
Output is correct |
47 |
Correct |
407 ms |
25280 KB |
Output is correct |
48 |
Correct |
1546 ms |
36728 KB |
Output is correct |
49 |
Correct |
1665 ms |
38324 KB |
Output is correct |
50 |
Correct |
1691 ms |
38324 KB |
Output is correct |
51 |
Correct |
1688 ms |
38952 KB |
Output is correct |
52 |
Correct |
1658 ms |
38428 KB |
Output is correct |
53 |
Correct |
1660 ms |
38868 KB |
Output is correct |
54 |
Correct |
1549 ms |
38580 KB |
Output is correct |
55 |
Correct |
1618 ms |
38324 KB |
Output is correct |
56 |
Correct |
1553 ms |
38592 KB |
Output is correct |
57 |
Correct |
1601 ms |
38324 KB |
Output is correct |
58 |
Correct |
1554 ms |
38364 KB |
Output is correct |
59 |
Correct |
1507 ms |
38348 KB |
Output is correct |
60 |
Correct |
1412 ms |
38352 KB |
Output is correct |
61 |
Correct |
1444 ms |
38352 KB |
Output is correct |
62 |
Correct |
1437 ms |
38608 KB |
Output is correct |
63 |
Correct |
1452 ms |
38352 KB |
Output is correct |
64 |
Correct |
1408 ms |
38356 KB |
Output is correct |
65 |
Correct |
1360 ms |
38172 KB |
Output is correct |
66 |
Correct |
1392 ms |
38352 KB |
Output is correct |
67 |
Correct |
1360 ms |
38844 KB |
Output is correct |