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;
#define ll long long
#define pb push_back
const int maxn = 5e5 + 20;
int a[maxn] , par[maxn];
bool active[maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
memset(active , 1 , sizeof active);
for(int i = 1; i <= n; i++)
{
cin >> a[i];
if(a[i] < 0)
{
for(int j = i - 1; j >= 0; j--)
if(active[j] && -a[j] < -a[i])
{
par[i] = j;
while(a[j] < 0)
{
active[j] ^= 1;
j = par[j];
}
active[j] ^= 1;
break;
}
}
for(int j = i; j >= 0; j--)
if(active[j] && a[j] >= 0)
{
cout << a[j] << endl;
break;
}
}
}
# | 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... |