実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
長さ N の整数列 A=(A_1,A_2,\dots,A_N) と整数 X が与えられます。
i=1,2,\dots,N の順に以下を行ってください。
- もし A_i<X なら、 X=A_i に更新した上で
1を出力する。 - そうでないなら
0を出力する。
制約
- 入力は全て整数
- 1 \le N,X,A_i \le 100
入力
入力は以下の形式で標準入力から与えられる。
N X A_1 A_2 \dots A_N
出力
N 行出力せよ。
そのうち k 行目には、 i=k についての出力をせよ。
入力例 1
5 10 6 4 7 1 3
出力例 1
1 1 0 1 0
- 最初、 X=10 です。
- i=1 について、 A_1=6<X=10 なので、 X=6 に更新した上で
1を出力します。 - i=2 について、 A_2=4<X=6 なので、 X=4 に更新した上で
1を出力します。 - i=3 について、 A_3=7 \ge X=4 なので、
0を出力します。 - i=4 について、 A_4=1<X=4 なので、 X=1 に更新した上で
1を出力します。 - i=5 について、 A_5=3 \ge X=1 なので、
0を出力します。
入力例 2
1 1 1
出力例 2
0
入力例 3
8 20 9 19 14 17 17 4 18 4
出力例 3
1 0 0 0 0 1 0 0
Score : 100 points
Problem Statement
You are given a length-N integer sequence A=(A_1,A_2,\dots,A_N) and an integer X.
For i=1,2,\dots,N in this order, do the following.
- If A_i<X, update X=A_i and output
1. - Otherwise, output
0.
Constraints
- All input values are integers.
- 1 \le N,X,A_i \le 100
Input
The input is given from Standard Input in the following format:
N X A_1 A_2 \dots A_N
Output
Output N lines.
The k-th line should contain the output for i=k.
Sample Input 1
5 10 6 4 7 1 3
Sample Output 1
1 1 0 1 0
- Initially, X=10.
- For i=1: since A_1=6<X=10, update X=6 and output
1. - For i=2: since A_2=4<X=6, update X=4 and output
1. - For i=3: since A_3=7 \ge X=4, output
0. - For i=4: since A_4=1<X=4, update X=1 and output
1. - For i=5: since A_5=3 \ge X=1, output
0.
Sample Input 2
1 1 1
Sample Output 2
0
Sample Input 3
8 20 9 19 14 17 17 4 18 4
Sample Output 3
1 0 0 0 0 1 0 0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
末尾が er または ist であるような文字列 S が与えられます。
S の末尾が er である場合は er を、 ist である場合は ist を出力してください。
制約
- 2 \le |S| \le 20
- S は英小文字のみからなる。
- S の末尾は
erまたはistである。
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
atcoder
出力例 1
er
S="atcoder" の末尾は er です。
入力例 2
tourist
出力例 2
ist
入力例 3
er
出力例 3
er
Score : 100 points
Problem Statement
You are given a string S ending with er or ist.
If S ends with er, print er; if it ends with ist, print ist.
Constraints
- 2 \le |S| \le 20
- S consists of lowercase English letters.
- S ends with
erorist.
Input
Input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
atcoder
Sample Output 1
er
S="atcoder" ends with er.
Sample Input 2
tourist
Sample Output 2
ist
Sample Input 3
er
Sample Output 3
er
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
英小文字からなる文字列 S,T が与えられるので、 T が S の(連続する)部分文字列かどうか判定してください。
なお、文字列 X に以下の操作を 0 回以上施して文字列 Y が得られる時、またその時に限り Y は X の(連続する)部分文字列であると言います。
- 以下の 2 つの操作から 1 つを選択して、その操作を行う。
- X の先頭の 1 文字を削除する。
- X の末尾の 1 文字を削除する。
例えば tag は voltage の(連続する)部分文字列ですが、 ace は atcoder の(連続する)部分文字列ではありません。
制約
- S,T は英小文字からなる
- 1 \le |S|,|T| \le 100 ( |X| は文字列 X の長さ )
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
T が S の(連続する)部分文字列なら Yes 、そうでないなら No と出力せよ。
入力例 1
voltage tag
出力例 1
Yes
tag は voltage の(連続する)部分文字列です。
入力例 2
atcoder ace
出力例 2
No
ace は atcoder の(連続する)部分文字列ではありません。
入力例 3
gorilla gorillagorillagorilla
出力例 3
No
入力例 4
toyotasystems toyotasystems
出力例 4
Yes
S=T である場合もあります。
Score : 200 points
Problem Statement
You are given strings S and T consisting of lowercase English letters. Determine whether T is a (contiguous) substring of S.
A string Y is said to be a (contiguous) substring of X if and only if Y can be obtained by performing the operation below on X zero or more times.
- Do one of the following.
- Delete the first character in X.
- Delete the last character in X.
For instance, tag is a (contiguous) substring of voltage, while ace is not a (contiguous) substring of atcoder.
Constraints
- S and T consist of lowercase English letters.
- 1 \le |S|,|T| \le 100 (|X| denotes the length of a string X.)
Input
The input is given from Standard Input in the following format:
S T
Output
If T is a (contiguous) substring of S, print Yes; otherwise, print No.
Sample Input 1
voltage tag
Sample Output 1
Yes
tag is a (contiguous) substring of voltage.
Sample Input 2
atcoder ace
Sample Output 2
No
ace is not a (contiguous) substring of atcoder.
Sample Input 3
gorilla gorillagorillagorilla
Sample Output 3
No
Sample Input 4
toyotasystems toyotasystems
Sample Output 4
Yes
It is possible that S=T.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
ナオヒロ君は N+1 個の連続する整数を 1 個ずつ持っていましたが、そのうち 1 個をなくしてしまいました。
残っている N 個の整数が順不同で A_1,\ldots,A_N として与えられるので、なくした整数を求めてください。
なお、なくした整数が一意に定まるような入力のみが与えられます。
制約
- 2 \leq N \leq 100
- 1 \leq A_i \leq 1000
- 入力は全て整数である
- なくした整数は一意に定まる
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
3 2 3 5
出力例 1
4
ナオヒロ君は初め 2,3,4,5 の 4 個の整数を持っており、4 をなくし、2,3,5 が残っていました。
なくした整数である 4 を出力します。
入力例 2
8 3 1 4 5 9 2 6 8
出力例 2
7
入力例 3
16 152 153 154 147 148 149 158 159 160 155 156 157 144 145 146 150
出力例 3
151
Score : 200 points
Problem Statement
Naohiro had N+1 consecutive integers, one of each, but he lost one of them.
The remaining N integers are given in arbitrary order as A_1,\ldots,A_N. Find the lost integer.
The given input guarantees that the lost integer is uniquely determined.
Constraints
- 2 \leq N \leq 100
- 1 \leq A_i \leq 1000
- All input values are integers.
- The lost integer is uniquely determined.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the answer.
Sample Input 1
3 2 3 5
Sample Output 1
4
Naohiro originally had four integers, 2,3,4,5, then lost 4, and now has 2,3,5.
Print the lost integer, 4.
Sample Input 2
8 3 1 4 5 9 2 6 8
Sample Output 2
7
Sample Input 3
16 152 153 154 147 148 149 158 159 160 155 156 157 144 145 146 150
Sample Output 3
151
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
長さ N の整数列 A=(A_1,A_2,\ldots,A_N),B=(B_1,B_2,\ldots,B_N) が与えられます。
Q 個のクエリが与えられるので順に処理してください。 i 番目 (1\le i\le Q) のクエリは以下で説明されます。
文字 c_i と整数 X_i,V_i が与えられる。 c_i=
Aならば A_{X_i} を、 c_i=Bならば B_{X_i} を V_i に変更する。その後、 \displaystyle \sum_{k=1}^N \min(A_k,B_k) を出力する。
制約
- 1\le N,Q \le 2 \times 10^5
- 1\le A_i,B_i \le 10^9
- c_i は
AかBのいずれか - 1\le X_i \le N
- 1\le V_i \le 10^9
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N Q A_1 A_2 \ldots A_N B_1 B_2 \ldots B_N c_1 X_1 V_1 c_2 X_2 V_2 \vdots c_Q X_Q V_Q
出力
Q 行出力せよ。 i 行目 (1\le i\le Q) には i 番目のクエリに対する答えを出力せよ。
入力例 1
4 3 3 1 4 1 2 7 1 8 A 2 3 B 3 3 A 1 7
出力例 1
7 9 9
1 番目のクエリでは A=(3,3,4,1),B=(2,7,1,8) となります。したがって、1 行目には \displaystyle \min(3,2)+\min(3,7) + \min(4 , 1)+\min(1,8) = 7 を出力してください。
2 番目のクエリでは A=(3,3,4,1),B=(2,7,3,8) となります。したがって、 2 行目には \displaystyle \min(3,2)+\min(3,7) + \min(4 , 3)+\min(1,8) = 9 を出力してください。
3 番目のクエリでは A=(7,3,4,1),B=(2,7,3,8) となります。したがって、 3 行目には \displaystyle \min(7,2)+\min(3,7) + \min(4 , 3)+\min(1,8) = 9 を出力してください。
入力例 2
1 3 1 1000000000 A 1 1 A 1 1 A 1 1
出力例 2
1 1 1
入力例 3
5 3 100 100 100 100 100 100 100 100 100 100 A 4 21 A 2 99 B 4 57
出力例 3
421 420 420
Score : 300 points
Problem Statement
You are given length-N integer sequences: A=(A_1,A_2,\ldots,A_N) and B=(B_1,B_2,\ldots,B_N).
You are given Q queries to process in order. The i-th query (1\le i\le Q) is described as follows:
You are given a character c_i and integers X_i,V_i. If c_i=
A, change A_{X_i} to V_i; if c_i=B, change B_{X_i} to V_i. Then, output \displaystyle \sum_{k=1}^N \min(A_k,B_k).
Constraints
- 1\le N,Q \le 2 \times 10^5
- 1\le A_i,B_i \le 10^9
- c_i is either
AorB. - 1\le X_i \le N
- 1\le V_i \le 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N Q A_1 A_2 \ldots A_N B_1 B_2 \ldots B_N c_1 X_1 V_1 c_2 X_2 V_2 \vdots c_Q X_Q V_Q
Output
Output Q lines. The i-th line (1\le i\le Q) should contain the answer to the i-th query.
Sample Input 1
4 3 3 1 4 1 2 7 1 8 A 2 3 B 3 3 A 1 7
Sample Output 1
7 9 9
After the 1st query, A=(3,3,4,1),B=(2,7,1,8). Therefore, output \displaystyle \min(3,2)+\min(3,7) + \min(4 , 1)+\min(1,8) = 7 on the 1st line.
After the 2nd query, A=(3,3,4,1),B=(2,7,3,8). Therefore, output \displaystyle \min(3,2)+\min(3,7) + \min(4 , 3)+\min(1,8) = 9 on the 2nd line.
After the 3rd query, A=(7,3,4,1),B=(2,7,3,8). Therefore, output \displaystyle \min(7,2)+\min(3,7) + \min(4 , 3)+\min(1,8) = 9 on the 3rd line.
Sample Input 2
1 3 1 1000000000 A 1 1 A 1 1 A 1 1
Sample Output 2
1 1 1
Sample Input 3
5 3 100 100 100 100 100 100 100 100 100 100 A 4 21 A 2 99 B 4 57
Sample Output 3
421 420 420