#include <bits/stdc++.h>
using namespace std;
vector<int>aib;
void update(int pos,int val,int n)
{
int i=pos;
while(i<=n)
{
aib[i]+=val;
i+=(i&(-i));
}
}
int get(int pos,int n)
{
int i=pos,s=0;
while(i>0)
{
s=s+aib[i];
i-=(i&(-i));
}
return s;
}
vector<int> countScans(vector<int>A, vector<int>X, vector<int>V)
{
int n=A.size(),q=X.size();
vector<int>Aux(n+q);
for(int i=0;i<n;i++)
{
// cin>>A[i];
Aux[i]=A[i];
}
for(int i=n;i<n+q;i++)
{
// cin>>A[i];
Aux[i]=V[i];
}
sort(Aux.begin(),Aux.end());
for(int i=0;i<n;i++)
{
int l=-1,r=n-1+q;
while(l<r-1)
{
int mid=(l+r)/2;
if(A[i]<=Aux[mid])
r=mid;
else
l=mid;
}
A[i]=r+1;
// cout<<A1[i]<<' ';
}
for(int i=n;i<n+q;i++)
{
int l=-1,r=n-1+q;
while(l<r-1)
{
int mid=(l+r)/2;
if(V[i-n]<=Aux[mid])
r=mid;
else
l=mid;
}
V[i-n]=r+1;
// cout<<A1[i]<<' ';
}
// cout<<'\n';
vector<int>ans;
for(int i=0;i<q;i++)
{
A[X[i]]=V[i];
int l=-1,r=n-1+q;
while(l<r-1)
{
int mid=(l+r)/2;
if(V[i]<=Aux[mid])
r=mid;
else
l=mid;
}
// cout<<A1[j]<<' ';
aib.assign(n+1+q,0);
int ans1=0;//cout<<"asa";
for(int j=0;j<n;j++)
{
ans1=max(ans1,get(n,n)-get(A[j],n));
// cout<<"asa";
update(A[j],1,n);
cout<<A[j]<<" ";
}
ans.push_back(ans1);
cout<<ans1<<'\n';
}
return ans;
}
/*int main()
{
int m,t;
cin>>m>>t;
vector<int>A(m);
vector<int>X(t);
vector<int>V(t);
for(int i=0;i<m;i++)
{
cin>>A[i];
}
for(int i=0;i<t;i++)
{
cin>>X[i]>>V[i];
}
countScans(A,X,V);
return 0;
}*/
/*
6 1
5 6 2 3 4 1
3 3
4 2
1 2 3 4
0 3
2 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
1628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
1628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5651 ms |
325912 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
1628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |