CF1468C.Berpizza

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 ).

输入格式

The first line contains one integer qq ( 2q51052 \le q \le 5 \cdot 10^5 ) — the number of queries.

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

  • 11 mm ( 1m51051 \le m \le 5 \cdot 10^5 ) — 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.

输出格式

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 .

输入输出样例

  • 输入#1

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

    输出#1

    2 1 3 4
  • 输入#2

    6
    1 8
    1 10
    1 8
    3
    3
    3

    输出#2

    2 1 3
  • 输入#3

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

    输出#3

    1 2 3
首页