#include <bits/stdc++.h>
using namespace std;
stack<int> a[100086];
char c;
int main()
{
	int n, x;
	int sum=0;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		sum++;
		a[sum] = a[sum-1];
		cin >> c;
		if(c == 'a')
		{
			cin >> x;
			a[sum].push(x);
			cout << a[sum].top() << endl;
		}
		else		
		if(c == 's')
		{
			a[sum].pop();
			if(!a[sum].empty())
			{
				cout << a[sum].top() << endl;
			}
			else
			{
				cout << "-1" << endl;				
			}
		}
		else		
		if(c == 't')
		{
			cin >> x;
			a[sum] = a[x-1];
			if(!a[sum].empty())
			{
				cout << a[sum].top() << endl;
			}
			else
			{
				cout << "-1" << endl;
			}
		}	
	}
	return 0;
}

0 comments

No comments so far...

Information

ID
5210
Time
1000ms
Memory
256MiB
Difficulty
4
Tags
# Submissions
4
Accepted
0
Uploaded By