301892: CF358C. Dima and Containers

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Dima and Containers

题目描述

Dima has a birthday soon! It's a big day! Saryozha's present to Dima is that Seryozha won't be in the room and won't disturb Dima and Inna as they celebrate the birthday. Inna's present to Dima is a stack, a queue and a deck. Inna wants her present to show Dima how great a programmer he is. For that, she is going to give Dima commands one by one. There are two types of commands: 1. Add a given number into one of containers. For the queue and the stack, you can add elements only to the end. For the deck, you can add elements to the beginning and to the end. 2. Extract a number from each of at most three distinct containers. Tell all extracted numbers to Inna and then empty all containers. In the queue container you can extract numbers only from the beginning. In the stack container you can extract numbers only from the end. In the deck number you can extract numbers from the beginning and from the end. You cannot extract numbers from empty containers. Every time Dima makes a command of the second type, Inna kisses Dima some (possibly zero) number of times. Dima knows Inna perfectly well, he is sure that this number equals the sum of numbers he extracts from containers during this operation. As we've said before, Dima knows Inna perfectly well and he knows which commands Inna will give to Dima and the order of the commands. Help Dima find the strategy that lets him give as more kisses as possible for his birthday!

输入输出格式

输入格式


The first line contains integer $ n $ $ (1<=n<=10^{5}) $ — the number of Inna's commands. Then $ n $ lines follow, describing Inna's commands. Each line consists an integer: 1. Integer $ a $ $ (1<=a<=10^{5}) $ means that Inna gives Dima a command to add number $ a $ into one of containers. 2. Integer $ 0 $ shows that Inna asks Dima to make at most three extractions from different containers.

输出格式


Each command of the input must correspond to one line of the output — Dima's action. For the command of the first type (adding) print one word that corresponds to Dima's choice: - pushStack — add to the end of the stack; - pushQueue — add to the end of the queue; - pushFront — add to the beginning of the deck; - pushBack — add to the end of the deck. For a command of the second type first print an integer $ k $ $ (0<=k<=3) $ , that shows the number of extract operations, then print $ k $ words separated by space. The words can be: - popStack — extract from the end of the stack; - popQueue — extract from the beginning of the line; - popFront — extract from the beginning from the deck; - popBack — extract from the end of the deck. The printed operations mustn't extract numbers from empty containers. Also, they must extract numbers from distinct containers. The printed sequence of actions must lead to the maximum number of kisses. If there are multiple sequences of actions leading to the maximum number of kisses, you are allowed to print any of them.

输入输出样例

输入样例 #1

10
0
1
0
1
2
0
1
2
3
0

输出样例 #1

0
pushStack
1 popStack
pushStack
pushQueue
2 popStack popQueue
pushStack
pushQueue
pushFront
3 popStack popQueue popFront

输入样例 #2

4
1
2
3
0

输出样例 #2

pushStack
pushQueue
pushFront
3 popStack popQueue popFront

Input

题意翻译

# Dima和容器 ## 题目描述 Dima 的生日快到了!这是个重要的日子!Saryozha 送给 Dima的礼物是,他会离开房间,不打扰 Dima 和 Inna 庆祝生日。Inna 送给 Dima 的礼物是一个堆栈(stack)、一个队列(queue)和一个双端队列(deck)。 Inna 希望她的礼物能向 Dima 展示他是多么优秀的程序员。为此,她会逐个给 Dima 发送命令。有两种类型的命令: 1. 将给定的数字添加到其中一个容器中。对于队列和堆栈,你只能将元素添加到末尾。对于双端队列,你可以将元素添加到开头或末尾。 2. 从至多三个不同的容器中提取一个数字。将所有提取出的数字告诉 Inna,然后清空所有容器。对于队列容器,你只能从开头提取数字。对于堆栈容器,你只能从末尾提取数字。对于双端队列容器,你可以从开头或末尾提取数字。你不能从空容器中提取数字。 每次 Dima 执行第二类型的命令时,Inna 就会亲吻 Dima 若干次(可能为零)。Dima 非常了解 Inna,他确定这个数字等于他在此操作中从容器中提取的数字之和。 正如我们之前说的,Dima 非常了解 Inna,他知道 Inna 将给他什么命令以及命令的顺序。帮助 Dima 找到让他在生日上获得尽可能多亲吻的策略! ## 输入格式 第一行包含整数 $n\ (1\le n\le10^5) $ — Inna 的命令数量。然后是 $n$ 行,描述 Inna 的命令。每行包含一个整数: 1. 整数 $a\ (1\le a\le10^5)$ 表示 Inna 命令 Dima 将数字 $a$ 添加到其中一个容器中。 2. 整数 $0$ 表示 Inna 要求 Dima 从不同的容器中最多提取三个数字。 ## 输出格式 输出的每个命令必须对应输出的一行 — Dima 的动作。 对于第一类型的命令(添加),打印一个与 Dima 的选择相对应的单词: - pushStack — 添加到堆栈的末尾; - pushQueue — 添加到队列的末尾; - pushFront — 添加到双端队列的开头; - pushBack — 添加到双端队列的末尾。 对于第二类型的命令,首先打印一个整数 $k (0\le k\le3) $,表示提取操作的数量,然后打印 $k$ 个以空格分隔的单词。这些单词可以是: - popStack — 从堆栈的末尾提取; - popQueue — 从队列的开头提取; - popFront — 从双端队列的开头提取; - popBack — 从双端队列的末尾提取。 所打印的操作不能从空容器中提取数字。同时,它们必须从不同的容器中提取数字。 打印的行为序列必须导致亲吻次数最多。如果有多个行为序列导致亲吻次数最多,你可以打印任何一个。 ## 样例 #1 ### 样例输入 #1 ``` 10 0 1 0 1 2 0 1 2 3 0 ``` ### 样例输出 #1 ``` 0 pushStack 1 popStack pushStack pushQueue 2 popStack popQueue pushStack pushQueue pushFront 3 popStack popQueue popFront ``` ## 样例 #2 ### 样例输入 #2 ``` 4 1 2 3 0 ``` ### 样例输出 #2 ``` pushStack pushQueue pushFront 3 popStack popQueue popFront ``` by zhangsenhao6728

加入题单

上一题 下一题 算法标签: