This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Power Of Ninja Go
#include <bits/stdc++.h>
//#ifdef atom #else #endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vii vector< ii >
#define pb push_back
const int maxn = 5e3+5;
int par[maxn];
int cur[maxn];
int keep[maxn][maxn];
int num[maxn];
int main()
{
//#ifndef atom freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif
int n; cin >> n;
for(int i = 1; i<= n; i++)
{
int x; cin >> x;
if(x> 0)
{
num[i] = x;
int foo = par[i-1];
for(int j = 0; j<= n; j++) keep[i][j] = keep[foo][j];
keep[i][0] = i;
par[i] = i-1;
}
else
{
x = -x;
int fnd = 0;
for(int j = x-1; j>= 0; j--)
{
if(keep[i-1][j])
{
fnd = keep[i-1][j]; break;
}
}
//printf("fnd is %d\n", fnd);
for(int j = 0; j<= n; j++) keep[i][j] = keep[par[fnd]][j];
keep[i][x] = i;
par[i] = fnd;
}
//printf("%d: ", i);
//for(int j = 0; j<= n; j++) printf("%d ", keep[i][j]);
//printf("\n");
printf("%d\n", num[keep[i][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... |