1468C. Berpizza

C. Berpizza

time limit per test

5 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.

At the start of the working day, there are no customers at the Berpizza. They come there one by one. When a customer comes into the pizzeria, she sits and waits for Monocarp or Polycarp to serve her. Monocarp has been working in Berpizza for just two weeks, so whenever he serves a customer, he simply chooses the one who came to Berpizza first, and serves that customer.

On the other hand, Polycarp is an experienced waiter at Berpizza, and he knows which customers are going to spend a lot of money at the pizzeria (and which aren't) as soon as he sees them. For each customer, Polycarp estimates the amount of money this customer can spend, and when he serves a customer, he chooses the one that is expected to leave the most money at Berpizza (in case there are several such customers, he chooses the one who came first among them).

Obviously, no customer can be served twice, so Monocarp and Polycarp choose which customer to serve only among those who haven't been served yet.

When the number of customers gets really high, it becomes difficult for both Monocarp and Polycarp to choose the customer they are going to serve. Your task is to write a program that makes these choices for them. Formally, your program should be able to process three types of queries:

  • 11 mm — a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as mm;
  • 22 — Monocarp serves a customer which came to the pizzeria first;
  • 33 — Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are several such customers, the one that came to the pizzeria first is chosen).

For each query of types 22 and 33, report the number of the customer who was served (the customers are numbered in the order they come to the pizzeria, starting from 11).

Input

The first line contains one integer qq (2≤q≤5⋅1052≤q≤5⋅105) — the number of queries.

Then qq lines follow, each describing a query in one of the following formats:

  • 11 mm (1≤m≤5⋅1051≤m≤5⋅105) — a customer comes to Berpizza, and Polycarp estimates the amount of money that they will spend as mm;
  • 22 — Monocarp serves a customer which came to the pizzeria first;
  • 33 — Polycarp serves a customer which is expected to spend the largest amount of money at the pizzeria (if there are multiple such customers, the one that came to the pizzeria first is chosen).

Queries of type 22 and 33 are asked only when there exists at least one customer that hasn't been served yet. There is at least one query of type 22 or 33 in the input.

Output

For each query of type 22 or 33, print one integer — the number of the customer that has been served in that event. The customers are numbered in the order in which they come to the pizzeria, starting from 11.

Examples

input

Copy

8
1 8
1 10
1 6
3
2
1 9
2
3

output

Copy

2 1 3 4 

input

Copy

6
1 8
1 10
1 8
3
3
3

output

Copy

2 1 3 

input

Copy

8
1 103913
3
1 103913
1 103913
3
1 103913
1 103913
2

output

Copy

1 2 3 

可以用优先队列,用set也可以,不过也可以用两个set,一个set的key值是排队顺序,还有一个set的key值是客户付款的大小。

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include <tuple>//包含tie的头文件
using namespace std;
const int manx = 2e5 + 10;
int k[manx];
set <pair<int, int>>a, b;//将入场顺序和客户付款金额打包
int main()
{
	int t;
	cin >> t;
	int cnt = 0;
	while (t--)
	{
		int n;
		cin >> n;
		if (n == 1)
		{
			int m;
			cin >> m;
			cnt++;
			a.insert({ cnt,m });//由于set会自动排序,key值默认first也就是cnt,入场顺序。
			b.insert({ -m,cnt });//b的key值是客户金额,采用-m将最大值排在最前面。
		}
		else if (n == 2)
		{
			int id, m;
			tie(id, m) = *a.begin();//用tie将id和m赋值。
			cout << id;
			a.erase(make_pair(id, m));//弹出服务的客户。
			b.erase(make_pair(-m, id));
		}
		else
		{
			int id, m;
			tie(m, id) = *b.begin();//b第一个元素也就是未被服务的客户中金额最大的。
			m *= -1;//为弹出做准备。
			cout << id;
			a.erase(make_pair(id, m));
			b.erase(make_pair(-m, id));
		}
		cout << " ";
	}
	
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值