Codeforces Beta Round 35(Div. 2)
B
仓库
Warehouse
Codeforces
1700
原题
← AC →

仓库AI (CI翻译)

Once upon a time, when the world was more beautiful, the sun shone brighter, the grass was greener and the sausages tasted better Arlandia was the most powerful country. And its capital was the place where our hero DravDe worked. He couldn’t program or make up problems (in fact, few people saw a computer those days) but he was nevertheless happy. He worked in a warehouse where a magical but non-alcoholic drink Ogudar-Olok was kept. We won’t describe his work in detail and take a better look at a simplified version of the warehouse.

很久以前,在一个更加美好的世界里,阳光更加明亮,青草更加翠绿,香肠也更加美味。那时的阿兰迪亚是最强大的国家,而我们的主人公 DravDe 就在它的首都工作。他不会编程,也不会编写题目(事实上,那时很少有人见过计算机),但他依然过得很开心。他在一个仓库里工作,仓库中存放着一种神奇但不含酒精的饮料 Ogudar-Olok。我们不打算详细描述他的工作,而是来看看这个仓库的简化模型。AI (CI翻译)

The warehouse has one set of shelving. It has $*n*$ shelves, each of which is divided into $*m*$ sections. The shelves are numbered from top to bottom starting from $1$ and the sections of each shelf are numbered from left to right also starting from $1$. Each section can contain exactly one box of the drink, and try as he might, DravDe can never put a box in a section that already has one. In the course of his work DravDe frequently notices that he has to put a box in a filled section. In that case his solution is simple. DravDe ignores that section and looks at the next one to the right. If it is empty, he puts the box there. Otherwise he keeps looking for the first empty section to the right. If no empty section is found by the end of the shelf, he looks at the shelf which is under it, then the next one, etc. Also each time he looks at a new shelf he starts from the shelf’s beginning. If DravDe still can’t find an empty section for the box, he immediately drinks it all up and throws the empty bottles away not to be caught.

仓库里有一组货架,共有 $*n*$ 层,每层分为 $*m*$ 个格子。货架从上到下编号,从 $1$ 开始;每层货架上的格子从左到右编号,也从 $1$ 开始。每个格子恰好能放一箱饮料。无论 DravDe 怎么尝试,他都不能把箱子放进已经有箱子的格子里。工作中,DravDe 经常发现自己需要把箱子放进一个已满的格子。这时他的处理方法很简单:他跳过这个格子,查看右边相邻的格子。如果那里是空的,就把箱子放进去;否则继续向右寻找第一个空格子。如果直到该层货架末尾仍未找到空格子,他就查看下一层货架,然后继续向下查找。每次查看新的一层货架时,他都会从该层的第一个格子开始寻找。如果 DravDe 仍然找不到可以放箱子的空格子,他就立刻把饮料喝光,并把空瓶扔掉,以免被发现。AI (CI翻译)

After one great party with a lot of Ogudar-Olok drunk DravDe asked you to help him. Unlike him, you can program and therefore modeling the process of counting the boxes in the warehouse will be easy work for you.

在一次喝了很多 Ogudar-Olok 的盛大派对之后,DravDe 请你帮忙。和他不同,你会编程,因此模拟仓库中箱子的存取过程对你来说轻而易举。AI (CI翻译)

The process of counting contains two types of query messages:

存取过程包含两种查询:AI (CI翻译)

  • «+1 x y id» (where $*x*$, $*y*$ are integers, $1 ≤ *x* ≤ *n*$, $1 ≤ *y* ≤ *m*$, and $*id*$ is a string of lower case Latin letters — from $1$ to $10$ characters long). That query means that the warehouse got a box identified as $*id*$, which should be put in the section $*y*$ on the shelf $*x*$. If the section is full, use the rules described above. It is guaranteed that every moment of the process the identifiers of all the boxes in the warehouse are different. You don’t have to answer this query.
  • «-1 id» (where $*id*$ is a string of lower case Latin letters — from $1$ to $10$ characters long). That query means that a box identified as $*id*$ is removed from the warehouse. You have to answer this query (see output format).
  • «+1 x y id»(其中 $*x*$、$*y*$ 为整数,$1 ≤ *x* ≤ *n*$、$1 ≤ *y* ≤ *m*$,$*id*$ 是由小写拉丁字母组成的字符串,长度为 $1$ 到 $10$ 个字符)。该查询表示仓库收到一箱编号为 $*id*$ 的饮料,应将它放在第 $*x*$ 层货架的第 $*y*$ 个格子中。如果该格子已满,则按照上文所述的规则寻找位置。保证在整个过程中,仓库中所有箱子的编号始终各不相同。你不需要回答此查询。
  • «-1 id»(其中 $*id*$ 是由小写拉丁字母组成的字符串,长度为 $1$ 到 $10$ 个字符)。该查询表示从仓库中取出编号为 $*id*$ 的箱子。你需要回答此查询(见输出格式)。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The first input line contains integers $*n*$, $*m*$ and $*k*$ ($1 ≤ *n*, *m* ≤ 30$, $1 ≤ *k* ≤ 2000$) — the height, the width of shelving and the amount of the operations in the warehouse that you need to analyze. In the following $*k*$ lines the queries are given in the order of appearance in the format described above.

输入的第一行包含整数 $*n*$、$*m*$ 和 $*k*$($1 ≤ *n*, *m* ≤ 30$,$1 ≤ *k* ≤ 2000),分别表示货架的高度、宽度,以及需要分析的仓库存取操作数。接下来的 $k$ 行按照出现顺序给出查询,格式如上所述。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each query of the «-1 id» type output two numbers in a separate line — index of the shelf and index of the section where the box with this identifier lay. If there was no such box in the warehouse when the query was made, output «-1 -1» without quotes.

对于每个 «-1 id» 类型的查询,输出一行两个数:该箱子所在的货架层号和格子编号。如果执行查询时仓库中没有该箱子,则输出 «-1 -1»,不含引号。AI (CI翻译)

样例

Input #1
2 2 9
+1 1 1 cola
+1 1 1 fanta
+1 1 1 sevenup
+1 1 1 whitekey
-1 cola
-1 fanta
-1 sevenup
-1 whitekey
-1 cola
Output #1
1 1
1 2
2 1
2 2
-1 -1
InputCopy OutputCopy
Input #2
2 2 8
+1 1 1 cola
-1 cola
+1 1 1 fanta
-1 fanta
+1 1 1 sevenup
-1 sevenup
+1 1 1 whitekey
-1 whitekey
Output #2
1 1
1 1
1 1
1 1
InputCopy OutputCopy
题目信息
题号
35B
时间限制
2 s
内存限制
64 MB
标签
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。