実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
水圧は水深のみに依存し、水深 x [m] の場所では \dfrac{x}{100} [MPa] になるものとします。
水深 D [m] の場所の水圧は何 [MPa] ですか?
制約
- 1 \leq D \leq 10000
- D は整数である。
入力
入力は以下の形式で標準入力から与えられる。
D
出力
答えを出力せよ。想定解答との絶対誤差または相対誤差が 10^{-3} 以下であれば正解として扱われる。
入力例 1
1000
出力例 1
10
水深 1000 [m] の場所の水圧は 10 [MPa] です。10.0 や 9.999999 などを出力しても正解となります。
入力例 2
50
出力例 2
0.5
入力例 3
3141
出力例 3
31.41
Score : 100 points
Problem Statement
Let us assume that water pressure depends only on depth and is \dfrac{x}{100} megapascal at a depth of x meters.
What is the water pressure in megapascals at a depth of D meters?
Constraints
- 1 \leq D \leq 10000
- D is an integer.
Input
Input is given from Standard Input in the following format:
D
Output
Print the answer. Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-3}.
Sample Input 1
1000
Sample Output 1
10
The water pressure at a depth of 1000 meters is 10 megapascal. Outputs such as 10.0 and 9.999999 would also be accepted.
Sample Input 2
50
Sample Output 2
0.5
Sample Input 3
3141
Sample Output 3
31.41
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
髙橋君はサッカーの試合で N 回ペナルティキックを蹴ります。
髙橋君は i 回目のペナルティキックでは、i が 3 の倍数の場合は失敗しそれ以外の場合は成功します。
髙橋君がペナルティキックを蹴ったときの結果を出力してください。
制約
- 1 \leq N \leq 100
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N
出力
髙橋君のペナルティキックの結果を表す長さ N の文字列を出力せよ。結果を表す文字列の i (1 \leq i \leq N) 文字目は髙橋君が i 回目のペナルティキックで成功した場合は o 、失敗した場合は x とする。
入力例 1
7
出力例 1
ooxooxo
髙橋君は 3 回目と 6 回目のペナルティキックに失敗するので、3 文字目と 6 文字目が x となります。
入力例 2
9
出力例 2
ooxooxoox
Score: 100 points
Problem Statement
Takahashi will have N penalty kicks in a soccer match.
For the i-th penalty kick, he will fail if i is a multiple of 3, and succeed otherwise.
Print the results of his penalty kicks.
Constraints
- 1 \leq N \leq 100
- All inputs are integers.
Input
The input is given from Standard Input in the following format:
N
Output
Print a string of length N representing the results of Takahashi's penalty kicks. The i-th character (1 \leq i \leq N) should be o if Takahashi succeeds in the i-th penalty kick, and x if he fails.
Sample Input 1
7
Sample Output 1
ooxooxo
Takahashi fails the third and sixth penalty kicks, so the third and sixth characters will be x.
Sample Input 2
9
Sample Output 2
ooxooxoox
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
長さ N の整数からなる数列 A=(A_1,\ldots,A_N) が与えられます。
A_1,\ldots,A_N に含まれない最小の非負整数を求めてください。
制約
- 1 \leq N \leq 2000
- 0 \leq A_i \leq 2000
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \ldots A_N
出力
答えを出力せよ。
入力例 1
8 0 3 2 6 2 1 0 0
出力例 1
4
非負整数は 0,1,2,3,4,\ldots と続きます。
0,1,2,3 は A に含まれ、4 は A に含まれないので、答えは 4 です。
入力例 2
3 2000 2000 2000
出力例 2
0
Score : 200 points
Problem Statement
You are given a sequence of length N consisting of integers: A=(A_1,\ldots,A_N).
Find the smallest non-negative integer not in (A_1,\ldots,A_N).
Constraints
- 1 \leq N \leq 2000
- 0 \leq A_i \leq 2000
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 \ldots A_N
Output
Print the answer.
Sample Input 1
8 0 3 2 6 2 1 0 0
Sample Output 1
4
The non-negative integers are 0,1,2,3,4,\ldots.
We have 0,1,2,3 in A, but not 4, so the answer is 4.
Sample Input 2
3 2000 2000 2000
Sample Output 2
0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
高橋君は長さ N の整数列 A=(A_1,A_2,\ldots,A_N) を持っています。
A は広義単調増加であることが保証されます。
高橋君はこの整数列に対して M 回操作を行います。 i 回目 (1\leq i\leq M) の操作では、次の操作を行います。
数列 A が B_i を要素として持つならば、そのような要素を 1 つ選び、削除する。 そのような要素が存在しないならば何もしない。
A は広義単調増加であるため、操作後の列は要素の選び方によらず一意であり、再び広義単調増加となることに注意せよ。
M 回の操作を行なった後の A を求めてください。
広義単調増加 とは
数列 X=(X_1,X_2,\ldots,X_K) が広義単調増加であるとは、 任意の i (1\leq i\leq K-1) について、 X_i\leq X_{i+1} をみたすことを指します。制約
- 1 \leq N \leq 100
- 1 \leq M \leq 100
- 1 \leq A_i,B_i \leq 10^9
- 整数列 A は広義単調増加である。
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \ldots A_N B_1 B_2 \ldots B_M
出力
操作後の A の各要素を、順に空白区切りで一行に出力せよ。
操作後の A が空ならば、何も出力しないようにせよ。
入力例 1
8 5 1 2 2 3 3 3 5 6 2 2 7 3 2
出力例 1
1 3 3 5 6
最初、A は A=(1,2,2,3,3,3,5,6) です。
操作は次のように行われます。
- A から 2 を 1 つ削除し、操作後の A は A=(1,2,3,3,3,5,6) となります。
- A から 2 を 1 つ削除し、操作後の A は A=(1,3,3,3,5,6) となります。
- A は 7 を要素として持たないため、何も行いません。操作後の A は A=(1,3,3,3,5,6) のままです。
- A から 3 を 1 つ削除し、操作後の A は A=(1,3,3,5,6) となります。
- A は 2 を要素として持たないため、何も行いません。操作後の A は A=(1,3,3,5,6) のままです。
よって、すべての操作の後、A=(1,3,3,5,6) であるため、要素をこの順に空白区切りで出力します。
入力例 2
1 2 1 1 1
出力例 2
操作後の A は空となるため、何も出力しません。
Score : 200 points
Problem Statement
Takahashi has an integer sequence A=(A_1,A_2,\ldots,A_N) of length N.
It is guaranteed that A is non-decreasing.
Takahashi performs M operations on this integer sequence. In the i-th operation (1\leq i\leq M), he performs the following operation:
If the sequence A contains B_i as an element, select one such element and delete it. If no such element exists, do nothing.
Note that since A is non-decreasing, the sequence after the operation is uniquely determined regardless of the choice of element, and remains non-decreasing.
Find A after performing M operations.
What is non-decreasing?
A sequence X=(X_1,X_2,\ldots,X_K) is non-decreasing if X_i\leq X_{i+1} holds for all i (1\leq i\leq K-1).Constraints
- 1 \leq N \leq 100
- 1 \leq M \leq 100
- 1 \leq A_i,B_i \leq 10^9
- The integer sequence A is non-decreasing.
- 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_N B_1 B_2 \ldots B_M
Output
Output the elements of A after the operations, in order, separated by spaces on a single line.
If A is empty after the operations, output nothing.
Sample Input 1
8 5 1 2 2 3 3 3 5 6 2 2 7 3 2
Sample Output 1
1 3 3 5 6
Initially, A is A=(1,2,2,3,3,3,5,6).
The operations are performed as follows:
- Delete one 2 from A, and A becomes A=(1,2,3,3,3,5,6) after the operation.
- Delete one 2 from A, and A becomes A=(1,3,3,3,5,6) after the operation.
- Since A does not contain 7 as an element, do nothing. A remains A=(1,3,3,3,5,6) after the operation.
- Delete one 3 from A, and A becomes A=(1,3,3,5,6) after the operation.
- Since A does not contain 2 as an element, do nothing. A remains A=(1,3,3,5,6) after the operation.
Therefore, after all operations, A=(1,3,3,5,6), so output the elements in this order separated by spaces.
Sample Input 2
1 2 1 1 1
Sample Output 2
A becomes empty after the operations, so output nothing.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
1 から N の番号がついた N 個の箱と 1 から N の番号がついた N 個の荷物があります。荷物 i (1 \leq i \leq N) は箱 A_i の中にあり、重さは W_i です。
あなたは荷物を一つ選び、他の箱の中に移動させる操作を 0 回以上繰り返し行うことができます。1 回の操作で移動させる荷物の重さが w であるとき、w のコストがかかります。
全ての箱に荷物が 1 つずつ入っている状態にするためにかかるコストの総和の最小値を求めてください。
制約
- 1 \leq N \leq 10^{5}
- 1 \leq A_i \leq N (1 \leq i \leq N)
- 1 \leq W_i \leq 10^{4} (1 \leq i \leq N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N W_1 W_2 \ldots W_N
出力
全ての箱に荷物が 1 つずつ入っている状態にするためにかかるコストの総和の最小値を出力せよ。
入力例 1
5 2 2 3 3 5 33 40 2 12 16
出力例 1
35
以下の 2 回の荷物の移動で、すべての箱に荷物が 1 つずつ入っている状態にすることができます。
- 荷物 1 を箱 2 から箱 1 に移す。このとき、コストは 33 である。
- 荷物 3 を箱 3 から箱 4 に移す。このとき、コストは 2 である。
この 2 回の荷物の移動は合計 35 のコストかかります。 35 未満のコストですべての箱に荷物が 1 つずつ入っている状態にすることはできないため、 35 を出力します。
入力例 2
12 3 6 7 4 12 4 8 11 11 1 8 11 3925 9785 9752 3587 4013 1117 3937 7045 6437 6208 3391 6309
出力例 2
17254
Score : 250 points
Problem Statement
There are N boxes numbered 1 to N and N items numbered 1 to N. Item i (1 \leq i \leq N) is in box A_i and has a weight of W_i.
You can repeatedly perform the operation of choosing an item and moving it to another box zero or more times. If the weight of the item being moved is w, the cost of the operation is w.
Find the minimum total cost required to make each box contain exactly one item.
Constraints
- 1 \leq N \leq 10^{5}
- 1 \leq A_i \leq N (1 \leq i \leq N)
- 1 \leq W_i \leq 10^{4} (1 \leq i \leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N W_1 W_2 \ldots W_N
Output
Print the minimum total cost required to make each box contain exactly one item.
Sample Input 1
5 2 2 3 3 5 33 40 2 12 16
Sample Output 1
35
With the following two moves, you can make each box contain exactly one item:
- Move item 1 from box 2 to box 1. The cost is 33.
- Move item 3 from box 3 to box 4. The cost is 2.
The total cost of these two moves is 35. It is impossible to make each box contain exactly one item with a cost less than 35, so print 35.
Sample Input 2
12 3 6 7 4 12 4 8 11 11 1 8 11 3925 9785 9752 3587 4013 1117 3937 7045 6437 6208 3391 6309
Sample Output 2
17254
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
N カップのアイスクリームがあります。
i カップ目の味は F_i 、美味しさは S_i ( S_i は偶数 ) です。
あなたは、 N 個のカップの中から 2 つを選んで食べることにしました。
このときの満足度は次のように定義されます。
- 食べたアイスクリームの美味しさを s,t ( 但し、 s \ge t ) とする。
- 2 つのカップの味が異なるなら、満足度は \displaystyle s+t である。
- そうでないなら、満足度は \displaystyle s + \frac{t}{2} である。
満足度として達成可能な最大値を求めてください。
制約
- 入力は全て整数
- 2 \le N \le 3 \times 10^5
- 1 \le F_i \le N
- 2 \le S_i \le 10^9
- S_i は偶数
入力
入力は以下の形式で標準入力から与えられる。
N F_1 S_1 F_2 S_2 \vdots F_N S_N
出力
答えを整数として出力せよ。
入力例 1
4 1 4 2 10 2 8 3 6
出力例 1
16
2 カップ目と 4 カップ目のアイスを食べることを考えます。
- 2 カップ目の味は 2 、美味しさは 10 です。
- 4 カップ目の味は 3 、美味しさは 6 です。
- 両者の味は異なるので、満足度は 10+6=16 です。
以上より、満足度 16 を達成できます。
満足度を 16 より大きくすることはできません。
入力例 2
4 4 10 3 2 2 4 4 12
出力例 2
17
1 カップ目と 4 カップ目のアイスを食べることを考えます。
- 1 カップ目の味は 4 、美味しさは 10 です。
- 4 カップ目の味は 4 、美味しさは 12 です。
- 両者の味は同じなので、満足度は 12+\frac{10}{2}=17 です。
以上より、満足度 17 を達成できます。
満足度を 17 より大きくすることはできません。
Score : 300 points
Problem Statement
We have N cups of ice cream.
The flavor and deliciousness of the i-th cup are F_i and S_i, respectively (S_i is an even number).
You will choose and eat two of the N cups.
Your satisfaction here is defined as follows.
- Let s and t (s \ge t) be the deliciousness of the eaten cups.
- If the two cups have different flavors, your satisfaction is \displaystyle s+t.
- Otherwise, your satisfaction is \displaystyle s + \frac{t}{2}.
Find the maximum achievable satisfaction.
Constraints
- All input values are integers.
- 2 \le N \le 3 \times 10^5
- 1 \le F_i \le N
- 2 \le S_i \le 10^9
- S_i is even.
Input
Input is given from Standard Input in the following format:
N F_1 S_1 F_2 S_2 \vdots F_N S_N
Output
Print the answer as an integer.
Sample Input 1
4 1 4 2 10 2 8 3 6
Sample Output 1
16
Consider eating the second and fourth cups.
- The second cup has a flavor of 2 and deliciousness of 10.
- The fourth cup has a flavor of 3 and deliciousness of 6.
- Since they have different flavors, your satisfaction is 10+6=16.
Thus, you can achieve the satisfaction of 16.
You cannot achieve a satisfaction greater than 16.
Sample Input 2
4 4 10 3 2 2 4 4 12
Sample Output 2
17
Consider eating the first and fourth cups.
- The first cup has a flavor of 4 and deliciousness of 10.
- The fourth cup has a flavor of 4 and deliciousness of 12.
- Since they have the same flavor, your satisfaction is 12+\frac{10}{2}=17.
Thus, you can achieve the satisfaction of 17.
You cannot achieve a satisfaction greater than 17.
実行時間制限: 4 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
高橋君は道端であるパズルを拾いました。
このパズルは、9 個の頂点と M 本の辺からなる無向グラフ、および、8 つのコマで構成されます。
グラフの 9 つの頂点はそれぞれ頂点 1、頂点 2、\ldots、頂点 9 と呼ばれ、
i = 1, 2, \ldots, M について、i 番目の辺は頂点 u_i と頂点 v_i を結んでいます。
8 つのコマはそれぞれコマ 1、コマ 2、\ldots、コマ 8 と呼ばれ、
j = 1, 2, \ldots, 8 について、コマ j は頂点 p_j に置かれています。
ここで、すべてのコマはそれぞれ異なる頂点に置かれていることが保証されます。
コマが置かれていない「空の頂点」がただ一つ存在することに注意してください。
高橋君はこのパズルに対して下記の操作を好きな回数( 0 回でもよい)だけ行うことができます。
空の頂点に隣接する頂点に置かれたコマを 1 つ選び、選んだコマを空の頂点に移動する。
高橋君は上記の操作を繰り返して、このパズルを「完成」させようとしています。 パズルは、下記の状態を満たしたときに完成となります。
j = 1, 2, \ldots, 8 について、コマ j は 頂点 j に置かれている。
高橋君がパズルを完成させることが可能かどうかを判定し、可能な場合はそのために必要な操作回数の最小値を出力してください。
制約
- 0 \leq M \leq 36
- 1 \leq u_i, v_i \leq 9
- 与えられるグラフは多重辺、自己ループを持たない
- 1 \leq p_j \leq 9
- j \neq j' \Rightarrow p_j \neq p_{j'}
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
M u_1 v_1 u_2 v_2 \vdots u_M v_M p_1 p_2 \ldots p_8
出力
高橋君がパズルを完成させることが可能な場合は、そのために必要な操作回数の最小値を出力せよ。 高橋君がパズルを完成させることが不可能な場合は、-1 を出力せよ。
入力例 1
5 1 2 1 3 1 9 2 9 3 9 3 9 2 4 5 6 7 8
出力例 1
5
下記の手順によって、5 回の操作でパズルを完成させることができます。
- コマ 2 を頂点 9 から頂点 1 に移動する。
- コマ 3 を頂点 2 から頂点 9 に移動する。
- コマ 2 を頂点 1 から頂点 2 に移動する。
- コマ 1 を頂点 3 から頂点 1 に移動する。
- コマ 3 を頂点 9 から頂点 3 に移動する。
一方、5 回未満の操作でパズルを完成させることはできません。よって、5 を出力します。
与えられるグラフは連結とは限らないことに注意してください。
入力例 2
5 1 2 1 3 1 9 2 9 3 9 1 2 3 4 5 6 7 8
出力例 2
0
パズルは初めから完成しています。よって、完成させるために必要な操作回数の最小値は 0 回です。
入力例 3
12 8 5 9 6 4 5 4 1 2 5 8 9 2 1 3 6 8 7 6 5 7 4 2 3 1 2 3 4 5 6 8 7
出力例 3
-1
操作の繰り返しによってパズルを完成させることができないので、-1 を出力します。
入力例 4
12 6 5 5 4 4 1 4 7 8 5 2 1 2 5 6 9 3 6 9 8 8 7 3 2 2 3 4 6 1 9 7 8
出力例 4
16
Score : 400 points
Problem Statement
Takahashi found a puzzle along some road.
It is composed of an undirected graph with nine vertices and M edges, and eight pieces.
The nine vertices of the graph are called Vertex 1, Vertex 2, \ldots, Vertex 9. For each i = 1, 2, \ldots, M, the i-th edge connects Vertex u_i and Vertex v_i.
The eight pieces are called Piece 1, Piece 2, \ldots, Piece 8.
For each j = 1, 2, \ldots, 8, Piece j is on Vertex p_j.
Here, it is guaranteed that all pieces are on distinct vertices.
Note that there is exactly one empty vertex without a piece.
Takahashi can do the following operation on the puzzle any number of times (possibly zero).
Choose a piece on a vertex adjacent to the empty vertex, and move it to the empty vertex.
By repeating this operation, he aims to complete the puzzle. The puzzle is considered complete when the following holds.
- For each j = 1, 2, \ldots, 8, Piece j is on Vertex j.
Determine whether it is possible for Takahashi to complete the puzzle. If it is possible, find the minimum number of operations needed to do so.
Constraints
- 0 \leq M \leq 36
- 1 \leq u_i, v_i \leq 9
- The given graph has no multi-edges or self-loops.
- 1 \leq p_j \leq 9
- j \neq j' \Rightarrow p_j \neq p_{j'}
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
M u_1 v_1 u_2 v_2 \vdots u_M v_M p_1 p_2 \ldots p_8
Output
If it is possible for Takahashi to complete the puzzle, find the minimum number of operations needed to do so. Otherwise, print -1.
Sample Input 1
5 1 2 1 3 1 9 2 9 3 9 3 9 2 4 5 6 7 8
Sample Output 1
5
The following procedure completes the puzzle in five operations.
- Move Piece 2 from Vertex 9 to Vertex 1.
- Move Piece 3 from Vertex 2 to Vertex 9.
- Move Piece 2 from Vertex 1 to Vertex 2.
- Move Piece 1 from Vertex 3 to Vertex 1.
- Move Piece 3 from Vertex 9 to Vertex 3.
On the other hand, it is impossible to complete the puzzle in less than five operations. Thus, we should print 5.
Note that the given graph may not be connected.
Sample Input 2
5 1 2 1 3 1 9 2 9 3 9 1 2 3 4 5 6 7 8
Sample Output 2
0
The puzzle is already complete from the beginning. Thus, the minimum number of operations needed to complete the puzzle is 0.
Sample Input 3
12 8 5 9 6 4 5 4 1 2 5 8 9 2 1 3 6 8 7 6 5 7 4 2 3 1 2 3 4 5 6 8 7
Sample Output 3
-1
No sequence of operations can complete the puzzle, so we should print -1.
Sample Input 4
12 6 5 5 4 4 1 4 7 8 5 2 1 2 5 6 9 3 6 9 8 8 7 3 2 2 3 4 6 1 9 7 8
Sample Output 4
16
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 450 点
問題文
1 以上 N 以下の整数 x であって、以下の 3 つの条件のうちちょうど \mathbf{1} つだけを満たすものの個数を 998244353 で割ったあまりを求めてください。
- x は 3 の倍数である
- x の十進表記には
3が含まれる - x の十進表記にはちょうど 3 種類の数字が使われる
なお、整数の十進表記は先頭に不要な 0 をつけないものとします。
制約
- N は整数
- 1 \leq N < 10^{500}
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
45
出力例 1
19
1 以上 45 以下の整数であって、問題文中の条件のうちちょうど 1 つを満たすものは以下の 19 個です。
- 1 番目の条件だけを満たす整数は 6, 9, 12, 15, 18, 21, 24, 27, 42, 45 の 10 個
- 2 番目の条件だけを満たす整数は 13, 23, 31, 32, 34, 35, 37, 38, 43 の 9 個
- 3 番目の条件だけを満たす整数は存在しない
入力例 2
1013
出力例 2
424
該当する整数の例として以下が挙げられます。
- 1 番目の条件だけを満たす整数は 555 や 1011 など
- 2 番目の条件だけを満たす整数は 343 や 553 など
- 3 番目の条件だけを満たす整数は 1012 や 704 など
入力例 3
2
出力例 3
0
該当する整数は 0 個です。
入力例 4
314159265358979323846264338327950
出力例 4
658111391
Score : 450 points
Problem Statement
Find, modulo 998244353, the number of integers x with 1 \leq x \leq N that satisfy exactly one of the following three conditions.
- x is a multiple of 3.
- The decimal representation of x contains
3. - Exactly three different digits are used in the decimal representation of x.
Here, the decimal representation of an integer should not have unnecessary leading 0s.
Constraints
- N is an integer.
- 1 \leq N < 10^{500}
Input
The input is given from Standard Input in the following format:
N
Output
Output the answer.
Sample Input 1
45
Sample Output 1
19
Among the integers from 1 to 45, there are 19 integers satisfying exactly one of the conditions in the problem statement, as follows.
- There are 10 integers satisfying only the first condition: 6, 9, 12, 15, 18, 21, 24, 27, 42, 45.
- There are 9 integers satisfying only the second condition: 13, 23, 31, 32, 34, 35, 37, 38, 43.
- There are no integers satisfying only the third condition.
Sample Input 2
1013
Sample Output 2
424
Below are examples of applicable integers.
- Integers satisfying only the first condition include 555 and 1011.
- Integers satisfying only the second condition include 343 and 553.
- Integers satisfying only the third condition include 1012 and 704.
Sample Input 3
2
Sample Output 3
0
There are no applicable integers.
Sample Input 4
314159265358979323846264338327950
Sample Output 4
658111391
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 550 点
問題文
0, 1 からなる長さ N の文字列 S が与えられます。S の i 文字目を S_i とします。
Q 個のクエリを与えられた順に処理してください。
クエリは 3 個の整数の組 (c, L, R) で表されて、c の値によってクエリの種類が異なります。
- c=1 のとき : L \leq i \leq R を満たす整数 i について、S_i が
1ならば0に、0ならば1に変更する。 - c=2 のとき : S の L 文字目から R 文字目までを取り出して出来る文字列を T とする。T に含まれる連続する
1の長さの最大値を出力する。
制約
- 1 \leq N \leq 5 \times 10^5
- 1 \leq Q \leq 10^5
- S は長さ N の
0,1からなる文字列 - c \in \lbrace 1, 2 \rbrace
- 1 \leq L \leq R \leq N
- N, Q, c, L, R は全て整数
入力
入力は以下の形式で標準入力から与えられる。ここで \mathrm{query}_i は i 番目のクエリを意味する。
N Q
S
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q
各クエリは次の形式で与えられる。
c L R
出力
c=2 であるクエリの個数を k として、k 行出力せよ。
i 行目には i 番目の c=2 であるクエリに対する答えを出力せよ。
入力例 1
7 6 1101110 2 1 7 2 2 4 1 3 6 2 5 6 1 4 7 2 1 7
出力例 1
3 1 0 7
クエリを順に処理すると次のようになります。
- はじめ、S=
1101110です。 - 1 番目のクエリについて、T =
1101110です。T に含まれる連続する1の中で最も長いものは、T の 4 文字目から 6 文字目からなる111なので、答えは 3 になります。 - 2 番目のクエリについて、T =
101です。T に含まれる連続する1の中で最も長いものは、T の 1 文字目あるいは 3 文字目の1なので、答えは 1 になります。 - 3 番目のクエリについて、操作後の S は
1110000です。 - 4 番目のクエリについて、T =
00です。T に1は含まれないので答えは 0 になります。 - 5 番目のクエリについて、操作後の S は
1111111です。 - 6 番目のクエリについて、T =
1111111です。T に含まれる連続する1の中で最も長いものは、T の 1 文字目から 7 文字目からなる1111111なので、答えは 7 になります。
Score : 550 points
Problem Statement
You are given a string S of length N consisting of 0 and 1. Let S_i denote the i-th character of S.
Process Q queries in the order they are given.
Each query is represented by a tuple of three integers (c, L, R), where c represents the type of the query.
- When c=1: For each integer i such that L \leq i \leq R, if S_i is
1, change it to0; if it is0, change it to1. - When c=2: Let T be the string obtained by extracting the L-th through R-th characters of S. Print the maximum number of consecutive
1s in T.
Constraints
- 1 \leq N \leq 5 \times 10^5
- 1 \leq Q \leq 10^5
- S is a string of length N consisting of
0and1. - c \in \lbrace 1, 2 \rbrace
- 1 \leq L \leq R \leq N
- N, Q, c, L, and R are all integers.
Input
The input is given from Standard Input in the following format, where \mathrm{query}_i represents the i-th query:
N Q
S
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q
Each query is given in the following format:
c L R
Output
Let k be the number of queries with c=2. Print k lines.
The i-th line should contain the answer to the i-th query with c=2.
Sample Input 1
7 6 1101110 2 1 7 2 2 4 1 3 6 2 5 6 1 4 7 2 1 7
Sample Output 1
3 1 0 7
The queries are processed as follows.
- Initially, S=
1101110. - For the first query, T =
1101110. The longest sequence of consecutive1s in T is111from the 4-th character to 6-th character, so the answer is 3. - For the second query, T =
101. The longest sequence of consecutive1s in T is1at the 1-st or 3-rd character, so the answer is 1. - For the third query, the operation changes S to
1110000. - For the fourth query, T =
00. T does not contain1, so the answer is 0. - For the fifth query, the operation changes S to
1111111. - For the sixth query, T =
1111111. The longest sequence of consecutive1s in T is1111111from the 1-st to 7-th characters, so the answer is 7.