# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
26840 | yutaka1999 | Editor (BOI15_edi) | C++14 | 309 ms | 50336 KiB |
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 <cstdio>
#include <cstdlib>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 300005
#define BT 20
using namespace std;
int A[SIZE];
int par[SIZE][BT];
int mn[SIZE][BT];
int ans[SIZE];
int main()
{
int n;
scanf("%d",&n);
memset(par,-1,sizeof(par));
memset(mn,-1,sizeof(mn));
for(int i=0;i<n;i++)
{
int a;
scanf("%d",&a);
if(a>0)
{
ans[i]=a;
par[i][0]=i;
}
else
{
a=-a;
int to=i-1;
for(int j=BT-1;j>=0;j--)
{
if(mn[to][j]>=a)
{
to=par[to][j];
}
}
to--;
if(to==-1)
{
ans[i]=0;
mn[i][0]=a;
}
else
{
ans[i]=ans[to];
int now=to,c=a;
for(int j=0;j<BT;j++)
{
par[i][j]=now;
mn[i][j]=c;
if(now!=-1)
{
c=min(c,mn[now][j]);
now=par[now][j];
}
}
}
}
printf("%d\n",ans[i]);
}
return 0;
}
Compilation message (stderr)
# | 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... |