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;
const int nx=5e3+5;
int n, a, t[nx], vl[nx], p[nx], vs[nx];
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++)
{
cin>>t[i];
vs[i]=1;
if (t[i]>0) vl[i]=t[i], t[i]=0, p[i]=i;
else
{
t[i]=-t[i];
for (int j=1; j<i; j++) if (vs[j]&&t[j]<t[i]) p[i]=j;
}
int cnt=0, cur=i;
while (p[cur]!=cur)
{
if (cnt) vs[cur]=!vs[cur];
cnt++;
cur=p[cur];
}
if (cnt) vs[cur]=!vs[cur];
int res=0;
for (int j=1; j<=i; j++) if (!t[j]&&vs[j]) res=vl[j];
cout<<res<<'\n';
}
}
# | 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... |