#include "bubblesort2.h"
#include<bits/stdc++.h>
using namespace std;
#define maxn 1000005
#define pii pair<int,int>
#define fi first
#define se second
const int inf=1e9;
namespace Segtree{
int tree[4*maxn],lazy[4*maxn];
void getnew(int id,int val){
tree[id]+=val;
lazy[id]+=val;
}
void pushdown(int id){
if(lazy[id]==0) return;
getnew(id<<1,lazy[id]);
getnew(id<<1|1,lazy[id]);
lazy[id]=0;
}
void update(int l,int r,int id,int pos,int x,int val){
if(l==r){
tree[id]+=x;
return;
}
pushdown(id);
int mid=(l+r)>>1;
if(pos<=mid){
getnew(id<<1|1,val);
update(l,mid,id<<1,pos,x,val);
}
else update(mid+1,r,id<<1|1,pos,x,val);
tree[id]=max(tree[id<<1],tree[id<<1|1]);
}
}
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
int n=(int)A.size(),q=(int)X.size();
vector<int> ans(q);
vector<pii> com;
for(int i=0;i<n;i++) com.push_back({A[i],i});
for(int i=0;i<q;i++) com.push_back({V[i],X[i]});
sort(com.begin(),com.end());
com.erase(unique(com.begin(),com.end()),com.end());
int sz=(int)com.size();
for(int i=1;i<=4*sz;i++) Segtree::tree[i]=-inf;
for(int i=0;i<n;i++){
int pos=lower_bound(com.begin(),com.end(),make_pair(A[i],i))-com.begin()+1;
Segtree::update(1,sz,1,pos,i+inf,-1);
}
//cout << Segtree::tree[1] << '\n';
for(int i=0;i<q;i++){
int pos=lower_bound(com.begin(),com.end(),make_pair(A[X[i]],X[i]))-com.begin()+1;
Segtree::update(1,sz,1,pos,-inf-X[i],1);
A[X[i]]=V[i];
pos=lower_bound(com.begin(),com.end(),make_pair(A[X[i]],X[i]))-com.begin()+1;
Segtree::update(1,sz,1,pos,X[i]+inf,-1);
ans[i]=Segtree::tree[1];
}
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 |
3 ms |
468 KB |
Output is correct |
4 |
Correct |
3 ms |
492 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
584 KB |
Output is correct |
10 |
Correct |
3 ms |
480 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
452 KB |
Output is correct |
13 |
Correct |
2 ms |
456 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
448 KB |
Output is correct |
16 |
Correct |
2 ms |
448 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 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 |
3 ms |
468 KB |
Output is correct |
4 |
Correct |
3 ms |
492 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
584 KB |
Output is correct |
10 |
Correct |
3 ms |
480 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
452 KB |
Output is correct |
13 |
Correct |
2 ms |
456 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
448 KB |
Output is correct |
16 |
Correct |
2 ms |
448 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
9 ms |
1196 KB |
Output is correct |
20 |
Correct |
10 ms |
1364 KB |
Output is correct |
21 |
Correct |
9 ms |
1352 KB |
Output is correct |
22 |
Correct |
10 ms |
1364 KB |
Output is correct |
23 |
Correct |
9 ms |
1212 KB |
Output is correct |
24 |
Correct |
10 ms |
1236 KB |
Output is correct |
25 |
Correct |
9 ms |
1220 KB |
Output is correct |
26 |
Correct |
9 ms |
1236 KB |
Output is correct |
27 |
Correct |
9 ms |
1236 KB |
Output is correct |
28 |
Correct |
9 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
1740 KB |
Output is correct |
2 |
Correct |
40 ms |
3456 KB |
Output is correct |
3 |
Correct |
81 ms |
5756 KB |
Output is correct |
4 |
Correct |
70 ms |
5744 KB |
Output is correct |
5 |
Correct |
68 ms |
5744 KB |
Output is correct |
6 |
Correct |
77 ms |
5624 KB |
Output is correct |
7 |
Correct |
67 ms |
5696 KB |
Output is correct |
8 |
Correct |
71 ms |
5696 KB |
Output is correct |
9 |
Correct |
67 ms |
5696 KB |
Output is correct |
10 |
Correct |
53 ms |
4552 KB |
Output is correct |
11 |
Correct |
67 ms |
4524 KB |
Output is correct |
12 |
Correct |
55 ms |
4556 KB |
Output is correct |
13 |
Correct |
52 ms |
4580 KB |
Output is correct |
14 |
Correct |
52 ms |
4536 KB |
Output is correct |
15 |
Correct |
51 ms |
4540 KB |
Output is correct |
16 |
Correct |
49 ms |
4532 KB |
Output is correct |
17 |
Correct |
50 ms |
4600 KB |
Output is correct |
18 |
Correct |
50 ms |
4584 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 |
3 ms |
468 KB |
Output is correct |
4 |
Correct |
3 ms |
492 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
584 KB |
Output is correct |
10 |
Correct |
3 ms |
480 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
452 KB |
Output is correct |
13 |
Correct |
2 ms |
456 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
448 KB |
Output is correct |
16 |
Correct |
2 ms |
448 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
9 ms |
1196 KB |
Output is correct |
20 |
Correct |
10 ms |
1364 KB |
Output is correct |
21 |
Correct |
9 ms |
1352 KB |
Output is correct |
22 |
Correct |
10 ms |
1364 KB |
Output is correct |
23 |
Correct |
9 ms |
1212 KB |
Output is correct |
24 |
Correct |
10 ms |
1236 KB |
Output is correct |
25 |
Correct |
9 ms |
1220 KB |
Output is correct |
26 |
Correct |
9 ms |
1236 KB |
Output is correct |
27 |
Correct |
9 ms |
1236 KB |
Output is correct |
28 |
Correct |
9 ms |
1236 KB |
Output is correct |
29 |
Correct |
14 ms |
1740 KB |
Output is correct |
30 |
Correct |
40 ms |
3456 KB |
Output is correct |
31 |
Correct |
81 ms |
5756 KB |
Output is correct |
32 |
Correct |
70 ms |
5744 KB |
Output is correct |
33 |
Correct |
68 ms |
5744 KB |
Output is correct |
34 |
Correct |
77 ms |
5624 KB |
Output is correct |
35 |
Correct |
67 ms |
5696 KB |
Output is correct |
36 |
Correct |
71 ms |
5696 KB |
Output is correct |
37 |
Correct |
67 ms |
5696 KB |
Output is correct |
38 |
Correct |
53 ms |
4552 KB |
Output is correct |
39 |
Correct |
67 ms |
4524 KB |
Output is correct |
40 |
Correct |
55 ms |
4556 KB |
Output is correct |
41 |
Correct |
52 ms |
4580 KB |
Output is correct |
42 |
Correct |
52 ms |
4536 KB |
Output is correct |
43 |
Correct |
51 ms |
4540 KB |
Output is correct |
44 |
Correct |
49 ms |
4532 KB |
Output is correct |
45 |
Correct |
50 ms |
4600 KB |
Output is correct |
46 |
Correct |
50 ms |
4584 KB |
Output is correct |
47 |
Correct |
246 ms |
19184 KB |
Output is correct |
48 |
Correct |
1152 ms |
54680 KB |
Output is correct |
49 |
Correct |
1273 ms |
58620 KB |
Output is correct |
50 |
Correct |
1201 ms |
58620 KB |
Output is correct |
51 |
Correct |
1218 ms |
58716 KB |
Output is correct |
52 |
Correct |
1237 ms |
58664 KB |
Output is correct |
53 |
Correct |
1233 ms |
58632 KB |
Output is correct |
54 |
Correct |
1111 ms |
58944 KB |
Output is correct |
55 |
Correct |
1202 ms |
58880 KB |
Output is correct |
56 |
Correct |
1102 ms |
58820 KB |
Output is correct |
57 |
Correct |
1096 ms |
58912 KB |
Output is correct |
58 |
Correct |
1093 ms |
58868 KB |
Output is correct |
59 |
Correct |
968 ms |
55584 KB |
Output is correct |
60 |
Correct |
971 ms |
55584 KB |
Output is correct |
61 |
Correct |
976 ms |
55596 KB |
Output is correct |
62 |
Correct |
907 ms |
54440 KB |
Output is correct |
63 |
Correct |
897 ms |
54572 KB |
Output is correct |
64 |
Correct |
887 ms |
54520 KB |
Output is correct |
65 |
Correct |
814 ms |
53236 KB |
Output is correct |
66 |
Correct |
782 ms |
53296 KB |
Output is correct |
67 |
Correct |
802 ms |
53284 KB |
Output is correct |