Submission #108726

#TimeUsernameProblemLanguageResultExecution timeMemory
108726Mahdi_JfriEditor (BOI15_edi)C++14
35 / 100
3040 ms6668 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...