#abc247d. D - Cylinder

D - Cylinder

Score : 400400 points

问题描述

我们有一个水平放置的圆柱体。给定 QQ 个查询,按照给定顺序处理它们。

  • 1 x c:在圆柱体右侧末端插入带有数字 xx 的球共 cc 个。
  • 2 c:从圆柱体内取出最左边的 cc 个球,并输出被取出球上数字之和。

我们假设球在圆柱体内的顺序始终保持不变。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a horizontal cylinder. Given QQ queries, process them in the given order.
Each query is of one of the following two types.

  • 1 x c: Insert cc balls, with a number xx written on each of them, to the right end of the cylinder.
  • 2 c: Take out the cc leftmost balls contained in the cylinder and print the sum of the numbers written on the balls that have been taken out.

We assume that the balls do never change their order in the cylinder.

Constraints

  • 1Q2×1051 \leq Q \leq 2\times 10^5
  • 0x1090 \leq x \leq 10^9
  • 1c1091 \leq c \leq 10^9
  • Whenever a query of type 2 c is given, there are cc or more balls in the cylinder.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

QQ

query1{\rm query}_1

\vdots

queryQ{\rm query}_Q

The ii-th query queryi{\rm query}_i is in one of the following two formats.

11 xx cc

22 cc

Output

Print the response to the queries of type 2 c in the given order, with newlines in between.

Sample Input 1

4
1 2 3
2 2
1 3 4
2 3

Sample Output 1

4
8
  • For the 11-st query, insert 33 balls, with a number 22 written on each of them, to the right end of the cylinder.
    The cylinder has now balls with numbers (2,2,2)(2,2,2) written on them, from left to right.
  • For the 22-nd query, take out the 22 leftmost balls contained in the cylinder.
    The numbers written on the balls taken out are 2,22,2, for a sum of 44, which should be printed. The cylinder has now a ball with a number (2)(2) written on it, from left to right.
  • For the 33-rd query, insert 44 balls, with a number 33 written on each of them, to the right end of the cylinder.
    The cylinder has now balls with numbers (2,3,3,3,3)(2,3,3,3,3) written on them, from left to right.
  • For the 44-th query, take out the 33 leftmost balls contained in the cylinder.
    The numbers written on the balls taken out are 2,3,32,3,3, for a sum of 88, which should be printed. The cylinder has now balls with numbers (3,3)(3,3) written on them, from left to right.

Sample Input 2

2
1 1000000000 1000000000
2 1000000000

Sample Output 2

1000000000000000000

Sample Input 3

5
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1

Sample Output 3

There may be nothing you should print.

update @ 2024/3/10 10:35:45