#include <bits/stdc++.h>
#include "bubblesort2.h"
using namespace std;
const int nmax=2*5e5+42;
struct info
{
int maxi,lazy;
};
info tree[4*nmax];
void push(int node)
{
tree[node*2].lazy+=tree[node].lazy;
tree[node*2+1].lazy+=tree[node].lazy;
tree[node].lazy=0;
}
info actual(info ret)
{
ret.maxi+=ret.lazy;
ret.lazy=0;
return ret;
}
info my_merge(info a,info b)
{
a=actual(a);
b=actual(b);
if(a.maxi<b.maxi)return b;
return a;
}
void update_single(int node,int l,int r,int pos,int val)
{
if(l==r)
{
tree[node].maxi=val;
return;
}
push(node);
int av=(l+r)/2;
if(pos<=av)update_single(node*2,l,av,pos,val);
else update_single(node*2+1,av+1,r,pos,val);
tree[node]=my_merge(tree[node*2],tree[node*2+1]);
}
void update_range(int node,int l,int r,int lq,int rq,int val)
{
if(l==lq&&r==rq)
{
tree[node].lazy+=val;
return;
}
push(node);
int av=(l+r)/2;
if(lq<=av)update_range(node*2,l,av,lq,min(av,rq),val);
if(av<rq)update_range(node*2+1,av+1,r,max(av+1,lq),rq,val);
tree[node]=my_merge(tree[node*2],tree[node*2+1]);
}
vector<int> countScans(vector<int> A,vector<int> X,vector<int> V)
{
vector< pair<int,int> > active={};
for(int i=0;i<A.size();i++)
active.push_back({A[i],i});
for(int i=0;i<X.size();i++)
active.push_back({V[i],X[i]});
sort(active.begin(),active.end());
unique(active.begin(),active.end());
int n=active.size()-1;
for(int i=0;i<A.size();i++)
{
int pos=lower_bound(active.begin(),active.end(),make_pair(A[i],i))-active.begin();
update_single(1,0,n,pos,i);
if(pos+1<=n)update_range(1,0,n,pos+1,n,-1);
}
vector<int> output={};
for(int i=0;i<X.size();i++)
{
int pos=lower_bound(active.begin(),active.end(),make_pair(A[X[i]],X[i]))-active.begin();
update_single(1,0,n,pos,-1e9);
if(pos+1<=n)update_range(1,0,n,pos+1,n,1);
A[X[i]]=V[i];
pos=lower_bound(active.begin(),active.end(),make_pair(V[i],X[i]))-active.begin();
update_single(1,0,n,pos,X[i]);
if(pos+1<=n)update_range(1,0,n,pos+1,n,-1);
output.push_back(actual(tree[1]).maxi);
}
return output;
}
/*
int main()
{
vector<int> A={1,2,3,4};
vector<int> X={0,2};
vector<int> V={3,1};
for(auto k:countScans(A,X,V))cout<<k<<endl;
return 0;
}
*/
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:73:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<A.size();i++)
~^~~~~~~~~
bubblesort2.cpp:76:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<X.size();i++)
~^~~~~~~~~
bubblesort2.cpp:85:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<A.size();i++)
~^~~~~~~~~
bubblesort2.cpp:96:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<X.size();i++)
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
9 ms |
640 KB |
Output is correct |
4 |
Correct |
9 ms |
512 KB |
Output is correct |
5 |
Correct |
9 ms |
640 KB |
Output is correct |
6 |
Correct |
8 ms |
692 KB |
Output is correct |
7 |
Correct |
9 ms |
640 KB |
Output is correct |
8 |
Correct |
9 ms |
512 KB |
Output is correct |
9 |
Correct |
9 ms |
640 KB |
Output is correct |
10 |
Correct |
9 ms |
640 KB |
Output is correct |
11 |
Correct |
8 ms |
640 KB |
Output is correct |
12 |
Correct |
9 ms |
640 KB |
Output is correct |
13 |
Correct |
9 ms |
512 KB |
Output is correct |
14 |
Correct |
8 ms |
512 KB |
Output is correct |
15 |
Correct |
9 ms |
512 KB |
Output is correct |
16 |
Correct |
8 ms |
512 KB |
Output is correct |
17 |
Correct |
9 ms |
512 KB |
Output is correct |
18 |
Correct |
8 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
9 ms |
640 KB |
Output is correct |
4 |
Correct |
9 ms |
512 KB |
Output is correct |
5 |
Correct |
9 ms |
640 KB |
Output is correct |
6 |
Correct |
8 ms |
692 KB |
Output is correct |
7 |
Correct |
9 ms |
640 KB |
Output is correct |
8 |
Correct |
9 ms |
512 KB |
Output is correct |
9 |
Correct |
9 ms |
640 KB |
Output is correct |
10 |
Correct |
9 ms |
640 KB |
Output is correct |
11 |
Correct |
8 ms |
640 KB |
Output is correct |
12 |
Correct |
9 ms |
640 KB |
Output is correct |
13 |
Correct |
9 ms |
512 KB |
Output is correct |
14 |
Correct |
8 ms |
512 KB |
Output is correct |
15 |
Correct |
9 ms |
512 KB |
Output is correct |
16 |
Correct |
8 ms |
512 KB |
Output is correct |
17 |
Correct |
9 ms |
512 KB |
Output is correct |
18 |
Correct |
8 ms |
512 KB |
Output is correct |
19 |
Correct |
20 ms |
1152 KB |
Output is correct |
20 |
Correct |
24 ms |
1152 KB |
Output is correct |
21 |
Correct |
24 ms |
1280 KB |
Output is correct |
22 |
Correct |
24 ms |
1152 KB |
Output is correct |
23 |
Correct |
23 ms |
1152 KB |
Output is correct |
24 |
Correct |
22 ms |
1152 KB |
Output is correct |
25 |
Correct |
22 ms |
1152 KB |
Output is correct |
26 |
Correct |
22 ms |
1152 KB |
Output is correct |
27 |
Correct |
22 ms |
1152 KB |
Output is correct |
28 |
Correct |
22 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
1404 KB |
Output is correct |
2 |
Correct |
77 ms |
3064 KB |
Output is correct |
3 |
Correct |
135 ms |
5356 KB |
Output is correct |
4 |
Correct |
131 ms |
5356 KB |
Output is correct |
5 |
Correct |
132 ms |
5360 KB |
Output is correct |
6 |
Correct |
141 ms |
5356 KB |
Output is correct |
7 |
Correct |
133 ms |
5356 KB |
Output is correct |
8 |
Correct |
141 ms |
5484 KB |
Output is correct |
9 |
Correct |
132 ms |
5356 KB |
Output is correct |
10 |
Correct |
111 ms |
4588 KB |
Output is correct |
11 |
Correct |
112 ms |
4588 KB |
Output is correct |
12 |
Correct |
120 ms |
4716 KB |
Output is correct |
13 |
Correct |
116 ms |
4588 KB |
Output is correct |
14 |
Correct |
112 ms |
4588 KB |
Output is correct |
15 |
Correct |
113 ms |
4612 KB |
Output is correct |
16 |
Correct |
105 ms |
4588 KB |
Output is correct |
17 |
Correct |
110 ms |
4588 KB |
Output is correct |
18 |
Correct |
110 ms |
4588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
9 ms |
640 KB |
Output is correct |
4 |
Correct |
9 ms |
512 KB |
Output is correct |
5 |
Correct |
9 ms |
640 KB |
Output is correct |
6 |
Correct |
8 ms |
692 KB |
Output is correct |
7 |
Correct |
9 ms |
640 KB |
Output is correct |
8 |
Correct |
9 ms |
512 KB |
Output is correct |
9 |
Correct |
9 ms |
640 KB |
Output is correct |
10 |
Correct |
9 ms |
640 KB |
Output is correct |
11 |
Correct |
8 ms |
640 KB |
Output is correct |
12 |
Correct |
9 ms |
640 KB |
Output is correct |
13 |
Correct |
9 ms |
512 KB |
Output is correct |
14 |
Correct |
8 ms |
512 KB |
Output is correct |
15 |
Correct |
9 ms |
512 KB |
Output is correct |
16 |
Correct |
8 ms |
512 KB |
Output is correct |
17 |
Correct |
9 ms |
512 KB |
Output is correct |
18 |
Correct |
8 ms |
512 KB |
Output is correct |
19 |
Correct |
20 ms |
1152 KB |
Output is correct |
20 |
Correct |
24 ms |
1152 KB |
Output is correct |
21 |
Correct |
24 ms |
1280 KB |
Output is correct |
22 |
Correct |
24 ms |
1152 KB |
Output is correct |
23 |
Correct |
23 ms |
1152 KB |
Output is correct |
24 |
Correct |
22 ms |
1152 KB |
Output is correct |
25 |
Correct |
22 ms |
1152 KB |
Output is correct |
26 |
Correct |
22 ms |
1152 KB |
Output is correct |
27 |
Correct |
22 ms |
1152 KB |
Output is correct |
28 |
Correct |
22 ms |
1152 KB |
Output is correct |
29 |
Correct |
28 ms |
1404 KB |
Output is correct |
30 |
Correct |
77 ms |
3064 KB |
Output is correct |
31 |
Correct |
135 ms |
5356 KB |
Output is correct |
32 |
Correct |
131 ms |
5356 KB |
Output is correct |
33 |
Correct |
132 ms |
5360 KB |
Output is correct |
34 |
Correct |
141 ms |
5356 KB |
Output is correct |
35 |
Correct |
133 ms |
5356 KB |
Output is correct |
36 |
Correct |
141 ms |
5484 KB |
Output is correct |
37 |
Correct |
132 ms |
5356 KB |
Output is correct |
38 |
Correct |
111 ms |
4588 KB |
Output is correct |
39 |
Correct |
112 ms |
4588 KB |
Output is correct |
40 |
Correct |
120 ms |
4716 KB |
Output is correct |
41 |
Correct |
116 ms |
4588 KB |
Output is correct |
42 |
Correct |
112 ms |
4588 KB |
Output is correct |
43 |
Correct |
113 ms |
4612 KB |
Output is correct |
44 |
Correct |
105 ms |
4588 KB |
Output is correct |
45 |
Correct |
110 ms |
4588 KB |
Output is correct |
46 |
Correct |
110 ms |
4588 KB |
Output is correct |
47 |
Correct |
502 ms |
19680 KB |
Output is correct |
48 |
Correct |
2017 ms |
50892 KB |
Output is correct |
49 |
Correct |
2143 ms |
53384 KB |
Output is correct |
50 |
Correct |
2190 ms |
53464 KB |
Output is correct |
51 |
Correct |
2242 ms |
53244 KB |
Output is correct |
52 |
Correct |
2252 ms |
53260 KB |
Output is correct |
53 |
Correct |
2420 ms |
53460 KB |
Output is correct |
54 |
Correct |
2248 ms |
53460 KB |
Output is correct |
55 |
Correct |
2456 ms |
53564 KB |
Output is correct |
56 |
Correct |
2234 ms |
53628 KB |
Output is correct |
57 |
Correct |
2451 ms |
53448 KB |
Output is correct |
58 |
Correct |
2210 ms |
53348 KB |
Output is correct |
59 |
Correct |
2131 ms |
50292 KB |
Output is correct |
60 |
Correct |
1968 ms |
50124 KB |
Output is correct |
61 |
Correct |
1979 ms |
50240 KB |
Output is correct |
62 |
Correct |
1872 ms |
49008 KB |
Output is correct |
63 |
Correct |
1929 ms |
48964 KB |
Output is correct |
64 |
Correct |
1945 ms |
48952 KB |
Output is correct |
65 |
Correct |
1804 ms |
47944 KB |
Output is correct |
66 |
Correct |
1773 ms |
47940 KB |
Output is correct |
67 |
Correct |
1792 ms |
47688 KB |
Output is correct |