Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋君はある会社の採用面接を受けました。
面接官の人数 N と、各面接官の高橋君への評価を表す長さ N の文字列 S が与えられます。
i=1,2,\ldots,N に対し S の i 文字目が i 番目の面接官の評価に対応し、o
は「良」、-
は「可」、x
は 「不可」を表します。
高橋君は以下の 2 つの条件を両方満たすならば合格、そうでなければ不合格です。
- 「良」と評価した面接官が少なくとも 1 人いる
- 「不可」と評価した面接官がいない
高橋君が合格かどうかを判定してください。
制約
- 1 \leq N \leq 100
- S は
o
,-
,x
のみからなる長さが N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
高橋君が合格ならば Yes
と、そうでなければ No
と出力せよ。
入力例 1
4 oo--
出力例 1
Yes
1, 2 番目の面接官が「良」と評価していて、さらに「不可」と評価した面接官がいないため合格です。
入力例 2
3 ---
出力例 2
No
「良」と評価した面接官が 1 人もいないため不合格です。
入力例 3
1 o
出力例 3
Yes
入力例 4
100 ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooox
出力例 4
No
100 番目の面接官が「不可」と評価しているため不合格です。
Score : 100 points
Problem Statement
Takahashi had a job interview.
You are given the number of interviewers, N, and a string S of length N representing the interviewers' evaluations of him.
For each i=1,2,\ldots,N, the i-th character of S corresponds to the i-th interviewer's evaluation; o
means Good, -
means Fair, and x
means Poor.
Takahashi will pass if both of the following conditions are satisfied, and fail otherwise.
- At least one interviewer's evaluation is Good.
- No interviewer's evaluation is Poor.
Determine whether Takahashi passes.
Constraints
- 1 \leq N \leq 100
- S is a string of length N consisting of
o
,-
, andx
.
Input
The input is given from Standard Input in the following format:
N S
Output
If Takahashi passes, print Yes
; otherwise, print No
.
Sample Input 1
4 oo--
Sample Output 1
Yes
The first and second interviewers' evaluations are Good, and no interviewer's evaluation is Poor, so he passes.
Sample Input 2
3 ---
Sample Output 2
No
No interviewer's evaluation is Good, so he fails.
Sample Input 3
1 o
Sample Output 3
Yes
Sample Input 4
100 ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooox
Sample Output 4
No
The 100-th interviewer's evaluation is Poor, so he fails.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英小文字からなる N 個の文字列 W_1,W_2,\dots,W_N が与えられます。
これらのうち一つ以上が and
, not
, that
, the
, you
のいずれかと一致するなら Yes
、そうでないなら No
と出力してください。
制約
- N は 1 以上 100 以下の整数
- 1 \le |W_i| \le 50 ( |W_i| は文字列 W_i の長さ )
- W_i は英小文字からなる
入力
入力は以下の形式で標準入力から与えられる。
N W_1 W_2 \dots W_N
出力
答えを出力せよ。
入力例 1
10 in that case you should print yes and not no
出力例 1
Yes
例えば W_4= you
なので、 Yes
と出力します。
入力例 2
10 in diesem fall sollten sie no und nicht yes ausgeben
出力例 2
No
文字列 W_i はいずれも、 and
, not
, that
, the
, you
のいずれとも一致しません。
Score : 100 points
Problem Statement
You are given N strings W_1,W_2,\dots,W_N consisting of lowercase English letters.
If one or more of these strings equal and
, not
, that
, the
, or you
, then print Yes
; otherwise, print No
.
Constraints
- N is an integer between 1 and 100, inclusive.
- 1 \le |W_i| \le 50 (|W_i| is the length of W_i.)
- W_i consists of lowercase English letters.
Input
The input is given from Standard Input in the following format:
N W_1 W_2 \dots W_N
Output
Print the answer.
Sample Input 1
10 in that case you should print yes and not no
Sample Output 1
Yes
We have, for instance, W_4= you
, so you should print Yes
.
Sample Input 2
10 in diesem fall sollten sie no und nicht yes ausgeben
Sample Output 2
No
None of the strings W_i equals any of and
, not
, that
, the
, and you
.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
数字のみからなる長さ 6 の文字列が N 個与えられます。i \, (i = 1, 2, \dots, N) 番目のものを S_i と表します。
さらに、数字のみからなる長さ 3 の文字列が M 個与えられます。j \, (j = 1, 2, \dots, M) 番目のものを T_j と表します。
S_1, S_2, \dots, S_N のうち、末尾 3 文字が T_1, T_2, \dots, T_M のいずれかに一致するものの個数を求めてください。
制約
- 1 \leq N, M \leq 1000
- N, M は整数
- 全ての i = 1, 2, \dots, N に対し、S_i は数字のみからなる長さ 6 の文字列
- 全ての j = 1, 2, \dots, M に対し、T_j は数字のみからなる長さ 3 の文字列
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 S_2 \vdots S_N T_1 T_2 \vdots T_M
出力
答えを出力せよ。
入力例 1
3 3 142857 004159 071028 159 287 857
出力例 1
2
S_1 の末尾 3 文字は 857
であり、これは T_3 に一致します。
S_2 の末尾 3 文字は 159
であり、これは T_1 に一致します。
S_3 の末尾 3 文字は 028
であり、これは T_1, T_2, T_3 のいずれにも一致しません。
以上から、答えは 2 です。
入力例 2
5 4 235983 109467 823476 592801 000333 333 108 467 983
出力例 2
3
入力例 3
4 4 000000 123456 987111 000000 000 111 999 111
出力例 3
3
Score : 200 points
Problem Statement
You are given N strings of length six each, consisting of digits. Let S_i be the i-th (i = 1, 2, \dots, N) of them.
You are also given M strings of length three each, consisting of digits. Let T_j be the j-th (j = 1, 2, \dots, M) of them.
Find the number of strings among S_1, S_2, \dots, S_N whose last three characters coincide with one or more of T_1, T_2, \dots, T_M.
Constraints
- 1 \leq N, M \leq 1000
- N and M are integers.
- S_i is a string of length 6 consisting of digits, for all i = 1, 2, \dots, N.
- T_j is a string of length 3 consisting of digits, for all j = 1, 2, \dots, M.
Input
The input is given from Standard Input in the following format:
N M S_1 S_2 \vdots S_N T_1 T_2 \vdots T_M
Output
Print the answer.
Sample Input 1
3 3 142857 004159 071028 159 287 857
Sample Output 1
2
The last three characters of S_1 are 857
, which coincide with T_3.
The last three characters of S_2 are 159
, which coincide with T_1.
The last three characters of S_3 are 028
, which do not coincide with T_1, T_2, or T_3.
Thus, the answer is 2.
Sample Input 2
5 4 235983 109467 823476 592801 000333 333 108 467 983
Sample Output 2
3
Sample Input 3
4 4 000000 123456 987111 000000 000 111 999 111
Sample Output 3
3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
英小文字からなる 3 つの文字列 S_1, S_2, S_3 と、1
、2
、3
のみからなる文字列 T が与えられます。
T の各文字に対応する文字列を連結してできる文字列を出力してください。より厳密には、以下の指示にしたがって文字列を出力してください。
- 1 \leq i \leq |T| を満たす整数 i に対し、文字列 s_i を次のように定める。
- T の i 文字目が
1
のとき、S_1 - T の i 文字目が
2
のとき、S_2 - T の i 文字目が
3
のとき、S_3
- T の i 文字目が
- s_1, s_2, \dots, s_{|T|} をこの順に連結してできる文字列を出力する。
制約
- 1 \leq |S_1|, |S_2|, |S_3| \leq 10
- 1 \leq |T| \leq 1000
- S_1, S_2, S_3 は英小文字からなる。
- T は
1
、2
、3
のみからなる。
入力
入力は以下の形式で標準入力から与えられる。
S_1 S_2 S_3 T
出力
答えを出力せよ。
入力例 1
mari to zzo 1321
出力例 1
marizzotomari
s_1 = mari
, s_2 = zzo
, s_3 = to
, s_4 = mari
であるので、これらを連結してできる文字列である marizzotomari
を出力します。
入力例 2
abra cad abra 123
出力例 2
abracadabra
入力例 3
a b c 1
出力例 3
a
Score : 200 points
Problem Statement
You are given three strings S_1, S_2, S_3 consisting of lowercase English letters, and a string T consisting of 1
, 2
, 3
.
Concatenate the three strings according to the characters in T and print the resulting string. Formally, conform to the following instructions.
- For each integer i such that 1 \leq i \leq |T|, let the string s_i be defined as follows:
- S_1, if the i-th character of T is
1
; - S_2, if the i-th character of T is
2
; - S_3, if the i-th character of T is
3
.
- S_1, if the i-th character of T is
- Concatenate the strings s_1, s_2, \dots, s_{|T|} in this order and print the resulting string.
Constraints
- 1 \leq |S_1|, |S_2|, |S_3| \leq 10
- 1 \leq |T| \leq 1000
- S_1, S_2, and S_3 consist of lowercase English letters.
- T consists of
1
,2
, and3
.
Input
Input is given from Standard Input in the following format:
S_1 S_2 S_3 T
Output
Print the answer.
Sample Input 1
mari to zzo 1321
Sample Output 1
marizzotomari
We have s_1 = mari
, s_2 = zzo
, s_3 = to
, s_4 = mari
. Concatenate these and print the resulting string: marizzotomari
.
Sample Input 2
abra cad abra 123
Sample Output 2
abracadabra
Sample Input 3
a b c 1
Sample Output 3
a
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 個のボールが左右一列に並んでいます。初め、左から i \, (1 \leq i \leq N) 番目のボールには整数 i が書かれています。
高橋君は Q 回の操作を行いました。 i \, (1 \leq i \leq Q) 回目に行われた操作は次のようなものです。
- 整数 x_i が書かれているボールをその右隣のボールと入れ替える。ただし、整数 x_i が書かれているボールが元々右端にあった場合、代わりに左隣のボールと入れ替える。
操作後において左から i \, (1 \leq i \leq N) 番目のボールに書かれている整数を a_i とします。 a_1,\ldots,a_N を求めてください。
制約
- 2 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq x_i \leq N
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N Q x_1 \vdots x_Q
出力
a_1,\ldots,a_N を空白区切りで出力せよ。
入力例 1
5 5 1 2 3 4 5
出力例 1
1 2 3 5 4
操作は以下のように行われます。
- 1 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 2,1,3,4,5 となる。
- 2 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,3,4,5 となる。
- 3 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,4,3,5 となる。
- 4 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,3,4,5 となる。
- 5 と書かれたボールは右端にあるので左隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,3,5,4 となる。
入力例 2
7 7 7 7 7 7 7 7 7
出力例 2
1 2 3 4 5 7 6
入力例 3
10 6 1 5 2 9 6 6
出力例 3
1 2 3 4 5 7 6 8 10 9
Score : 300 points
Problem Statement
N balls are lined up in a row from left to right. Initially, the i-th (1 \leq i \leq N) ball from the left has an integer i written on it.
Takahashi has performed Q operations. The i-th (1 \leq i \leq Q) operation was as follows.
- Swap the ball with the integer x_i written on it with the next ball to the right. If the ball with the integer x_i written on it was originally the rightmost ball, swap it with the next ball to the left instead.
Let a_i be the integer written on the i-th (1 \leq i \leq N) ball after the operations. Find a_1,\ldots,a_N.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq x_i \leq N
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N Q x_1 \vdots x_Q
Output
Print a_1,\ldots,a_N, with spaces in between.
Sample Input 1
5 5 1 2 3 4 5
Sample Output 1
1 2 3 5 4
The operations are performed as follows.
- Swap the ball with 1 written on it with the next ball to the right. Now, the balls have integers 2,1,3,4,5 written on them, from left to right.
- Swap the ball with 2 written on it with the next ball to the right. Now, the balls have integers 1,2,3,4,5 written on them, from left to right.
- Swap the ball with 3 written on it with the next ball to the right. Now, the balls have integers 1,2,4,3,5 written on them, from left to right.
- Swap the ball with 4 written on it with the next ball to the right. Now, the balls have integers 1,2,3,4,5 written on them, from left to right.
- Swap the ball with 5 written on it with the next ball to the left, since it is the rightmost ball. Now, the balls have integers 1,2,3,5,4 written on them, from left to right.
Sample Input 2
7 7 7 7 7 7 7 7 7
Sample Output 2
1 2 3 4 5 7 6
Sample Input 3
10 6 1 5 2 9 6 6
Sample Output 3
1 2 3 4 5 7 6 8 10 9
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
9\times 9 のマス目 A があり、各マスには 1 以上 9 以下の整数が書き込まれています。
具体的には、 A の上から i 行目、左から j 列目のマスには A_{i,j} が書き込まれています。
A が次の条件をすべてみたしているならば Yes
を、そうでないならば No
を出力してください。
- A の各行について、その行に含まれる 9 マスには 1 以上 9 以下の整数がちょうど 1 個ずつ書き込まれている。
- A の各列について、その列に含まれる 9 マスには 1 以上 9 以下の整数がちょうど 1 個ずつ書き込まれている。
- A の行を上から 3 行ずつ 3 つに分け、同様に列も左から 3 列ずつ 3 つに分ける。 これによって A を 9 つの 3\times 3 のマス目に分けたとき、それぞれの 3\times 3 のマス目には 1 以上 9 以下の整数がちょうど 1 個ずつ書き込まれている。
制約
- 1\leq A_{i,j}\leq 9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A_{1,1} A_{1,2} \ldots A_{1,9} A_{2,1} A_{2,2} \ldots A_{2,9} \vdots A_{9,1} A_{9,2} \ldots A_{9,9}
出力
マス目 A が問題文の条件をすべてみたすならば Yes
を、
そうでないならば No
を出力せよ。
入力例 1
1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 2 3 4 5 6 7 8 9 1 5 6 7 8 9 1 2 3 4 8 9 1 2 3 4 5 6 7 3 4 5 6 7 8 9 1 2 6 7 8 9 1 2 3 4 5 9 1 2 3 4 5 6 7 8
出力例 1
Yes
マス目 A は次のようになっています。
マス目 A は 3 つの条件をすべてみたしているため、Yes
を出力します。
入力例 2
1 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9 1 3 4 5 6 7 8 9 1 2 4 5 6 7 8 9 1 2 3 5 6 7 8 9 1 2 3 4 6 7 8 9 1 2 3 4 5 7 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 7 9 1 2 3 4 5 6 7 8
出力例 2
No
マス目 A は次のようになっています。
例えば左上の 3\times 3 のマス目に注目すると 3 つめの条件をみたしていないことが分かるため、No
を出力します。
入力例 3
1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6
出力例 3
No
マス目 A は次のようになっています。
例えば一番左の列に注目すると 2 つめの条件をみたしていないことが分かるため、No
を出力します。
Score : 250 points
Problem Statement
There is a 9\times 9 grid A, where each cell contains an integer between 1 and 9, inclusive.
Specifically, the cell at the i-th row from the top and j-th column from the left contains A_{i,j}.
If A satisfies all of the following conditions, print Yes
. Otherwise, print No
.
- For each row of A, the nine cells in that row contain each integer from 1 to 9 exactly once.
- For each column of A, the nine cells in that column contain each integer from 1 to 9 exactly once.
- Divide the rows of A into three groups, each of three rows, from top to bottom, and similarly divide the columns into three groups, each of three columns, from left to right. Each 3\times 3 grid obtained from A in this way contains each integer from 1 to 9 exactly once.
Constraints
- 1\leq A_{i,j}\leq 9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A_{1,1} A_{1,2} \ldots A_{1,9} A_{2,1} A_{2,2} \ldots A_{2,9} \vdots A_{9,1} A_{9,2} \ldots A_{9,9}
Output
If the grid A satisfies all the conditions in the problem statement, print Yes
; otherwise, print No
.
Sample Input 1
1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 2 3 4 5 6 7 8 9 1 5 6 7 8 9 1 2 3 4 8 9 1 2 3 4 5 6 7 3 4 5 6 7 8 9 1 2 6 7 8 9 1 2 3 4 5 9 1 2 3 4 5 6 7 8
Sample Output 1
Yes
The grid A is shown below.
The grid A satisfies all three conditions, so print Yes
.
Sample Input 2
1 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9 1 3 4 5 6 7 8 9 1 2 4 5 6 7 8 9 1 2 3 5 6 7 8 9 1 2 3 4 6 7 8 9 1 2 3 4 5 7 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 7 9 1 2 3 4 5 6 7 8
Sample Output 2
No
The grid A is shown below.
For example, if you look at the top left 3\times 3 grid, you can see that the third condition is unsatisfied, so print No
.
Sample Input 3
1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6
Sample Output 3
No
The grid A is shown below.
For example, if you look at the leftmost column, you can see that the second condition is unsatisfied, so print No
.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 350 点
問題文
1, 2, \ldots, N の番号のついた N 人の候補者から当選者を 1 人選ぶ選挙において、M 票の投票がありました。
各票ではそれぞれちょうど 1 人が投票先として選ばれており、i 票目の投票先は候補者 A_i です。
これから 1 票目から順に開票を行い、 1 票ごとにその時点で開票が終了した場合の当選者を更新して表示します。
開票された票において最も得票数が多かった候補者が当選となります。ただし、最も得票数が多かった候補者が複数いる場合は、その中で最も番号の小さい候補者が当選となります。
各 i = 1, 2, \ldots, M について、1, 2, \ldots, i 票目のみを開票した場合の当選者を求めてください。
制約
- 1 \leq N,M \leq 200000
- 1 \leq A_i \leq N
- 入力される数値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \ldots A_M
出力
M 行出力せよ。
i 行目には 1, 2, \ldots, i 票目のみを開票した場合の当選者の番号を出力せよ。
入力例 1
3 7 1 2 2 3 1 3 3
出力例 1
1 1 2 2 1 1 3
候補者 i の得票数を C_i で表すこととします。
- 1 票目までが開票された時点では、(C_1, C_2, C_3) = (1, 0, 0) なので当選者は 1 です。
- 2 票目までが開票された時点では、(C_1, C_2, C_3) = (1, 1, 0) なので当選者は 1 です。
- 3 票目までが開票された時点では、(C_1, C_2, C_3) = (1, 2, 0) なので当選者は 2 です。
- 4 票目までが開票された時点では、(C_1, C_2, C_3) = (1, 2, 1) なので当選者は 2 です。
- 5 票目までが開票された時点では、(C_1, C_2, C_3) = (2, 2, 1) なので当選者は 1 です。
- 6 票目までが開票された時点では、(C_1, C_2, C_3) = (2, 2, 2) なので当選者は 1 です。
- 7 票目までが開票された時点では、(C_1, C_2, C_3) = (2, 2, 3) なので当選者は 3 です。
入力例 2
100 5 100 90 80 70 60
出力例 2
100 90 80 70 60
入力例 3
9 8 8 8 2 2 8 8 2 2
出力例 3
8 8 8 2 8 8 8 2
Score : 350 points
Problem Statement
There is an election to choose one winner from N candidates with candidate numbers 1, 2, \ldots, N, and there have been M votes cast.
Each vote is for exactly one candidate, with the i-th vote being for candidate A_i.
The votes will be counted in order from first to last, and after each vote is counted, the current winner will be updated and displayed.
The candidate with the most votes among those counted is the winner. If there are multiple candidates with the most votes, the one with the smallest candidate number is the winner.
For each i = 1, 2, \ldots, M, determine the winner when counting only the first i votes.
Constraints
- 1 \leq N, M \leq 200000
- 1 \leq A_i \leq N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 A_2 \ldots A_M
Output
Print M lines.
The i-th line should contain the winner's candidate number when counting only the first i votes.
Sample Input 1
3 7 1 2 2 3 1 3 3
Sample Output 1
1 1 2 2 1 1 3
Let C_i denote the number of votes for candidate i.
- After the first vote is counted, (C_1, C_2, C_3) = (1, 0, 0), so the winner is 1.
- After the second vote is counted, (C_1, C_2, C_3) = (1, 1, 0), so the winner is 1.
- After the third vote is counted, (C_1, C_2, C_3) = (1, 2, 0), so the winner is 2.
- After the fourth vote is counted, (C_1, C_2, C_3) = (1, 2, 1), so the winner is 2.
- After the fifth vote is counted, (C_1, C_2, C_3) = (2, 2, 1), so the winner is 1.
- After the sixth vote is counted, (C_1, C_2, C_3) = (2, 2, 2), so the winner is 1.
- After the seventh vote is counted, (C_1, C_2, C_3) = (2, 2, 3), so the winner is 3.
Sample Input 2
100 5 100 90 80 70 60
Sample Output 2
100 90 80 70 60
Sample Input 3
9 8 8 8 2 2 8 8 2 2
Sample Output 3
8 8 8 2 8 8 8 2
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 475 点
問題文
長さ N の数列 A=(A_1,A_2,\dots,A_N) が与えられます。
以下の Q 個のクエリに、与えられる順番で対応してください。
k 番目のクエリは以下の形式で与えられます。
i_k x_k
- まず、 A_{i_k} = x_k と変更する。この変更は以降のクエリにも引き継がれる。
- その後、 A の \rm{mex} を出力する。
- A の \rm{mex} とは、 A に含まれない最小の非負整数を指す。
制約
- 入力は全て整数
- 1 \le N,Q \le 2 \times 10^5
- 0 \le A_i \le 10^9
- 1 \le i_k \le N
- 0 \le x_k \le 10^9
入力
入力は以下の形式で標準入力から与えられる。
N Q A_1 A_2 \dots A_N i_1 x_1 i_2 x_2 \vdots i_Q x_Q
出力
全体で Q 行出力せよ。
そのうち k 行目には k 番目のクエリに対する答えを整数として出力せよ。
入力例 1
8 5 2 0 2 2 1 1 2 5 4 3 4 4 6 3 8 1000000000 2 1
出力例 1
4 3 6 5 0
最初、数列 A は (2,0,2,2,1,1,2,5) です。
この入力では、 5 つのクエリを処理します。
- 1 番目のクエリで A_4 = 3 と変更し、 A=(2,0,2,3,1,1,2,5) となりました。
- この時点で、 A の \rm{mex} は 4 です。
- 2 番目のクエリで A_4 = 4 と変更し、 A=(2,0,2,4,1,1,2,5) となりました。
- この時点で、 A の \rm{mex} は 3 です。
- 3 番目のクエリで A_6 = 3 と変更し、 A=(2,0,2,4,1,3,2,5) となりました。
- この時点で、 A の \rm{mex} は 6 です。
- 4 番目のクエリで A_8 = 1000000000 と変更し、 A=(2,0,2,4,1,3,2,1000000000) となりました。
- この時点で、 A の \rm{mex} は 5 です。
- 5 番目のクエリで A_2 = 1 と変更し、 A=(2,1,2,4,1,3,2,1000000000) となりました。
- この時点で、 A の \rm{mex} は 0 です。
Score : 475 points
Problem Statement
You are given a sequence A=(A_1,A_2,\dots,A_N) of length N.
Respond to the following Q queries in the order they are given.
The k-th query is given in the following format:
i_k x_k
- First, change A_{i_k} to x_k. This change will carry over to subsequent queries.
- Then, print the \rm{mex} of A.
- The \rm{mex} of A is the smallest non-negative integer not contained in A.
Constraints
- All input values are integers.
- 1 \le N,Q \le 2 \times 10^5
- 0 \le A_i \le 10^9
- 1 \le i_k \le N
- 0 \le x_k \le 10^9
Input
Input is given from Standard Input in the following format:
N Q A_1 A_2 \dots A_N i_1 x_1 i_2 x_2 \vdots i_Q x_Q
Output
Print Q lines in total.
The k-th line should contain the answer to the k-th query as an integer.
Sample Input 1
8 5 2 0 2 2 1 1 2 5 4 3 4 4 6 3 8 1000000000 2 1
Sample Output 1
4 3 6 5 0
Initially, the sequence A is (2,0,2,2,1,1,2,5).
This input gives you five queries.
- The first query changes A_4 to 3, making A=(2,0,2,3,1,1,2,5).
- At this point, the \rm{mex} of A is 4.
- The second query changes A_4 to 4, making A=(2,0,2,4,1,1,2,5).
- At this point, the \rm{mex} of A is 3.
- The third query changes A_6 to 3, making A=(2,0,2,4,1,3,2,5).
- At this point, the \rm{mex} of A is 6.
- The fourth query changes A_8 to 1000000000, making A=(2,0,2,4,1,3,2,1000000000).
- At this point, the \rm{mex} of A is 5.
- The fifth query changes A_2 to 1, making A=(2,1,2,4,1,3,2,1000000000).
- At this point, the \rm{mex} of A is 0.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
長さ N の数列 A = (A_1, \dots, A_N), B = (B_1, \dots, B_N) が与えられます。\{1,2,\ldots,N\} の空でない部分集合 S であって、以下の条件を満たすものの個数を数えてください。
- \max_{i \in S} A_i \geq \sum_{i \in S} B_i
なお、答えは非常に大きくなることがあるため、998244353 で割ったあまりを出力してください。
制約
- 1 \leq N \leq 5000
- 1 \leq A_i,B_i \leq 5000
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N B_1 B_2 \ldots B_N
出力
問題文中の条件を満たす S の個数を 998244353 で割ったあまりを出力せよ。
入力例 1
2 3 1 1 2
出力例 1
2
\{1,2,\ldots,N\} の空でない部分集合としてあり得るものは、\{1\}, \{2\}, \{1,2\} の 3 通りです。
- S=\{1\} のとき \max_{i \in S} A_i=3, \sum_{i \in S} B_i=1
- S=\{2\} のとき \max_{i \in S} A_i=1, \sum_{i \in S} B_i=2
- S=\{1,2\} のとき \max_{i \in S} A_i=3, \sum_{i \in S} B_i=3
であるため、問題文中の条件、即ち \max_{i \in S} A_i \geq \sum_{i \in S} B_i を満たす S は \{1\} と \{1,2\} の 2 通りです。
入力例 2
2 1 1 2 2
出力例 2
0
条件を満たす S が存在しない場合もあります。
入力例 3
20 1937 3980 2689 1208 3640 1979 581 2271 4229 3948 3708 1522 4161 4661 3797 96 3388 3395 2920 2247 4485 2580 174 1156 3770 3396 3558 3500 3494 479 269 3383 1230 1711 3545 3919 134 475 3796 1017
出力例 3
476
Score : 500 points
Problem Statement
Given are sequences of N integers each: A = (A_1, \dots, A_N) and B = (B_1, \dots, B_N). Find the number of non-empty subsets S of \{1,2,\ldots,N\} that satisfy the following condition:
- \max_{i \in S} A_i \geq \sum_{i \in S} B_i.
Since the count can be enormous, print it modulo 998244353.
Constraints
- 1 \leq N \leq 5000
- 1 \leq A_i,B_i \leq 5000
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N B_1 B_2 \ldots B_N
Output
Print the number of subsets S that satisfy the condition in the Problem Statement, modulo 998244353.
Sample Input 1
2 3 1 1 2
Sample Output 1
2
\{1,2,\ldots,N\} has three subsets: \{1\}, \{2\}, and \{1,2\}.
- For S=\{1\}, we have \max_{i \in S} A_i=3 and \sum_{i \in S} B_i=1.
- For S=\{2\}, we have \max_{i \in S} A_i=1 and \sum_{i \in S} B_i=2.
- For S=\{1,2\}, we have \max_{i \in S} A_i=3 and \sum_{i \in S} B_i=3.
Thus, the condition \max_{i \in S} A_i \geq \sum_{i \in S} B_i is satisfied by two subsets: \{1\} and \{1,2\}.
Sample Input 2
2 1 1 2 2
Sample Output 2
0
There may be no subsets that satisfy the condition.
Sample Input 3
20 1937 3980 2689 1208 3640 1979 581 2271 4229 3948 3708 1522 4161 4661 3797 96 3388 3395 2920 2247 4485 2580 174 1156 3770 3396 3558 3500 3494 479 269 3383 1230 1711 3545 3919 134 475 3796 1017
Sample Output 3
476