#P11027. [COTS 2020] 餐厅 Restoran

    ID: 12440 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2020Special JudgeO2优化COCI(克罗地亚)

[COTS 2020] 餐厅 Restoran

Background

Translated from Izborne Pripreme 2020 (Croatian IOI/CEOI Team Selection) D2T2。2s,0.5G\texttt{2s,0.5G}

Problem Description

There are NN people queuing in front of a Soviet restaurant, numbered 1N1 \sim N in order.

There is only one dish in the restaurant, and it is also the signature dish—fried eggs. There is no chef in the restaurant, so the food is cooked by the customers themselves.

Due to limited equipment, at any moment, at most one person can cook, and at any moment, at most one person can eat.

Define the “total dining time” as the time needed from when the first person starts preparing food to when the last person finishes eating.

Cooking and eating do not have to follow the queue order; a customer who cooks earlier may eat later.

Person ii has cooking time aia_i and eating time bib_i. You need to find the minimum possible total dining time under an optimal arrangement.

In addition, there are MM events:

  • DOLAZI a b\texttt{DOLAZI a b}: A new customer arrives, with cooking time aa and eating time bb. Suppose this is the ii-th arriving new customer, then their number is (N+i)(N+i).
  • ODLAZI x\texttt{ODLAZI x}: Customer xx leaves the queue.
  • POREDAK\texttt{POREDAK}: The customers are very impatient and want to know the optimal strategy that makes the total dining time as short as possible.

For the first two types of events, you need to output the minimum total dining time after the event ends.

For the third type of event, you need to output the best cooking order and eating order at that moment.

Input Format

The first line contains two positive integers N,MN, M.

The next NN lines: the ii-th line contains two positive integers ai,bia_i, b_i.

The next MM lines: each line describes an event.

The testdata guarantees that all events are valid, and at every moment there is at least one customer.

Output Format

Output (M+1)(M+1) lines.

The first line outputs the minimum total dining time initially.

Then for the next MM lines, for the ii-th line:

  • If the ii-th event is DOLAZI\texttt{DOLAZI} or ODLAZI\texttt{ODLAZI}, output one integer, the minimum total dining time after this event ends.
  • Otherwise, suppose there are currently kk customers, output 2k2k integers describing an optimal strategy: the first kk integers are the cooking order, and the last kk integers are the eating order.
2 1
1 3
2 3
POREDAK
7
1 2 1 2
1 4
4 3
DOLAZI 3 8
DOLAZI 5 2
ODLAZI 1
ODLAZI 3
7
14
16
13
11

Hint

Constraints

For 100%100\% of the testdata, it is guaranteed that:

  • 1N,M2×1051 \le N, M \le 2 \times 10^5
  • 1ai,bi,a,b1091 \le a_i, b_i, a, b \le 10^9
  • All events are valid, and at every moment there is at least one customer;
  • There are at most 10\bf 10 POREDAK\texttt{POREDAK} events.
Subtask ID NN \le MM \le Special Property Score
11 99 11 A 55
22 2020 1313
33 2×1052 \times 10^5 2121
44 2×1052 \times 10^5 B 2929
55 3232
  • Special Property A: Only POREDAK\texttt{POREDAK} events.
  • Special Property B: There are no POREDAK\texttt{POREDAK} events.

Translated by ChatGPT 5