#include "bubblesort2.h"
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int aib[500005];
int ub(int x)
{
return x&(-x);
}
int nr,n,i,v[500005];
map <int,int> m;
void update(int poz,int val)
{
int i;
for (i=poz;i<=nr;i+=ub(i))
{
aib[i]+=val;
}
}
int suma(int poz)
{
int i,sum=0;
for (i=poz;i>=1;i-=ub(i))
{
sum=sum+aib[i];
}
return sum;
}
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> val){
int q=X.size();
n=A.size();
for (i=0;i<n;i++)
{
v[i+1]=A[i];
}
for (i=1;i<=n;i++)
{
m[v[i]]=1;
}
for (i=0;i<q;i++)
{
m[val[i]]=1;
}
nr=0;
for (auto ind: m)
{
nr++;
m[ind.first]=nr;
}
for (i=1;i<=n;i++)
{
v[i]=m[v[i]];
}
int j;
vector <int> sol;
for (i=0;i<q;i++)
{
v[X[i]+1]=m[val[i]];
int maxim=0;
for (j=1;j<=n;j++)
{
maxim=max(maxim,suma(nr)-suma(v[j]));
update(v[j],1);
}
for (j=1;j<=n;j++)
{
update(v[j],-1);
}
sol.push_back(maxim);
}
return sol;
}
/*
int readInt(){
int i;
if(scanf("%d",&i)!=1){
fprintf(stderr,"Error while reading input\n");
exit(1);
}
return i;
}
int main(){
int N,Q;
N=readInt();
Q=readInt();
std::vector<int> A(N);
for(int i=0;i<N;i++)
A[i]=readInt();
std::vector<int> X(Q),V(Q);
for(int j=0;j<Q;j++){
X[j]=readInt();
V[j]=readInt();
}
std::vector<int> res=countScans(A,X,V);
for(int j=0;j<int(res.size());j++)
printf("%d\n",res[j]);
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
332 KB |
Output is correct |
2 |
Correct |
32 ms |
456 KB |
Output is correct |
3 |
Correct |
182 ms |
612 KB |
Output is correct |
4 |
Correct |
184 ms |
728 KB |
Output is correct |
5 |
Correct |
181 ms |
708 KB |
Output is correct |
6 |
Correct |
175 ms |
616 KB |
Output is correct |
7 |
Correct |
178 ms |
588 KB |
Output is correct |
8 |
Correct |
180 ms |
596 KB |
Output is correct |
9 |
Correct |
180 ms |
836 KB |
Output is correct |
10 |
Correct |
170 ms |
588 KB |
Output is correct |
11 |
Correct |
175 ms |
588 KB |
Output is correct |
12 |
Correct |
174 ms |
584 KB |
Output is correct |
13 |
Correct |
168 ms |
580 KB |
Output is correct |
14 |
Correct |
162 ms |
564 KB |
Output is correct |
15 |
Correct |
162 ms |
560 KB |
Output is correct |
16 |
Correct |
171 ms |
676 KB |
Output is correct |
17 |
Correct |
166 ms |
560 KB |
Output is correct |
18 |
Correct |
166 ms |
540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
332 KB |
Output is correct |
2 |
Correct |
32 ms |
456 KB |
Output is correct |
3 |
Correct |
182 ms |
612 KB |
Output is correct |
4 |
Correct |
184 ms |
728 KB |
Output is correct |
5 |
Correct |
181 ms |
708 KB |
Output is correct |
6 |
Correct |
175 ms |
616 KB |
Output is correct |
7 |
Correct |
178 ms |
588 KB |
Output is correct |
8 |
Correct |
180 ms |
596 KB |
Output is correct |
9 |
Correct |
180 ms |
836 KB |
Output is correct |
10 |
Correct |
170 ms |
588 KB |
Output is correct |
11 |
Correct |
175 ms |
588 KB |
Output is correct |
12 |
Correct |
174 ms |
584 KB |
Output is correct |
13 |
Correct |
168 ms |
580 KB |
Output is correct |
14 |
Correct |
162 ms |
564 KB |
Output is correct |
15 |
Correct |
162 ms |
560 KB |
Output is correct |
16 |
Correct |
171 ms |
676 KB |
Output is correct |
17 |
Correct |
166 ms |
560 KB |
Output is correct |
18 |
Correct |
166 ms |
540 KB |
Output is correct |
19 |
Correct |
2760 ms |
1744 KB |
Output is correct |
20 |
Correct |
3295 ms |
1664 KB |
Output is correct |
21 |
Correct |
3241 ms |
1860 KB |
Output is correct |
22 |
Correct |
3296 ms |
1716 KB |
Output is correct |
23 |
Correct |
3087 ms |
1700 KB |
Output is correct |
24 |
Correct |
3132 ms |
1764 KB |
Output is correct |
25 |
Correct |
2977 ms |
1536 KB |
Output is correct |
26 |
Correct |
2940 ms |
1628 KB |
Output is correct |
27 |
Correct |
3006 ms |
1560 KB |
Output is correct |
28 |
Correct |
3056 ms |
1344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1963 ms |
788 KB |
Output is correct |
2 |
Execution timed out |
9017 ms |
1212 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
332 KB |
Output is correct |
2 |
Correct |
32 ms |
456 KB |
Output is correct |
3 |
Correct |
182 ms |
612 KB |
Output is correct |
4 |
Correct |
184 ms |
728 KB |
Output is correct |
5 |
Correct |
181 ms |
708 KB |
Output is correct |
6 |
Correct |
175 ms |
616 KB |
Output is correct |
7 |
Correct |
178 ms |
588 KB |
Output is correct |
8 |
Correct |
180 ms |
596 KB |
Output is correct |
9 |
Correct |
180 ms |
836 KB |
Output is correct |
10 |
Correct |
170 ms |
588 KB |
Output is correct |
11 |
Correct |
175 ms |
588 KB |
Output is correct |
12 |
Correct |
174 ms |
584 KB |
Output is correct |
13 |
Correct |
168 ms |
580 KB |
Output is correct |
14 |
Correct |
162 ms |
564 KB |
Output is correct |
15 |
Correct |
162 ms |
560 KB |
Output is correct |
16 |
Correct |
171 ms |
676 KB |
Output is correct |
17 |
Correct |
166 ms |
560 KB |
Output is correct |
18 |
Correct |
166 ms |
540 KB |
Output is correct |
19 |
Correct |
2760 ms |
1744 KB |
Output is correct |
20 |
Correct |
3295 ms |
1664 KB |
Output is correct |
21 |
Correct |
3241 ms |
1860 KB |
Output is correct |
22 |
Correct |
3296 ms |
1716 KB |
Output is correct |
23 |
Correct |
3087 ms |
1700 KB |
Output is correct |
24 |
Correct |
3132 ms |
1764 KB |
Output is correct |
25 |
Correct |
2977 ms |
1536 KB |
Output is correct |
26 |
Correct |
2940 ms |
1628 KB |
Output is correct |
27 |
Correct |
3006 ms |
1560 KB |
Output is correct |
28 |
Correct |
3056 ms |
1344 KB |
Output is correct |
29 |
Correct |
1963 ms |
788 KB |
Output is correct |
30 |
Execution timed out |
9017 ms |
1212 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |