#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-n];
}
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=0;i<q;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;
}
V[i]=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+q,n+q)-get(A[j],n+q));
// cout<<"asa";
update(A[j],1,n+q);
//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
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
11 ms |
348 KB |
Output is correct |
3 |
Correct |
71 ms |
512 KB |
Output is correct |
4 |
Correct |
72 ms |
524 KB |
Output is correct |
5 |
Correct |
86 ms |
512 KB |
Output is correct |
6 |
Correct |
64 ms |
516 KB |
Output is correct |
7 |
Correct |
68 ms |
348 KB |
Output is correct |
8 |
Correct |
72 ms |
508 KB |
Output is correct |
9 |
Correct |
80 ms |
348 KB |
Output is correct |
10 |
Correct |
65 ms |
344 KB |
Output is correct |
11 |
Correct |
64 ms |
512 KB |
Output is correct |
12 |
Correct |
74 ms |
508 KB |
Output is correct |
13 |
Correct |
71 ms |
512 KB |
Output is correct |
14 |
Correct |
85 ms |
504 KB |
Output is correct |
15 |
Correct |
66 ms |
508 KB |
Output is correct |
16 |
Correct |
68 ms |
344 KB |
Output is correct |
17 |
Correct |
69 ms |
504 KB |
Output is correct |
18 |
Correct |
68 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
11 ms |
348 KB |
Output is correct |
3 |
Correct |
71 ms |
512 KB |
Output is correct |
4 |
Correct |
72 ms |
524 KB |
Output is correct |
5 |
Correct |
86 ms |
512 KB |
Output is correct |
6 |
Correct |
64 ms |
516 KB |
Output is correct |
7 |
Correct |
68 ms |
348 KB |
Output is correct |
8 |
Correct |
72 ms |
508 KB |
Output is correct |
9 |
Correct |
80 ms |
348 KB |
Output is correct |
10 |
Correct |
65 ms |
344 KB |
Output is correct |
11 |
Correct |
64 ms |
512 KB |
Output is correct |
12 |
Correct |
74 ms |
508 KB |
Output is correct |
13 |
Correct |
71 ms |
512 KB |
Output is correct |
14 |
Correct |
85 ms |
504 KB |
Output is correct |
15 |
Correct |
66 ms |
508 KB |
Output is correct |
16 |
Correct |
68 ms |
344 KB |
Output is correct |
17 |
Correct |
69 ms |
504 KB |
Output is correct |
18 |
Correct |
68 ms |
512 KB |
Output is correct |
19 |
Correct |
1457 ms |
856 KB |
Output is correct |
20 |
Correct |
1629 ms |
784 KB |
Output is correct |
21 |
Correct |
1577 ms |
780 KB |
Output is correct |
22 |
Correct |
1652 ms |
732 KB |
Output is correct |
23 |
Correct |
1417 ms |
768 KB |
Output is correct |
24 |
Correct |
1439 ms |
776 KB |
Output is correct |
25 |
Correct |
1466 ms |
852 KB |
Output is correct |
26 |
Correct |
1466 ms |
784 KB |
Output is correct |
27 |
Correct |
1517 ms |
788 KB |
Output is correct |
28 |
Correct |
1497 ms |
1008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1570 ms |
896 KB |
Output is correct |
2 |
Execution timed out |
9031 ms |
1672 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
11 ms |
348 KB |
Output is correct |
3 |
Correct |
71 ms |
512 KB |
Output is correct |
4 |
Correct |
72 ms |
524 KB |
Output is correct |
5 |
Correct |
86 ms |
512 KB |
Output is correct |
6 |
Correct |
64 ms |
516 KB |
Output is correct |
7 |
Correct |
68 ms |
348 KB |
Output is correct |
8 |
Correct |
72 ms |
508 KB |
Output is correct |
9 |
Correct |
80 ms |
348 KB |
Output is correct |
10 |
Correct |
65 ms |
344 KB |
Output is correct |
11 |
Correct |
64 ms |
512 KB |
Output is correct |
12 |
Correct |
74 ms |
508 KB |
Output is correct |
13 |
Correct |
71 ms |
512 KB |
Output is correct |
14 |
Correct |
85 ms |
504 KB |
Output is correct |
15 |
Correct |
66 ms |
508 KB |
Output is correct |
16 |
Correct |
68 ms |
344 KB |
Output is correct |
17 |
Correct |
69 ms |
504 KB |
Output is correct |
18 |
Correct |
68 ms |
512 KB |
Output is correct |
19 |
Correct |
1457 ms |
856 KB |
Output is correct |
20 |
Correct |
1629 ms |
784 KB |
Output is correct |
21 |
Correct |
1577 ms |
780 KB |
Output is correct |
22 |
Correct |
1652 ms |
732 KB |
Output is correct |
23 |
Correct |
1417 ms |
768 KB |
Output is correct |
24 |
Correct |
1439 ms |
776 KB |
Output is correct |
25 |
Correct |
1466 ms |
852 KB |
Output is correct |
26 |
Correct |
1466 ms |
784 KB |
Output is correct |
27 |
Correct |
1517 ms |
788 KB |
Output is correct |
28 |
Correct |
1497 ms |
1008 KB |
Output is correct |
29 |
Correct |
1570 ms |
896 KB |
Output is correct |
30 |
Execution timed out |
9031 ms |
1672 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |