This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
long long n,v[300010],ans[300010],ant[300010];
int main()
{
cin>>n;
for(int i=1;i<=n;++i)
{
cin>>v[i];
if(v[i]>0)
{
ans[i]=v[i];
ant[i]=i-1;
continue;
}
int poz=i-1;
while(v[poz]<=v[i])
{
poz=ant[poz];
}
ant[i]=poz-1;
ans[i]=ans[ant[i]];
}
for(int i=1;i<=n;++i)
cout<<ans[i]<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |