B - Taro Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200200

問題文

AtCoder 王国では、長男に必ず「太郎」という名前を付けます。長男以外には「太郎」という名前は付けません。 長男とは、各家で生まれた男の子のうち最も早く生まれた者を指します。

AtCoder 王国には NN 戸の家があり、MM 人の赤子が生まれました。また、MM 人の赤子が生まれる前には、NN 戸のどの家も赤子が生まれたことはありませんでした。

赤子の情報が生まれの時系列順に与えられます。

ii 番目に生まれた赤子は、AiA_i 番目の家で生まれ、BiB_iM のとき男の子、F のとき女の子です。

MM 人の赤子それぞれについて、付けられた名前が「太郎」か判定してください。

制約

  • 1N,M1001\leq N,M\leq 100
  • 1AiN1\leq A_i\leq N
  • BiB_iM または F
  • 入力される数値は全て整数

入力

入力は以下の形式で標準入力から与えられる。

NN MM
A1A_1 B1B_1
\vdots
AMA_M BMB_M

出力

MM 行出力せよ。

i (1iM)i\ (1\leq i \leq M) 行目には、ii 番目に生まれた赤子の名前が「太郎」ならば Yes を、そうでない場合 No を出力せよ。


入力例 1Copy

Copy
2 4
1 M
1 M
2 F
2 M

出力例 1Copy

Copy
Yes
No
No
Yes

11 番目に生まれた赤子は、家 11 で生まれた男の子のうち最も早く生まれた者なので「太郎」です。

一方、22 番目に生まれた赤子は、家 11 で生まれた男の子のうち最も早く生まれた者ではないので「太郎」ではありません。

33 番目に生まれた赤子は、女の子なので「太郎」ではありません。

44 番目に生まれた赤子は、家 22 で生まれた男の子のうち最も早く生まれた者なので「太郎」です。33 番目に生まれた赤子も家 22 で生まれていますが、男の子のうち最も早く生まれた者を「太郎」と名付けることに注意してください。


入力例 2Copy

Copy
4 7
2 M
3 M
1 F
4 F
4 F
1 F
2 M

出力例 2Copy

Copy
Yes
Yes
No
No
No
No
No

Score : 200200 points

Problem Statement

In the Kingdom of AtCoder, the eldest son is always given the name Taro. No one else is given the name Taro. The eldest son is the earliest born male child in each family.

There are NN families in the Kingdom, and MM babies were born. Before the MM babies were born, none of the NN families had had any babies.

Information about the babies is given in chronological order of their birth.

The ii-th baby born was born in family AiA_i, and the baby is male if BiB_i is M, and female if it is F.

Determine for each of the MM babies whether the name given is Taro.

Constraints

  • 1N,M1001\leq N,M\leq 100
  • 1AiN1\leq A_i\leq N
  • BiB_i is M or F.
  • All numbers in the input are integers.

Input

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

NN MM
A1A_1 B1B_1
\vdots
AMA_M BMB_M

Output

Print MM lines.

The ii-th line (1iM)(1\leq i \leq M) should contain Yes if the name given to the ii-th baby is Taro, and No otherwise.


Sample Input 1Copy

Copy
2 4
1 M
1 M
2 F
2 M

Sample Output 1Copy

Copy
Yes
No
No
Yes

The first baby is the earliest born boy in family 11, so he is named Taro.

The second baby is not the earliest born boy in family 11, so he is not named Taro.

The third baby is a girl, so she is not named Taro.

The fourth baby is the earliest born boy in family 22, so he is named Taro. Note that the third baby is also born in family 22, but it is the earliest born boy who is named Taro.


Sample Input 2Copy

Copy
4 7
2 M
3 M
1 F
4 F
4 F
1 F
2 M

Sample Output 2Copy

Copy
Yes
Yes
No
No
No
No
No


2025-03-14 (Fri)
13:11:17 +00:00