Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
横一列に 4 つのマスが並んでいます。
各文字が 0
または 1
である長さ 4 の文字列 S が与えられます。
S の i 文字目が 1
であるとき、左から i 番目のマスには 1 人の人がおり、
S の i 文字目が 0
であるとき、左から i 番目のマスには人がいません。
全ての人が一斉に、1 つ右隣のマスへ移動します。この移動により、もともと右端のマスにいた人は消えます。
移動後の各マスに人がいるかどうかを、S と同様のルールで文字列として出力してください。
制約
- S は
0
,1
のみからなる長さ 4 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
長さ 4 の文字列であって、移動後、左から i 番目のマスに人がいるならば i 文字目が 1
、いないならば 0
であるようなものを出力せよ。
入力例 1
1011
出力例 1
0101
移動により、左から 1 番目のマスにいた人は左から 2 番目のマスに、
左から 3 番目のマスにいた人は左から 4 番目のマスに移動し、
左から 4 番目のマス(右端のマス)にいた人は消えます。
入力例 2
0000
出力例 2
0000
入力例 3
1111
出力例 3
0111
Score : 100 points
Problem Statement
There are 4 squares lined up horizontally.
You are given a string S of length 4 consisting of 0
and 1
.
If the i-th character of S is 1
, there is a person in the i-th square from the left;
if the i-th character of S is 0
, there is no person in the i-th square from the left.
Now, everyone will move to the next square to the right simultaneously. By this move, the person who was originally in the rightmost square will disappear.
Determine if there will be a person in each square after the move. Print the result as a string in the same format as S. (See also Sample Input / Output for clarity.)
Constraints
- S is a string of length 4 consisting of
0
and1
.
Input
Input is given from Standard Input in the following format:
S
Output
Print a string of length 4 such that the i-th character is 1
if there will be a person in the i-th square from the left after the move, and 0
otherwise.
Sample Input 1
1011
Sample Output 1
0101
After the move, the person who was originally in the 1-st square will move to the 2-nd square,
the person in the 3-rd square to the 4-th square,
and the person in the 4-th square will disappear.
Sample Input 2
0000
Sample Output 2
0000
Sample Input 3
1111
Sample Output 3
0111
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
N 問の問題からなるコンテストが開催され、i\ (1\leq i\leq N) 問目の配点は A_i 点でした。
すぬけくんはこのコンテストに参加し、B_1,B_2,\ldots,B_M 問目の M 問を解きました。 すぬけくんの総得点を求めてください。
ただし、総得点とは解いた問題の配点の総和を意味するものとします。
制約
- 1\leq M \leq N \leq 100
- 1\leq A_i \leq 100
- 1\leq B_1 < B_2 < \ldots < B_M \leq N
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_N B_1 B_2 \dots B_M
出力
答えを整数として出力せよ。
入力例 1
3 2 10 20 30 1 3
出力例 1
40
すぬけくんは 1 問目と 3 問目を解きました。 配点はそれぞれ 10 点と 30 点なので、総得点は 10+30=40 点です。
入力例 2
4 1 1 1 1 100 4
出力例 2
100
入力例 3
8 4 22 75 26 45 72 81 47 29 4 6 7 8
出力例 3
202
Score : 100 points
Problem Statement
There was a contest with N problems. The i-th (1\leq i\leq N) problem was worth A_i points.
Snuke took part in this contest and solved M problems: the B_1-th, B_2-th, \ldots, and B_M-th ones. Find his total score.
Here, the total score is defined as the sum of the points for the problems he solved.
Constraints
- 1\leq M \leq N \leq 100
- 1\leq A_i \leq 100
- 1\leq B_1 < B_2 < \ldots < B_M \leq N
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 A_2 \dots A_N B_1 B_2 \dots B_M
Output
Print the answer as an integer.
Sample Input 1
3 2 10 20 30 1 3
Sample Output 1
40
Snuke solved the 1-st and 3-rd problems, which are worth 10 and 30 points, respectively. Thus, the total score is 10+30=40 points.
Sample Input 2
4 1 1 1 1 100 4
Sample Output 2
100
Sample Input 3
8 4 22 75 26 45 72 81 47 29 4 6 7 8
Sample Output 3
202
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
整数 N と長さ N の数列 A=(A _ 1,A _ 2,\ldots,A _ N) が与えられます。
クエリが Q 個与えられるので、与えられた順番に処理してください。 クエリは次の 2 種類のいずれかです。
1 k x
: A _ k の値を x に変更する。2 k
: A _ k の値を出力する。
制約
- 1 \leq N \leq 10 ^ 5
- 1 \leq Q \leq 10 ^ 5
- 0 \leq A _ i \leq 10 ^ 9\ (1\leq i\leq N)
- どのクエリについても、1\leq k\leq N
- 1 番目の形式のクエリについて、0\leq x\leq 10 ^ 9
- 2 番目の形式のクエリが 1 つ以上存在する
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A _ 1 A _ 2 \ldots A _ N Q \operatorname{query} _ 1 \operatorname{query} _ 2 \vdots \operatorname{query} _ Q
ただし、\operatorname{query} _ i は i 個目のクエリを表しており、次の形式のいずれかで与えられる。
1 k x
2 k
出力
2 番目の形式のクエリの回数を q 回として q 行出力せよ。 j\ (1\leq j\leq q) 行目には、2 番目の形式のクエリのうち j 個目のものに対する答えを出力せよ。
入力例 1
3 1 3 5 7 2 2 2 3 1 3 0 2 3 1 2 8 2 2 2 1
出力例 1
3 5 0 8 1
はじめ、A=(1,3,5) です。
- 1 つめのクエリにおいて、A=(1,3,5) です。A _ 2=3 なので、3 を出力します。
- 2 つめのクエリにおいて、A=(1,3,5) です。A _ 3=5 なので、5 を出力します。
- 3 つめのクエリでは、A _ 3 の値を 0 に変更し、A=(1,3,0) となります。
- 4 つめのクエリにおいて、A=(1,3,0) です。A _ 3=0 なので、0 を出力します。
- 5 つめのクエリでは、A _ 2 の値を 8 に変更し、A=(1,8,0) となります。
- 6 つめのクエリにおいて、A=(1,8,0) です。A _ 2=8 なので、8 を出力します。
- 7 つめのクエリにおいて、A=(1,8,0) です。A _ 1=1 なので、1 を出力します。
入力例 2
5 22 2 16 7 30 10 1 4 0 1 5 0 2 2 2 3 2 4 2 5 1 4 100 1 5 100 2 3 2 4
出力例 2
2 16 0 0 16 100
入力例 3
7 478 369 466 343 541 42 165 20 2 1 1 7 729 1 6 61 1 6 838 1 3 319 1 4 317 2 4 1 1 673 1 3 176 1 5 250 1 1 468 2 6 1 7 478 1 5 595 2 6 1 6 599 1 6 505 2 3 2 5 2 1
出力例 3
478 317 838 838 176 595 468
Score : 200 points
Problem Statement
You are given an integer N and a sequence A=(A _ 1,A _ 2,\ldots,A _ N) of length N.
Given Q queries, process them in the given order. Each query is of one of the following two kinds:
1 k x
: set the value A _ k to x.2 k
: print the value A _ k.
Constraints
- 1 \leq N \leq 10 ^ 5
- 1 \leq Q \leq 10 ^ 5
- 0 \leq A _ i \leq 10 ^ 9\ (1\leq i\leq N)
- 1\leq k\leq N for all queries.
- 0\leq x\leq 10 ^ 9 for all queries of the first kind.
- There is at least one query of the second kind.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N A _ 1 A _ 2 \ldots A _ N Q \operatorname{query} _ 1 \operatorname{query} _ 2 \vdots \operatorname{query} _ Q
Here, \operatorname{query} _ i denotes the i-th query, given in one of the following formats:
1 k x
2 k
Output
Print q lines, where q is the number of queries of the second kind. The j-th (1\leq j\leq q) line should contain the response to the j-th such query.
Sample Input 1
3 1 3 5 7 2 2 2 3 1 3 0 2 3 1 2 8 2 2 2 1
Sample Output 1
3 5 0 8 1
Initially, A=(1,3,5).
- For the 1-st query, A=(1,3,5), where A _ 2=3, so 3 should be printed.
- For the 2-nd query, A=(1,3,5), where A _ 3=5, so 5 should be printed.
- The 3-rd query sets the value A _ 3 to 0, making A=(1,3,0).
- For the 4-th query, A=(1,3,0), where A _ 3=0, so 0 should be printed.
- The 5-th query sets the value A _ 2 to 8, making A=(1,8,0).
- For the 6-th query, A=(1,8,0), where A _ 2=8, so 8 should be printed.
- For the 7-th query, A=(1,8,0), where A _ 1=1, so 1 should be printed.
Sample Input 2
5 22 2 16 7 30 10 1 4 0 1 5 0 2 2 2 3 2 4 2 5 1 4 100 1 5 100 2 3 2 4
Sample Output 2
2 16 0 0 16 100
Sample Input 3
7 478 369 466 343 541 42 165 20 2 1 1 7 729 1 6 61 1 6 838 1 3 319 1 4 317 2 4 1 1 673 1 3 176 1 5 250 1 1 468 2 6 1 7 478 1 5 595 2 6 1 6 599 1 6 505 2 3 2 5 2 1
Sample Output 3
478 317 838 838 176 595 468
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君には N 人の友達がいます。N 人の友達はそれぞれ、友達 1 、友達 2 、\ldots 、友達 N というあだ名で呼ばれています。
ある日、高橋君はある恥ずかしい秘密を、友達の一人である友達 X に知られてしまいました。
i = 1, 2, \ldots, N について、友達 i が高橋君の秘密を知ったとき、友達 A_i がまだ高橋君の秘密を知らなければ、友達 i は高橋君の秘密を友達 A_i にも教えてしまいます。
高橋君の秘密は最終的に何人の友達に知られることになるでしょうか?
制約
- 2 \leq N \leq 10^5
- 1 \leq X \leq N
- 1 \leq A_i \leq N
- A_i \neq i
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N X A_1 A_2 \cdots A_N
出力
答えを出力せよ。
入力例 1
4 2 3 1 1 2
出力例 1
3
高橋君の秘密は以下の流れで友達 1 、友達 2 、友達 3 の 3 人に知れ渡ります。
- ある日、高橋君は秘密を友達 2 に知られてしまいました。
- 秘密を知った友達 2 は、その秘密を友達 1 に教えます。
- 秘密を知った友達 1 は、その秘密を友達 3 に教えます。
高橋君の秘密は最終的に 3 人の友達に知られることになるため、3 を出力します。
入力例 2
20 12 7 11 10 1 7 20 14 2 17 3 2 5 19 20 8 14 18 2 10 10
出力例 2
7
Score : 200 points
Problem Statement
Takahashi has N friends. They have nicknames: Friend 1, Friend 2, \ldots, Friend N.
One day, Takahashi accidentally let one of his friends, Friend X, learn his shameful secret.
For each i = 1, 2, \ldots, N, when Friend i learns the secret, he/she will share it with Friend A_i, if Friend A_i has not already learned it.
How many of Takahashi's friends will learn the secret in the end?
Constraints
- 2 \leq N \leq 10^5
- 1 \leq X \leq N
- 1 \leq A_i \leq N
- A_i \neq i
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X A_1 A_2 \cdots A_N
Output
Print the answer.
Sample Input 1
4 2 3 1 1 2
Sample Output 1
3
Takahashi's secret will be learned by Friend 1, Friend 2, and Friend 3, as follows.
- One day, Takahashi let Friend 2 learn the secret.
- Friend 2 shares it with Friend 1.
- Friend 1 shares it with Friend 3.
In the end, three of his friends learn the secret, so we print 3.
Sample Input 2
20 12 7 11 10 1 7 20 14 2 17 3 2 5 19 20 8 14 18 2 10 10
Sample Output 2
7
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
AtCoder 鉄道のとある路線には N 個の駅が存在し、始点から終点に向かって i \, (1 \leq i \leq N) 番目の駅の名前は S_i です。
普通列車は全ての駅に止まりますが、急行列車は全ての駅に止まるとは限りません。具体的には、急行列車は M \, (M \leq N) 個の駅にのみ止まり、j \, (1 \leq j \leq M) 番目に止まる駅の名前は T_j です。
ただし、T_1 = S_1 かつ T_M = S_N、すなわち急行列車は始点と終点の両方に止まることが保証されます。
N 個の駅それぞれについて、その駅に急行列車が止まるかどうか判定してください。
制約
- 2 \leq M \leq N \leq 10^5
- N, M は整数
- S_i \, (1 \leq i \leq N) は英小文字のみからなる 1 文字以上 10 文字以下の文字列
- S_i \neq S_j \, (i \neq j)
- T_1 = S_1 かつ T_M = S_N
- (T_1, \dots, T_M) は (S_1, \dots, S_N) から 0 個以上の文字列を選んで取り除き、残った文字列を元の順序で並べることで得られる
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 \ldots S_N T_1 \ldots T_M
出力
N 行出力せよ。i \, (1 \leq i \leq N) 行目には、始点から終点に向かって i 番目の駅に急行列車が止まるなら Yes
、そうでないなら No
と出力せよ。
入力例 1
5 3 tokyo kanda akiba okachi ueno tokyo akiba ueno
出力例 1
Yes No Yes No Yes
入力例 2
7 7 a t c o d e r a t c o d e r
出力例 2
Yes Yes Yes Yes Yes Yes Yes
急行列車が全ての駅に止まることもあります。
Score : 300 points
Problem Statement
There are N stations on a certain line operated by AtCoder Railway. The i-th station (1 \leq i \leq N) from the starting station is named S_i.
Local trains stop at all stations, while express trains may not. Specifically, express trains stop at only M \, (M \leq N) stations, and the j-th stop (1 \leq j \leq M) is the station named T_j.
Here, it is guaranteed that T_1 = S_1 and T_M = S_N, that is, express trains stop at both starting and terminal stations.
For each of the N stations, determine whether express trains stop at that station.
Constrains
- 2 \leq M \leq N \leq 10^5
- N and M are integers.
- S_i (1 \leq i \leq N) is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
- S_i \neq S_j \, (i \neq j)
- T_1 = S_1 and T_M = S_N.
- (T_1, \dots, T_M) is obtained by removing zero or more strings from (S_1, \dots, S_N) and lining up the remaining strings without changing the order.
Input
Input is given from Standard Input in the following format:
N M S_1 \ldots S_N T_1 \ldots T_M
Output
Print N lines. The i-th line (1 \leq i \leq N) should contain Yes
if express trains stop at the i-th station from the starting station, and No
otherwise.
Sample Input 1
5 3 tokyo kanda akiba okachi ueno tokyo akiba ueno
Sample Output 1
Yes No Yes No Yes
Sample Input 2
7 7 a t c o d e r a t c o d e r
Sample Output 2
Yes Yes Yes Yes Yes Yes Yes
Express trains may stop at all stations.