#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct A
{
int F,S;
};
int N,M;
map<int,vector<int> >V;
set<int> S;
int lenn[500005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin>>N;
fill (lenn,lenn+N+1,N+1);
V[-1000000001].push_back(0);
for(int i=1;i<=N;i++)
{
int T;
cin>>T;
V[-T].push_back(i);
}
for(auto&I:V)
{
for(auto&J:I.second)S.insert(J);
for(auto&J:I.second)
{
auto K=S.lower_bound(J);
if(K!=S.begin())
{
int&R=lenn[J-*(--K)-1];
R=min(R,J);
}
}
}
for(int i=N-1;i;i--)lenn[i]=min(lenn[i],lenn[i+1]);
for(int i=1;i<=N;i++)
{
if(lenn[i]==N+1)printf("-1 ");
else printf("%d ",lenn[i]-i);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
3 ms |
484 KB |
Output is correct |
4 |
Correct |
2 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
520 KB |
Output is correct |
6 |
Correct |
3 ms |
648 KB |
Output is correct |
7 |
Correct |
2 ms |
648 KB |
Output is correct |
8 |
Correct |
2 ms |
648 KB |
Output is correct |
9 |
Correct |
2 ms |
648 KB |
Output is correct |
10 |
Correct |
2 ms |
648 KB |
Output is correct |
11 |
Correct |
2 ms |
648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
3 ms |
484 KB |
Output is correct |
4 |
Correct |
2 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
520 KB |
Output is correct |
6 |
Correct |
3 ms |
648 KB |
Output is correct |
7 |
Correct |
2 ms |
648 KB |
Output is correct |
8 |
Correct |
2 ms |
648 KB |
Output is correct |
9 |
Correct |
2 ms |
648 KB |
Output is correct |
10 |
Correct |
2 ms |
648 KB |
Output is correct |
11 |
Correct |
2 ms |
648 KB |
Output is correct |
12 |
Correct |
3 ms |
844 KB |
Output is correct |
13 |
Correct |
6 ms |
1108 KB |
Output is correct |
14 |
Correct |
96 ms |
8480 KB |
Output is correct |
15 |
Correct |
178 ms |
13068 KB |
Output is correct |
16 |
Correct |
273 ms |
17268 KB |
Output is correct |
17 |
Correct |
767 ms |
43296 KB |
Output is correct |
18 |
Execution timed out |
1068 ms |
59604 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |