Submission #1274528

#TimeUsernameProblemLanguageResultExecution timeMemory
1274528beheshtEditor (BOI15_edi)C++20
0 / 100
106 ms26868 KiB
#include <bits/stdc++.h>

#define d1(x)                cout << #x << " : " << x << endl << flush
#define d2(x, y)             cout << #x << " : " << x << "   " << #y << " : " << y << endl << flush
#define d3(x, y, z)          cout << #x << " : " << x << "   " << #y << " : " << y << "   " << #z << " : " << z << endl << flush
#define d4(x, y, z, a)       cout << #x << " : " << x << "   " << #y << " : " << y << "   " << #z << " : " << z << "    "<< #a << " : " << a << endl << flush
#define arr(x)               array <ll, x>
#define ld                   long double
#define ll                   long long
#define int                  long long
#define pb                   push_back
#define endl                 '\n'
#define lc                   v << 1
#define rc                   v << 1 | 1

using namespace std;

const int INF = 1e9 + 24 + (34 / 10); // 34 ---> 35
const int MAXN = 3e5 + 24 + (34 / 10); // 34 ---> 35

int nex[MAXN], pre[MAXN], a[MAXN];

void del(int ind){
	nex[pre[ind]] = nex[ind];
	pre[nex[ind]] = pre[ind];
}

signed main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	set <arr(2)> s;

	for(int i = 1; i <= n; i++){
		cin >> a[i];

		nex[i] = i + 1;
		pre[i] = i - 1;
		
		if(a[i] < 0)
			s.insert({a[i], i});

		else
			s.insert({0, -i});
	}

	pre[n + 1] = n;
	nex[0] = 1;

	int ans = 0;

	while(!s.empty()){
		auto [val, ind] = *s.begin();

		if(val == 0){
			ans = a[-ind];
			break;
		}

		int nind = pre[ind];
		int nval = a[nind];
		
		del(ind);
		del(nind);
		s.erase({val, ind});

		if(nval > 0)
			s.erase({0, -nind});
		
		else
			s.erase({nval, nind});
	}

	for(int i = 1; i < n; i++)
		cout << 1 << endl;

	cout << ans << endl;
}

// Ey To Bahane! :_)))

// -------------<3------------- //
/*
Magasan dor shirini: 

1. MAXN
2. Input style
3. index or value? Masale In Ast!	
4. MOD 

*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...