SMBC 编程竞赛 #2(第 481 场 AtCoder Beginner Contest)
C
银行账户
Bank Accounts
AtCoder
⌀ 96
原题
← BD →

银行账户AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

In the backyard of Kowasugi Bank, ghosts are growing pumpkins. You have decided to open bank accounts for the pumpkins.

在 Kowasugi 银行的后院里,幽灵们正在种南瓜。你决定为这些南瓜开设银行账户。

AI (CI翻译)

When a bank account for a pumpkin is opened, it is assigned one name and one ID. The ID is chosen as the smallest positive integer that is not yet used as an ID.

为南瓜开设银行账户时,会为该账户分配一个名称和一个 ID。ID 取尚未被用作 ID 的最小正整数。AI (CI翻译)

Initially, no bank accounts for pumpkins have been opened. The following event occurs $Q$ times; process them in order.

最初,没有为任何南瓜开设银行账户。以下事件会发生 $Q$ 次,请按顺序处理。AI (CI翻译)

  • A pumpkin comes and introduces itself with the name $s$.
  • If there is an account assigned the name $s$, print its ID.
    • If there is no account assigned the name $s$, open one new account with the name $s$ and print its ID.
  • 一个南瓜前来,并自我介绍说它的名字是 $s$。
  • 如果存在名称为 $s$ 的账户,输出其 ID。
    • 如果不存在名称为 $s$ 的账户,则开设一个名称为 $s$ 的新账户,并输出其 ID。
AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $Q$ is an integer between $1$ and $2 \times 10^5$, inclusive.
  • In each event, $s$ is a string of length between $1$ and $10$, inclusive, consisting of lowercase English letters.
  • $Q$ 是 $1$ 到 $2 \times 10^5$ 之间的整数(包含两端)。
  • 在每次事件中,$s$ 是一个长度为 $1$ 到 $10$(包含两端)、仅由小写英文字母组成的字符串。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入通过标准输入以如下格式给出:AI (CI翻译)

Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q

Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q
AI (CI翻译)

$\mathrm{query}_i$ represents the $i$-th event and is given in the following format:

$\mathrm{query}_i$ 表示第 $i$ 次事件,以如下格式给出:AI (CI翻译)

s

s
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Print $Q$ lines. The $i$-th line should contain the value to be printed in the $i$-th event.

输出 $Q$ 行。第 $i$ 行应包含第 $i$ 次事件中应输出的值。AI (CI翻译)

样例

Input #1
8
pumpkin
hobak
pompoen
hobak
pumpkin
boga
boga
hobak
Output #1
1
2
3
2
1
4
4
2
The events proceed as follows. - In the $1$-st event, a new account with the name `pumpkin` and ID $1$ is opened. - In the $2$-nd event, a new account with the name `hobak` and ID $2$ is opened. - In the $3$-rd event, a new account with the name `pompoen` and ID $3$ is opened. - In the $4$-th event, an account with the name `hobak` already exists, and its ID is $2$. - In the $5$-th event, an account with the name `pumpkin` already exists, and its ID is $1$. - In the $6$-th event, a new account with the name `boga` and ID $4$ is opened. - In the $7$-th event, an account with the name `boga` already exists, and its ID is $4$. - In the $8$-th event, an account with the name `hobak` already exists, and its ID is $2$.
Input #2
7
joayo
joayo
joayo
joayo
joayo
joayo
joayo
Output #2
1
1
1
1
1
1
1
题目信息
题号
abc481_c
时间限制
2 s
内存限制
1024 MB

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