実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
(1,2,…,N) を並び替えた数列 P と整数 X が与えられます。 数列 P の i 番目の項の値は P_i です。 P_k = X を満たす k を出力してください。
制約
- 1 \leq N \leq 100
- 1 \leq X \leq N
- P は (1,2,…,N) を並び替えてできる数列
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N X P_1 P_2 \ldots P_N
出力
答えを出力せよ。
入力例 1
4 3 2 3 1 4
出力例 1
2
P = (2,3,1,4) なので、P_2 = 3 です。したがって、2 を出力します。
入力例 2
5 2 3 5 1 4 2
出力例 2
5
入力例 3
6 6 1 2 3 4 5 6
出力例 3
6
Score : 100 points
Problem Statement
You are given a sequence P that is a permutation of (1,2,…,N), and an integer X. The i-th term of P has a value of P_i. Print k such that P_k = X.
Constraints
- 1 \leq N \leq 100
- 1 \leq X \leq N
- P is a permutation of (1,2,…,N).
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N X P_1 P_2 \ldots P_N
Output
Print the answer.
Sample Input 1
4 3 2 3 1 4
Sample Output 1
2
We have P = (2,3,1,4), so P_2 = 3. Thus, you should print 2.
Sample Input 2
5 2 3 5 1 4 2
Sample Output 2
5
Sample Input 3
6 6 1 2 3 4 5 6
Sample Output 3
6
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
チーム高橋とチーム青木が N 回の試合を行いました。 i 回め (1\leq i\leq N) の試合ではチーム高橋が X _ i 点、チーム青木が Y _ i 点を獲得しました。
N 回の試合で獲得した得点の合計がより多いチームの勝ちです。
どちらのチームが勝ったか出力してください。 ただし、獲得した得点の合計が等しい場合は引き分けとなります。
制約
- 1\leq N\leq 100
- 0\leq X _ i\leq 100\ (1\leq i\leq N)
- 0\leq Y _ i\leq 100\ (1\leq i\leq N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N X _ 1 Y _ 1 X _ 2 Y _ 2 \vdots X _ N Y _ N
出力
チーム高橋が勝った場合 Takahashi を、チーム青木が勝った場合 Aoki を、引き分けの場合 Draw を出力せよ。
入力例 1
4 10 2 10 1 10 2 3 2
出力例 1
Takahashi
4 回の試合で、チーム高橋は 33 点、チーム青木は 7 点を獲得しました。
チーム高橋が勝ったため、Takahashi を出力してください。
入力例 2
6 5 4 4 5 2 4 1 6 7 1 3 2
出力例 2
Draw
いずれのチームも 22 点を獲得しました。
引き分けなので、Draw を出力してください。
入力例 3
4 0 0 10 10 50 50 0 100
出力例 3
Aoki
一方もしくは両方のチームが、一試合のうちに 1 点も取れない場合もあります。
Score: 100 points
Problem Statement
Team Takahashi and Team Aoki played N matches. In the i-th match (1\leq i\leq N), Team Takahashi scored X _ i points, and Team Aoki scored Y _ i points.
The team with the higher total score from the N matches wins.
Print the winner. If the two teams have the same total score, it is a draw.
Constraints
- 1\leq N\leq 100
- 0\leq X _ i\leq 100\ (1\leq i\leq N)
- 0\leq Y _ i\leq 100\ (1\leq i\leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N X _ 1 Y _ 1 X _ 2 Y _ 2 \vdots X _ N Y _ N
Output
If Team Takahashi wins, print Takahashi; if Team Aoki wins, print Aoki; if it is a draw, print Draw.
Sample Input 1
4 10 2 10 1 10 2 3 2
Sample Output 1
Takahashi
In four matches, Team Takahashi scored 33 points, and Team Aoki scored 7 points.
Team Takahashi wins, so print Takahashi.
Sample Input 2
6 5 4 4 5 2 4 1 6 7 1 3 2
Sample Output 2
Draw
Both teams scored 22 points.
It is a draw, so print Draw.
Sample Input 3
4 0 0 10 10 50 50 0 100
Sample Output 3
Aoki
One or both teams may score no points in a match.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 150 点
問題文
実数 X が小数点以下第 3 位まで与えられます。
実数 X を以下の条件を満たすように出力してください。
- 小数点以下の部分について、末尾に
0を付けない - 末尾に過剰な小数点を付けない
制約
- 0 \le X < 100
- X は小数点以下第 3 位まで与えられる
入力
入力は以下の形式で標準入力から与えられる。
X
出力
答えを出力せよ。
入力例 1
1.012
出力例 1
1.012
1.012 はそのまま出力しても構いません。
入力例 2
12.340
出力例 2
12.34
12.340 を末尾に 0 を付けずに出力すると 12.34 となります。
入力例 3
99.900
出力例 3
99.9
99.900 を末尾に 0 を付けずに出力すると 99.9 となります。
入力例 4
0.000
出力例 4
0
0.000 を末尾に 0 や過剰な小数点を付けずに出力すると 0 となります。
Score : 150 points
Problem Statement
A real number X is given to the third decimal place.
Print the real number X under the following conditions.
- The decimal part must not have trailing
0s. - There must not be an unnecessary trailing decimal point.
Constraints
- 0 \le X < 100
- X is given to the third decimal place.
Input
The input is given from Standard Input in the following format:
X
Output
Output the answer.
Sample Input 1
1.012
Sample Output 1
1.012
1.012 can be printed as it is.
Sample Input 2
12.340
Sample Output 2
12.34
Printing 12.340 without the trailing 0 results in 12.34.
Sample Input 3
99.900
Sample Output 3
99.9
Printing 99.900 without the trailing 0s results in 99.9.
Sample Input 4
0.000
Sample Output 4
0
Printing 0.000 without trailing 0s or an unnecessary decimal point results in 0.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
a+b+c \leq S かつ a \times b \times c \leq T を満たす非負整数の組 (a,b,c) はいくつありますか?
制約
- 0 \leq S \leq 100
- 0 \leq T \leq 10000
- S, T は整数である。
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
条件を満たす非負整数の組 (a,b,c) の個数を出力せよ。
入力例 1
1 0
出力例 1
4
条件を満たす非負整数の組 (a,b,c) は (0,0,0), (0,0,1), (0,1,0), (1,0,0) の 4 つです。
入力例 2
2 5
出力例 2
10
入力例 3
10 10
出力例 3
213
入力例 4
30 100
出力例 4
2471
Score : 200 points
Problem Statement
How many triples of non-negative integers (a, b, c) satisfy a+b+c \leq S and a \times b \times c \leq T?
Constraints
- 0 \leq S \leq 100
- 0 \leq T \leq 10000
- S and T are integers.
Input
Input is given from Standard Input in the following format:
S T
Output
Print the number of triples of non-negative integers (a,b,c) satisfying the conditions.
Sample Input 1
1 0
Sample Output 1
4
The triples (a,b,c) satisfying the conditions are (0,0,0), (0,0,1), (0,1,0), and (1,0,0) ― there are four of them.
Sample Input 2
2 5
Sample Output 2
10
Sample Input 3
10 10
Sample Output 3
213
Sample Input 4
30 100
Sample Output 4
2471
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
長さ N の数列 A=(A_1,\ldots,A_N) が与えられます。
1\leq i,j \leq N である組 (i,j) であって、A_i-A_j=X となるものが存在するかどうか判定してください。
制約
- 2 \leq N \leq 2\times 10^5
- -10^9 \leq A_i \leq 10^9
- -10^9 \leq X \leq 10^9
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N X A_1 \ldots A_N
出力
1\leq i,j \leq N である組 (i,j) であって、A_i-A_j=X となるものが存在するとき Yes、存在しないとき No と出力せよ。
入力例 1
6 5 3 1 4 1 5 9
出力例 1
Yes
A_6-A_3=9-4=5 です。
入力例 2
6 -4 -2 -7 -1 -8 -2 -8
出力例 2
No
A_i-A_j=-4 となる組 (i,j) は存在しません。
入力例 3
2 0 141421356 17320508
出力例 3
Yes
A_1-A_1=0 です。
Score : 300 points
Problem Statement
You are given a sequence of N numbers: A=(A_1,\ldots,A_N).
Determine whether there is a pair (i,j) with 1\leq i,j \leq N such that A_i-A_j=X.
Constraints
- 2 \leq N \leq 2\times 10^5
- -10^9 \leq A_i \leq 10^9
- -10^9 \leq X \leq 10^9
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N X A_1 \ldots A_N
Output
Print Yes if there is a pair (i,j) with 1\leq i,j \leq N such that A_i-A_j=X, and No otherwise.
Sample Input 1
6 5 3 1 4 1 5 9
Sample Output 1
Yes
We have A_6-A_3=9-4=5.
Sample Input 2
6 -4 -2 -7 -1 -8 -2 -8
Sample Output 2
No
There is no pair (i,j) such that A_i-A_j=-4.
Sample Input 3
2 0 141421356 17320508
Sample Output 3
Yes
We have A_1-A_1=0.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
1 以上 N 以下の整数からなる集合が M 個あり、順に S_1, S_2, \dots, S_M と呼びます。
S_i は C_i 個の整数 a_{i, 1}, a_{i, 2}, \dots, a_{i, C_i} からなります。
M 個の集合から 1 個以上の集合を選ぶ方法は 2^M-1 通りあります。
このうち、次の条件を満たす選び方は何通りありますか?
- 1 \leq x \leq N を満たす全ての整数 x に対して、選んだ集合の中に x を含む集合が少なくとも 1 個存在する。
制約
- 1 \leq N \leq 10
- 1 \leq M \leq 10
- 1 \leq C_i \leq N
- 1 \leq a_{i,1} \lt a_{i,2} \lt \dots \lt a_{i,C_i} \leq N
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M
C_1
a_{1,1} a_{1,2} \dots a_{1,C_1}
C_2
a_{2,1} a_{2,2} \dots a_{2,C_2}
\vdots
C_M
a_{M,1} a_{M,2} \dots a_{M,C_M}
出力
問題文の条件を満たす集合の選び方の数を出力せよ。
入力例 1
3 3 2 1 2 2 1 3 1 2
出力例 1
3
入力で与えられている集合はそれぞれ S_1 = \lbrace 1, 2 \rbrace, S_2 = \lbrace 1, 3 \rbrace, S_3 = \lbrace 2 \rbrace です。
問題文の条件を満たす集合の選び方は次の 3 通りです。
- S_1, S_2 を選ぶ。
- S_1, S_2, S_3 を選ぶ。
- S_2, S_3 を選ぶ。
入力例 2
4 2 2 1 2 2 1 3
出力例 2
0
問題文の条件を満たす選び方が存在しない場合もあります。
入力例 3
6 6 3 2 3 6 3 2 4 6 2 3 6 3 1 5 6 3 1 3 6 2 1 4
出力例 3
18
Score : 300 points
Problem Statement
There are M sets, called S_1, S_2, \dots, S_M, consisting of integers between 1 and N.
S_i consists of C_i integers a_{i, 1}, a_{i, 2}, \dots, a_{i, C_i}.
There are (2^M-1) ways to choose one or more sets from the M sets.
How many of them satisfy the following condition?
- For all integers x such that 1 \leq x \leq N, there is at least one chosen set containing x.
Constraints
- 1 \leq N \leq 10
- 1 \leq M \leq 10
- 1 \leq C_i \leq N
- 1 \leq a_{i,1} \lt a_{i,2} \lt \dots \lt a_{i,C_i} \leq N
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M
C_1
a_{1,1} a_{1,2} \dots a_{1,C_1}
C_2
a_{2,1} a_{2,2} \dots a_{2,C_2}
\vdots
C_M
a_{M,1} a_{M,2} \dots a_{M,C_M}
Output
Print the number of ways to choose sets that satisfy the conditions in the Problem Statement.
Sample Input 1
3 3 2 1 2 2 1 3 1 2
Sample Output 1
3
The sets given in the input are S_1 = \lbrace 1, 2 \rbrace, S_2 = \lbrace 1, 3 \rbrace, S_3 = \lbrace 2 \rbrace.
The following three ways satisfy the conditions in the Problem Statement:
- choosing S_1, S_2;
- choosing S_1, S_2, S_3;
- choosing S_2, S_3.
Sample Input 2
4 2 2 1 2 2 1 3
Sample Output 2
0
There may be no way to choose sets that satisfies the conditions in the Problem Statement.
Sample Input 3
6 6 3 2 3 6 3 2 4 6 2 3 6 3 1 5 6 3 1 3 6 2 1 4
Sample Output 3
18
実行時間制限: 3 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
高橋君は N 種類の硬貨をそれぞれ何枚か持っており、 具体的には、1\leq i\leq N について A_i 円硬貨を B_i 枚持っています。
高橋君が現在持っている硬貨を用いて、(お釣りが出ないように)ちょうど X 円を支払うことができるか判定してください。
制約
- 1\leq N\leq 50
- 1\leq X\leq 10^4
- 1\leq A_i\leq 100
- 1\leq B_i\leq 50
- A_i はすべて異なる。
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N X A_1 B_1 A_2 B_2 \vdots A_N B_N
出力
高橋君が現在持っている硬貨を用いてちょうど X 円を支払うことができる場合は Yes を、
できない場合は No を出力せよ。
入力例 1
2 19 2 3 5 6
出力例 1
Yes
高橋君は 2 円硬貨を 3 枚、5 円硬貨を 6 枚持っています。
このうち、2 円硬貨を 2 枚、5 円硬貨を 3 枚用いることでちょうど 2\times 2+5\times 3=19 円を支払うことができます。
よって、Yes を出力します。
入力例 2
2 18 2 3 5 6
出力例 2
No
持っている硬貨をどのように組み合わせてもちょうど 18 円を支払うことはできません。
よって、No を出力します。
入力例 3
3 1001 1 1 2 1 100 10
出力例 3
Yes
1 枚も使用しない硬貨が存在しても構いません。
Score : 400 points
Problem Statement
Takahashi has N kinds of coins; specifically, for 1\leq i\leq N, he has B_i coins worth A_i yen (the currency in Japan) each.
Determine if Takahashi can pay exactly X yen (without change) with the coins he currently has.
Constraints
- 1\leq N\leq 50
- 1\leq X\leq 10^4
- 1\leq A_i\leq 100
- 1\leq B_i\leq 50
- A_i are pairwise distinct.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N X A_1 B_1 A_2 B_2 \vdots A_N B_N
Output
Print Yes if Takahashi can pay exactly X yen with the coins he currently has;
print No otherwise.
Sample Input 1
2 19 2 3 5 6
Sample Output 1
Yes
Takahashi has three 2-yen coins and six 5-yen coins.
He can use two 2-yen coins and three 5-yen coins to pay exactly 2\times 2+5\times 3=19 yen.
Thus, Yes should be printed.
Sample Input 2
2 18 2 3 5 6
Sample Output 2
No
There is no combination of the coins that he can use to pay exactly 18 yen.
Thus, No should be printed.
Sample Input 3
3 1001 1 1 2 1 100 10
Sample Output 3
Yes
He need not use all kinds of coins.
実行時間制限: 4 sec / メモリ制限: 1024 MiB
配点 : 450 点
問題文
N 個の島と、2 つの島の間を双方向に結ぶ M 本の橋があり、
それぞれ島 1, 島 2, \ldots, 島 N および 橋 1, 橋 2, \ldots, 橋 M と番号づけられています。
橋 i は島 U_i と島 V_i を相互に結んでおり、どちらの方向に移動するにも T_i だけ時間がかかります。
ここで、橋の両端が同一の島であるような橋は存在しませんが、ある 2 つの島の間が 2 本以上の橋で直接繋がれている可能性はあります。
また、どの 2 つの島の間もいくつかの橋をわたって移動することができます。
Q 個の問題が与えられるので、各問題に対する答えを求めてください。i 番目の問題は次のようなものです。
相異なる K_i 本の橋、橋 B_{i,1}, 橋 B_{i,2}, \ldots, 橋 B_{i,K_i} が与えられます。
これらの橋をすべて 1 回以上わたり、島 1 から島 N まで移動するために必要な時間の最小値を求めてください。
ただし、島 1 から島 N までの移動において、橋をわたって島の間を移動するのにかかる時間以外は無視できるものとします。
また、与えられた橋はどの順で、またどの向きにわたってもかまいません。
制約
- 2\leq N \leq 400
- N-1\leq M \leq 2\times 10^5
- 1\leq U_i<V_i\leq N
- 1\leq T_i\leq 10^9
- 1\leq Q\leq 3000
- 1\leq K_i\leq 5
- 1\leq B_{i,1}<B_{i,2}<\cdots<B_{i,K_i}\leq M
- 入力はすべて整数
- どの 2 つの島の間もいくつかの橋をわたって移動することができる。
入力
入力は以下の形式で標準入力から与えられる。
N M
U_1 V_1 T_1
U_2 V_2 T_2
\vdots
U_M V_M T_M
Q
K_1
B_{1,1} B_{1,2} \cdots B_{1,{K_1}}
K_2
B_{2,1} B_{2,2} \cdots B_{2,{K_2}}
\vdots
K_Q
B_{Q,1} B_{Q,2} \cdots B_{Q,{K_Q}}
出力
Q 行出力せよ。i 行目(1\leq i\leq Q)には i 番目の問題に対する答えを整数で出力せよ。
入力例 1
3 5 1 2 10 1 3 20 1 3 30 2 3 15 2 3 25 2 1 1 2 3 5
出力例 1
25 70
1 番目の問題では橋 1 をわたった上で島 1 から島 3 へ移動するために必要な時間の最小値を求める必要があります。
橋 1 を使って島 1 から島 2 に移動した後に橋 4 を使って島 2 から島 3 に移動したとき時間は 10+15=25 だけかかり、このときが最小です。
よって、1 行目には 25 を出力します。
2 番目の問題では橋 3 および橋 5 をわたった上で島 1 から島 3 へ移動するために必要な時間の最小値を求める必要があります。
橋 3 を通って島 1 から島 3 に移動した後に橋 5 を使って島 2 へ移動し、橋 4 を使用して島 3 に移動したとき時間は 30+25+15=70 だけかかり、このときが最小です。よって、2 行目には 70 を出力します。
入力例 2
6 6 1 5 1 2 5 1 2 4 1 3 4 1 3 6 1 1 6 1 2 5 1 2 3 4 5 1 5
出力例 2
5 3
各問題において指定された橋をわたる際、わたる方向はどちらでも問題ありません。
入力例 3
5 5 1 2 1000000000 2 3 1000000000 3 4 1000000000 4 5 1000000000 1 5 1000000000 1 1 3
出力例 3
4000000000
答えが 32bit 整数型に収まらない可能性があることに注意してください。
Score : 450 points
Problem Statement
There are N islands and M bidirectional bridges connecting two islands. The islands and bridges are numbered 1, 2, \ldots, N and 1, 2, \ldots, M, respectively.
Bridge i connects islands U_i and V_i, and the time it takes to cross it in either direction is T_i.
No bridge connects an island to itself, but it is possible for two islands to be directly connected by more than one bridge.
One can travel between any two islands using some bridges.
You are given Q queries, so answer each of them. The i-th query is as follows:
You are given K_i distinct bridges: bridges B_{i,1}, B_{i,2}, \ldots, B_{i,K_i}.
Find the minimum time required to travel from island 1 to island N using each of these bridges at least once.
Only consider the time spent crossing bridges.
You can cross the given bridges in any order and in any direction.
Constraints
- 2 \leq N \leq 400
- N-1 \leq M \leq 2 \times 10^5
- 1 \leq U_i < V_i \leq N
- 1 \leq T_i \leq 10^9
- 1 \leq Q \leq 3000
- 1 \leq K_i \leq 5
- 1 \leq B_{i,1} < B_{i,2} < \cdots < B_{i,K_i} \leq M
- All input values are integers.
- It is possible to travel between any two islands using some bridges.
Input
The input is given from Standard Input in the following format:
N M
U_1 V_1 T_1
U_2 V_2 T_2
\vdots
U_M V_M T_M
Q
K_1
B_{1,1} B_{1,2} \cdots B_{1,{K_1}}
K_2
B_{2,1} B_{2,2} \cdots B_{2,{K_2}}
\vdots
K_Q
B_{Q,1} B_{Q,2} \cdots B_{Q,{K_Q}}
Output
Print Q lines. The i-th line (1 \leq i \leq Q) should contain the answer to the i-th query as an integer.
Sample Input 1
3 5 1 2 10 1 3 20 1 3 30 2 3 15 2 3 25 2 1 1 2 3 5
Sample Output 1
25 70
For the first query, we need to find the minimum time to travel from island 1 to island 3 while using bridge 1. The minimum time is achieved by using bridge 1 to move from island 1 to island 2, then using bridge 4 to move from island 2 to island 3. The time taken is 10 + 15 = 25. Hence, print 25 on the first line.
For the second query, we need to find the minimum time to travel from island 1 to island 3 while using both bridges 3 and 5. The minimum time is achieved by using bridge 3 to move from island 1 to island 3, then using bridge 5 to move to island 2, and finally using bridge 4 to return to island 3. The time taken is 30 + 25 + 15 = 70. Hence, print 70 on the second line.
Sample Input 2
6 6 1 5 1 2 5 1 2 4 1 3 4 1 3 6 1 1 6 1 2 5 1 2 3 4 5 1 5
Sample Output 2
5 3
For each query, you can cross the specified bridges in either direction.
Sample Input 3
5 5 1 2 1000000000 2 3 1000000000 3 4 1000000000 4 5 1000000000 1 5 1000000000 1 1 3
Sample Output 3
4000000000
Beware that the answer may not fit in a 32-bit integer.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
英小文字からなる長さ N の文字列 S と Q 個のクエリが与えられます。クエリを順に処理してください。
クエリは以下の 2 種類です。
1 x c: S の x 文字目を文字 c に置き換える2 l r: S を文字の昇順に並び替えて得られる文字列を T とする。S の l 文字目から r 文字目までからなる文字列が T の部分文字列であるときYes、部分文字列でないときNoを出力する
部分文字列とは?
S の部分文字列とは、S の先頭から 0 文字以上、末尾から 0 文字以上削除して得られる文字列のことをいいます。 例えば、ab は abc の部分文字列ですが、ac は abc の部分文字列ではありません。
制約
- 1\leq N \leq 10^5
- S は英小文字からなる長さ N の文字列
- 1 \leq Q \leq 10^5
- 1 種類目のクエリにおいて、1 \leq x \leq N
- 1 種類目のクエリにおいて、c は英小文字
- 2 種類目のクエリにおいて、1 \leq l \leq r \leq N
入力
入力は以下の形式で標準入力から与えられる。ただし、\text{query}_i で i 番目のクエリを表す。
N
S
Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
出力
問題文中の指示に従ってクエリを処理せよ。
入力例 1
6 abcdcf 4 2 1 3 2 2 6 1 5 e 2 2 6
出力例 1
Yes No Yes
- 1 番目のクエリにおいて、S を文字の昇順に並び替えて得られる文字列 T は
abccdfです。 S の 1 文字目から 3 文字目までからなる文字列はabcであり T の部分文字列です。よってYesを出力します。 - 2 番目のクエリにおいて、S を文字の昇順に並び替えて得られる文字列 T は
abccdfです。 S の 2 文字目から 6 文字目までからなる文字列はbcdcfであり T の部分文字列ではありません。よってNoを出力します。 - 3 番目のクエリにより、S の 5 文字目が
eに置き換えられ、S はabcdefとなります。 - 4 番目のクエリにおいて、S を文字の昇順に並び替えて得られる文字列 T は
abcdefです。 S の 2 文字目から 6 文字目までからなる文字列はbcdefであり T の部分文字列です。よってYesを出力します。
Score : 500 points
Problem Statement
You are given a string S of length N consisting of lowercase English letters, and Q queries. Process the queries in order.
Each query is of one of the following two kinds:
1 x c: replace the x-th character of S by the character c.2 l r: let T be the string obtained by sorting the characters of S in ascending order. PrintYesif the string consisting of the l-th through r-th characters of S is a substring of T; printNootherwise.
What is a substring?
A substring of S is a string obtained by removing 0 or more initial characters and 0 or more final characters of S. For example,ab is a substring of abc, while ac is not a substring of abc.
Constraints
- 1\leq N \leq 10^5
- S is a string of length N consisting of lowercase English letters.
- 1 \leq Q \leq 10^5
- For each query of the first kind, 1 \leq x \leq N.
- For each query of the first kind, c is a lowercase English letter.
- For each query of the second kind, 1 \leq l \leq r \leq N.
Input
The input is given from Standard Input in the following format, where \text{query}_i denotes the i-th query:
N
S
Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
Output
Process the queries as instructed in the Problem Statement.
Sample Input 1
6 abcdcf 4 2 1 3 2 2 6 1 5 e 2 2 6
Sample Output 1
Yes No Yes
- In the 1-st query,
abccdfis the string T obtained by sorting the characters of S in ascending order. The stringabc, consisting of the 1-st through 3-rd characters of S, is a substring of T, soYesshould be printed. - In the 2-nd query,
abccdfis the string T obtained by sorting the characters of S in ascending order. The stringbcdcf, consisting of the 2-nd through 6-th characters of S, is not a substring of T, soNoshould be printed. - The 3-rd query sets the 5-th character of S to
e, making Sabcdef. - In the 4-th query,
abcdefis the string T obtained by sorting the characters of S in ascending order. The stringbcdef, consisting of the 2-nd through 6-th characters of S, is a substring of T, soYesshould be printed.