#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#include "bubblesort2.h"
int ind[1000001];
int tree[4000001];
int lazy[4000001];
int tree2[1000001];
void u(int i,int j){
while(i<1000001){
tree2[i]+=j;
i+=(i&-i);
}
}
int s(int i){
int su=0;
while(i>0){
su+=tree2[i];
i-=(i&-i);
}
return su;
}
void push(int no,int l,int r){
tree[no]+=lazy[no];
if(l<r){
lazy[no*2+1]+=lazy[no];
lazy[no*2+2]+=lazy[no];
}
lazy[no]=0;
}
void update(int no,int l,int r,int aa,int bb,int val){
push(no,l,r);
if(r<aa or l>bb){
return;
}
if(aa<=l and r<=bb){
tree[no]+=val;
if(l<r){
lazy[no*2+1]+=val;
lazy[no*2+2]+=val;
}
}
else{
int mid=(l+r)/2;
update(no*2+1,l,mid,aa,bb,val);
update(no*2+2,mid+1,r,aa,bb,val);
tree[no]=max(tree[no*2+1],tree[no*2+2]);
}
}
void update2(int no,int l,int r,int i,int val){
push(no,l,r);
if(l==r){
tree[no]=val;
}
else{
int mid=(l+r)/2;
push(no*2+1,l,mid);
push(no*2+2,mid+1,r);
if(i<=mid){
update2(no*2+1,l,mid,i,val);
}
else{
update2(no*2+2,mid+1,r,i,val);
}
tree[no]=max(tree[no*2+1],tree[no*2+2]);
}
}
int val[500001];
std::vector<int> countScans(std::vector<int> it,std::vector<int> X,std::vector<int> V){
int q=X.size();
int n=it.size();
vector<pair<pair<int,int>,int>> cur;
for(int i=0;i<n;i++){
cur.pb({{it[i],i},i});
}
for(int i=0;i<q;i++){
cur.pb({{V[i],X[i]},i+n});
}
sort(cur.begin(),cur.end());
for(int i=0;i<n+q;i++){
ind[cur[i].b]=i;
}
for(int i=0;i<4*(n+q);i++){
tree[i]=-1e9;
}
vector<int> ans;
for(int i=0;i<n;i++){
u(ind[i]+1,1);
}
for(int i=0;i<n;i++){
val[i]=ind[i];
update2(0,0,n+q-1,ind[i],i-s(ind[i]));
}
for(int i=0;i<q;i++){
u(val[X[i]]+1,-1);
u(ind[i+n]+1,1);
update2(0,0,n+q-1,ind[i+n],X[i]-s(ind[i+n]));
update2(0,0,n+q-1,val[X[i]],-1e9);
if(ind[i+n]<n+q-1){
update(0,0,n+q-1,ind[i+n]+1,n+q-1,-1);
}
if(val[X[i]]<n+q-1){
update(0,0,n+q-1,val[X[i]]+1,n+q-1,1);
}
val[X[i]]=ind[i+n];
ans.pb(tree[0]);
}
/*for(auto j:ans){
cout<<j<<",";
}
cout<<endl;*/
return ans;
}
//#define endl '\n'
/*int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int nn,qq;
cin>>nn>>qq;
int pp;
vector<int> ac;
vector<int> bc;
vector<int> dc;
for(int i=0;i<nn;i++){
cin>>pp;
ac.pb(pp);
}
for(int i=0;i<qq;i++){
cin>>pp;
bc.pb(pp);
cin>>pp;
dc.pb(pp);
}
countScans(ac,bc,dc);
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
768 KB |
Output is correct |
5 |
Correct |
5 ms |
768 KB |
Output is correct |
6 |
Correct |
4 ms |
768 KB |
Output is correct |
7 |
Correct |
4 ms |
768 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
6 ms |
896 KB |
Output is correct |
10 |
Correct |
4 ms |
768 KB |
Output is correct |
11 |
Correct |
4 ms |
768 KB |
Output is correct |
12 |
Correct |
4 ms |
768 KB |
Output is correct |
13 |
Correct |
5 ms |
768 KB |
Output is correct |
14 |
Correct |
4 ms |
768 KB |
Output is correct |
15 |
Correct |
4 ms |
768 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
4 ms |
768 KB |
Output is correct |
18 |
Correct |
5 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
768 KB |
Output is correct |
5 |
Correct |
5 ms |
768 KB |
Output is correct |
6 |
Correct |
4 ms |
768 KB |
Output is correct |
7 |
Correct |
4 ms |
768 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
6 ms |
896 KB |
Output is correct |
10 |
Correct |
4 ms |
768 KB |
Output is correct |
11 |
Correct |
4 ms |
768 KB |
Output is correct |
12 |
Correct |
4 ms |
768 KB |
Output is correct |
13 |
Correct |
5 ms |
768 KB |
Output is correct |
14 |
Correct |
4 ms |
768 KB |
Output is correct |
15 |
Correct |
4 ms |
768 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
4 ms |
768 KB |
Output is correct |
18 |
Correct |
5 ms |
768 KB |
Output is correct |
19 |
Correct |
15 ms |
1472 KB |
Output is correct |
20 |
Correct |
18 ms |
1600 KB |
Output is correct |
21 |
Correct |
17 ms |
1600 KB |
Output is correct |
22 |
Correct |
27 ms |
1600 KB |
Output is correct |
23 |
Correct |
17 ms |
1632 KB |
Output is correct |
24 |
Correct |
17 ms |
1600 KB |
Output is correct |
25 |
Correct |
17 ms |
1600 KB |
Output is correct |
26 |
Correct |
17 ms |
1600 KB |
Output is correct |
27 |
Correct |
17 ms |
1600 KB |
Output is correct |
28 |
Correct |
16 ms |
1600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
2300 KB |
Output is correct |
2 |
Correct |
61 ms |
4592 KB |
Output is correct |
3 |
Correct |
117 ms |
7392 KB |
Output is correct |
4 |
Correct |
117 ms |
7404 KB |
Output is correct |
5 |
Correct |
115 ms |
7404 KB |
Output is correct |
6 |
Correct |
116 ms |
7404 KB |
Output is correct |
7 |
Correct |
116 ms |
7404 KB |
Output is correct |
8 |
Correct |
118 ms |
7404 KB |
Output is correct |
9 |
Correct |
114 ms |
7404 KB |
Output is correct |
10 |
Correct |
111 ms |
7404 KB |
Output is correct |
11 |
Correct |
109 ms |
7404 KB |
Output is correct |
12 |
Correct |
116 ms |
7464 KB |
Output is correct |
13 |
Correct |
128 ms |
7544 KB |
Output is correct |
14 |
Correct |
114 ms |
7404 KB |
Output is correct |
15 |
Correct |
116 ms |
7404 KB |
Output is correct |
16 |
Correct |
113 ms |
7404 KB |
Output is correct |
17 |
Correct |
112 ms |
7532 KB |
Output is correct |
18 |
Correct |
106 ms |
7404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
768 KB |
Output is correct |
5 |
Correct |
5 ms |
768 KB |
Output is correct |
6 |
Correct |
4 ms |
768 KB |
Output is correct |
7 |
Correct |
4 ms |
768 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
6 ms |
896 KB |
Output is correct |
10 |
Correct |
4 ms |
768 KB |
Output is correct |
11 |
Correct |
4 ms |
768 KB |
Output is correct |
12 |
Correct |
4 ms |
768 KB |
Output is correct |
13 |
Correct |
5 ms |
768 KB |
Output is correct |
14 |
Correct |
4 ms |
768 KB |
Output is correct |
15 |
Correct |
4 ms |
768 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
4 ms |
768 KB |
Output is correct |
18 |
Correct |
5 ms |
768 KB |
Output is correct |
19 |
Correct |
15 ms |
1472 KB |
Output is correct |
20 |
Correct |
18 ms |
1600 KB |
Output is correct |
21 |
Correct |
17 ms |
1600 KB |
Output is correct |
22 |
Correct |
27 ms |
1600 KB |
Output is correct |
23 |
Correct |
17 ms |
1632 KB |
Output is correct |
24 |
Correct |
17 ms |
1600 KB |
Output is correct |
25 |
Correct |
17 ms |
1600 KB |
Output is correct |
26 |
Correct |
17 ms |
1600 KB |
Output is correct |
27 |
Correct |
17 ms |
1600 KB |
Output is correct |
28 |
Correct |
16 ms |
1600 KB |
Output is correct |
29 |
Correct |
18 ms |
2300 KB |
Output is correct |
30 |
Correct |
61 ms |
4592 KB |
Output is correct |
31 |
Correct |
117 ms |
7392 KB |
Output is correct |
32 |
Correct |
117 ms |
7404 KB |
Output is correct |
33 |
Correct |
115 ms |
7404 KB |
Output is correct |
34 |
Correct |
116 ms |
7404 KB |
Output is correct |
35 |
Correct |
116 ms |
7404 KB |
Output is correct |
36 |
Correct |
118 ms |
7404 KB |
Output is correct |
37 |
Correct |
114 ms |
7404 KB |
Output is correct |
38 |
Correct |
111 ms |
7404 KB |
Output is correct |
39 |
Correct |
109 ms |
7404 KB |
Output is correct |
40 |
Correct |
116 ms |
7464 KB |
Output is correct |
41 |
Correct |
128 ms |
7544 KB |
Output is correct |
42 |
Correct |
114 ms |
7404 KB |
Output is correct |
43 |
Correct |
116 ms |
7404 KB |
Output is correct |
44 |
Correct |
113 ms |
7404 KB |
Output is correct |
45 |
Correct |
112 ms |
7532 KB |
Output is correct |
46 |
Correct |
106 ms |
7404 KB |
Output is correct |
47 |
Correct |
455 ms |
24416 KB |
Output is correct |
48 |
Correct |
1801 ms |
69324 KB |
Output is correct |
49 |
Correct |
1919 ms |
74572 KB |
Output is correct |
50 |
Correct |
1898 ms |
74532 KB |
Output is correct |
51 |
Correct |
1870 ms |
74520 KB |
Output is correct |
52 |
Correct |
1919 ms |
74696 KB |
Output is correct |
53 |
Correct |
1895 ms |
74544 KB |
Output is correct |
54 |
Correct |
1806 ms |
74664 KB |
Output is correct |
55 |
Correct |
1839 ms |
74744 KB |
Output is correct |
56 |
Correct |
1732 ms |
74664 KB |
Output is correct |
57 |
Correct |
1796 ms |
74676 KB |
Output is correct |
58 |
Correct |
1714 ms |
74700 KB |
Output is correct |
59 |
Correct |
1710 ms |
73300 KB |
Output is correct |
60 |
Correct |
1648 ms |
73408 KB |
Output is correct |
61 |
Correct |
1752 ms |
73236 KB |
Output is correct |
62 |
Correct |
1636 ms |
73176 KB |
Output is correct |
63 |
Correct |
1686 ms |
73084 KB |
Output is correct |
64 |
Correct |
1647 ms |
73328 KB |
Output is correct |
65 |
Correct |
1526 ms |
72980 KB |
Output is correct |
66 |
Correct |
1548 ms |
73036 KB |
Output is correct |
67 |
Correct |
1553 ms |
73036 KB |
Output is correct |