Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
AtCoder 市では市長選挙が行われています。候補者は高橋氏と青木氏です。
2 人のどちらかに投じられた有効票は N 票あり、現在開票が行われています。なお、 N は奇数です。
現在の開票作業の途中経過は高橋氏に T 票、青木氏に A 票です。
現時点で勝敗が確定しているかを判定してください。
制約
- 1 \leq N \leq 99
- N は奇数
- 0 \leq T,A \leq N
- T+A \leq N
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N T A
出力
現時点で勝敗が確定しているならば Yes
、そうでなければ No
と出力せよ。
入力例 1
7 4 2
出力例 1
Yes
残りの 1 票が青木氏に入っても、高橋氏は勝利します。高橋氏の勝利が確定しているため、Yes
と出力します。
入力例 2
99 12 48
出力例 2
No
現時点では青木氏が多く票を獲得していますが、高橋氏が残りの 39 票を獲得すると高橋氏が勝利します。よって、No
と出力します。
入力例 3
1 0 0
出力例 3
No
Score : 100 points
Problem Statement
A mayoral election is being held in AtCoder City. The candidates are Takahashi and Aoki.
There are N valid votes cast for either of the two candidates, and the counting is currently underway. Here, N is an odd number.
The current vote count is T votes for Takahashi and A votes for Aoki.
Determine if the outcome of the election is already decided at this point.
Constraints
- 1 \leq N \leq 99
- N is an odd number.
- 0 \leq T, A \leq N
- T + A \leq N
- All input values are integers.
Input
The input is given from standard input in the following format:
N T A
Output
Print Yes
if the outcome of the election is already decided, and No
otherwise.
Sample Input 1
7 4 2
Sample Output 1
Yes
Even if the remaining one vote goes to Aoki, Takahashi will still win. That is, his victory is decided, so print Yes
.
Sample Input 2
99 12 48
Sample Output 2
No
Although Aoki currently has more votes, Takahashi would win if he receives the remaining 39 votes. Therefore, print No
.
Sample Input 3
1 0 0
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 150 点
問題文
AtCoder 王国の住民は A 時になるとたこ焼きへの愛を叫ぶことになっています。
AtCoder 王国に住む高橋君は毎日 B 時に就寝し C 時に起床します。高橋君は、起きているときはたこ焼きへの愛を叫ぶことができ、寝ているときは叫ぶことができません。高橋君が毎日たこ焼きへの愛を叫ぶことができているか判定してください。ただし、一日は 24 時間であり、高橋君が寝ている時間は 24 時間未満であるとします。
制約
- 0\leq A,B,C\lt 24
- A,B,C は相異なる
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B C
出力
高橋君が毎日たこ焼きへの愛を叫ぶことができているならば Yes
を、そうでないならば No
を出力せよ。
入力例 1
21 8 14
出力例 1
Yes
高橋君は毎日 8 時に就寝し 14 時に起床します。21 時には起きているため、高橋君は毎日たこ焼きへの愛を叫ぶことができます。よって Yes
を出力します。
入力例 2
0 21 7
出力例 2
No
高橋君は毎日 21 時に就寝し 7 時に起床します。0 時には起きていないため、高橋君は毎日たこ焼きへの愛を叫ぶことができません。よって No
を出力します。
入力例 3
10 7 17
出力例 3
No
Score : 150 points
Problem Statement
In the Kingdom of AtCoder, residents are required to shout their love for takoyaki at A o'clock every day.
Takahashi, who lives in the Kingdom of AtCoder, goes to bed at B o'clock and wakes up at C o'clock every day (in the 24-hour clock). He can shout his love for takoyaki when he is awake, but cannot when he is asleep. Determine whether he can shout his love for takoyaki every day. Here, a day has 24 hours, and his sleeping time is less than 24 hours.
Constraints
- 0\leq A,B,C\lt 24
- A, B, and C are pairwise different.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B C
Output
Print Yes
if Takahashi can shout his love for takoyaki every day, and No
otherwise.
Sample Input 1
21 8 14
Sample Output 1
Yes
Takahashi goes to bed at 8 o'clock and wakes up at 14 o'clock every day. He is awake at 21 o'clock, so he can shout his love for takoyaki every day. Therefore, print Yes
.
Sample Input 2
0 21 7
Sample Output 2
No
Takahashi goes to bed at 21 o'clock and wakes up at 7 o'clock every day. He is not awake at 0 o'clock, so he cannot shout his love for takoyaki every day. Therefore, print No
.
Sample Input 3
10 7 17
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
この問題は 1 つの入力ファイルに複数のテストケースが含まれる問題です。
はじめに整数 T が与えられます。T 個のテストケースについて次の問題を解いてください。
- N 個の正整数 A_1, A_2, ..., A_N があります。このうち奇数は何個ありますか?
制約
- 1 \leq T \leq 100
- 1 \leq N \leq 100
- 1 \leq A_i \leq 10^9
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。ここで \text{test}_i は i 番目のテストケースを意味する。
T \text{test}_1 \text{test}_2 \vdots \text{test}_T
各テストケースは以下の形式で与えられる。
N A_1 A_2 \dots A_N
出力
T 行出力せよ。i 行目には i 番目のテストケースに対する答えを出力せよ。
入力例 1
4 3 1 2 3 2 20 23 10 6 10 4 1 5 9 8 6 5 1 1 1000000000
出力例 1
2 1 5 0
この入力は 4 個のテストケースが含まれています。
入力の 2 行目と 3 行目が 1 番目のテストケースに対応する入力で、N = 3, A_1 = 1, A_2 = 2, A_3 = 3 になります。
A_1, A_2, A_3 のうち奇数は全部で 2 個なので 1 行目に 2 を出力します。
Score : 200 points
Problem Statement
In this problem, an input file contains multiple test cases.
You are first given an integer T. Solve the following problem for T test cases.
- We have N positive integers A_1, A_2, ..., A_N. How many of them are odd?
Constraints
- 1 \leq T \leq 100
- 1 \leq N \leq 100
- 1 \leq A_i \leq 10^9
- All values in the input are integers.
Input
The input is given from Standard Input in the following format, where \text{test}_i represents the i-th test case:
T \text{test}_1 \text{test}_2 \vdots \text{test}_T
Each test case is in the following format:
N A_1 A_2 \dots A_N
Output
Print T lines. The i-th line should contain the answer for the i-th test case.
Sample Input 1
4 3 1 2 3 2 20 23 10 6 10 4 1 5 9 8 6 5 1 1 1000000000
Sample Output 1
2 1 5 0
This input contains four test cases.
The second and third lines correspond to the first test case, where N = 3, A_1 = 1, A_2 = 2, A_3 = 3.
We have two odd numbers in A_1, A_2, and A_3, so the first line should contain 2.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
キーエンスでは良いことも悪いこともありのままに報告するという文化があります。
そこで、報告内容が元の文章のありのままであるかを確認したいです。
英小文字のみからなる文字列 S, T が与えられます。
S と T が等しいならば 0 を、そうでないならば異なっている文字のうち先頭のものが何文字目かを出力してください。
ただし、S,T の一方にのみ i 文字目が存在するときも、i 文字目は異なっているとみなすものとします。
より厳密には、S と T が等しくないならば次の条件のうちいずれかをみたす最小の整数 i を出力してください。
- 1\leq i\leq |S| かつ 1\leq i\leq |T| かつ S_i\neq T_i
- |S|< i\leq |T|
- |T|< i\leq |S|
ただし、|S|,|T| でそれぞれ S,T の長さを、S_i,T_i でそれぞれ S,T の i 文字目を表します。
制約
- S,T は英小文字のみからなる長さ 1 以上 100 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
S と T が等しいならば 0 を、そうでないならば異なっている文字のうち先頭のものが何文字目かを出力せよ。
入力例 1
abcde abedc
出力例 1
3
S=abcde
, T=abedc
です。
S と T は 1,2 文字目は等しく、3 文字目が異なるため、 3 を出力します。
入力例 2
abcde abcdefg
出力例 2
6
S=abcde
, T=abcdefg
です。
S と T は 5 文字目まで等しく、T にのみ 6 文字目が存在するため、6 を出力します。
入力例 3
keyence keyence
出力例 3
0
S と T は等しいため、 0 を出力します。
Score : 200 points
Problem Statement
KEYENCE has a culture of reporting things as they are, whether good or bad.
So we want to check whether the reported content is exactly the same as the original text.
You are given two strings S and T, consisting of lowercase English letters.
If S and T are equal, print 0; otherwise, print the position of the first character where they differ.
Here, if the i-th character exists in only one of S and T, consider that the i-th characters are different.
More precisely, if S and T are not equal, print the smallest integer i satisfying one of the following conditions:
- 1\leq i\leq |S|, 1\leq i\leq |T|, and S_i\neq T_i.
- |S| < i \leq |T|.
- |T| < i \leq |S|.
Here, |S| and |T| denote the lengths of S and T, respectively, and S_i and T_i denote the i-th characters of S and T, respectively.
Constraints
- S and T are strings of length between 1 and 100, inclusive, consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
S T
Output
If S and T are equal, print 0; otherwise, print the position of the first character where they differ.
Sample Input 1
abcde abedc
Sample Output 1
3
We have S= abcde
and T= abedc
.
S and T have the same first and second characters, but differ at the third character, so print 3.
Sample Input 2
abcde abcdefg
Sample Output 2
6
We have S= abcde
and T= abcdefg
.
S and T are equal up to the fifth character, but only T has a sixth character, so print 6.
Sample Input 3
keyence keyence
Sample Output 3
0
S and T are equal, so print 0.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 頂点 M 辺の単純無向グラフが与えられます。頂点には 1 から N の番号がついており、i 番目の辺は頂点 A_i と頂点 B_i を結んでいます。 このグラフから 0 本以上のいくつかの辺を削除してグラフが閉路を持たないようにするとき、削除する辺の本数の最小値を求めてください。
単純無向グラフとは
単純無向グラフとは、自己ループや多重辺を含まず、辺に向きの無いグラフのことをいいます。
閉路とは
単純無向グラフが閉路を持つとは、i \neq j ならば v_i \neq v_j を満たす長さ 3 以上の頂点列 (v_0, v_1, \ldots, v_{n-1}) であって、各 0 \leq i < n に対し v_i と v_{i+1 \bmod n} の間に辺が存在するものがあることをいいます。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq M \leq 2 \times 10^5
- 1 \leq A_i, B_i \leq N
- 与えられるグラフは単純
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 A_2 B_2 \vdots A_M B_M
出力
答えを出力せよ。
入力例 1
6 7 1 2 1 3 2 3 4 2 6 5 4 6 4 5
出力例 1
2
頂点 1 と頂点 2 を結ぶ辺・頂点 4 と頂点 5 を結ぶ辺の 2 本を削除するなどの方法でグラフが閉路を持たないようにすることができます。
1 本以下の辺の削除でグラフが閉路を持たないようにすることはできないので、2 を出力します。
入力例 2
4 2 1 2 3 4
出力例 2
0
入力例 3
5 3 1 2 1 3 2 3
出力例 3
1
Score : 300 points
Problem Statement
You are given a simple undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the i-th edge connects vertex A_i and vertex B_i. Let us delete zero or more edges to remove cycles from the graph. Find the minimum number of edges that must be deleted for this purpose.
What is a simple undirected graph?
A simple undirected graph is a graph without self-loops or multi-edges whose edges have no direction.
What is a cycle?
A cycle in a simple undirected graph is a sequence of vertices (v_0, v_1, \ldots, v_{n-1}) of length at least 3 satisfying v_i \neq v_j if i \neq j such that for each 0 \leq i < n, there is an edge between v_i and v_{i+1 \bmod n}.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq M \leq 2 \times 10^5
- 1 \leq A_i, B_i \leq N
- The given graph is simple.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 B_1 A_2 B_2 \vdots A_M B_M
Output
Print the answer.
Sample Input 1
6 7 1 2 1 3 2 3 4 2 6 5 4 6 4 5
Sample Output 1
2
One way to remove cycles from the graph is to delete the two edges between vertex 1 and vertex 2 and between vertex 4 and vertex 5.
There is no way to remove cycles from the graph by deleting one or fewer edges, so you should print 2.
Sample Input 2
4 2 1 2 3 4
Sample Output 2
0
Sample Input 3
5 3 1 2 1 3 2 3
Sample Output 3
1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
ボールがいくつか刺さった棒が N 本あり、各ボールには英小文字が 1 個書かれています。
i = 1, 2, \ldots, N について、i 番目の棒に刺さった各ボールの英小文字は、文字列 S_i によって表されます。 具体的には、i 番目の棒には文字列 S_i の長さ |S_i| に等しい個数のボールが刺さっており、 刺さっているボールの英小文字を、棒のある端から順に並べたものは文字列 S_i と等しいです。
2 つの棒は、一方の棒に刺さっているボールの英小文字をどちらかの端から並べた列と、もう一方の棒に刺さっているボールの英小文字をどちらかの端から並べた列が一致するとき、同じ棒とみなされます。 より形式的には、1 以上 N 以下の整数 i, j について、i 本目の棒と j 本目の棒は、S_i が S_j と一致するか、S_i が S_j を前後反転したものと一致するとき、かつそのときに限り、同じとみなされます。
N 本の棒の中に、何種類の異なる棒があるかを出力してください。
制約
- N は整数
- 2 \leq N \leq 2 \times 10^5
- S_i は英小文字のみからなる文字列
- |S_i| \geq 1
- \sum_{i = 1}^N |S_i| \leq 2 \times 10^5
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
答えを出力せよ。
入力例 1
6 a abc de cba de abc
出力例 1
3
- S_2 =
abc
が S_4 =cba
を前後反転したものと一致するため、2 番目の棒と 4 番目の棒は同じとみなされます。 - S_2 =
abc
が S_6 =abc
と一致するため、2 番目の棒と 6 番目の棒は同じとみなされます。 - S_3 =
de
が S_5 =de
と一致するため、3 番目の棒と 5 番目の棒は同じとみなされます。
よって、6 本の棒の中に、1 本目の棒、2 本目の棒( 4, 6 本目の棒と同じ)、3 本目の棒( 5 本目の棒と同じ)の 3 種類の異なる棒があります。
Score : 300 points
Problem Statement
There are N sticks with several balls stuck onto them. Each ball has a lowercase English letter written on it.
For each i = 1, 2, \ldots, N, the letters written on the balls stuck onto the i-th stick are represented by a string S_i. Specifically, the number of balls stuck onto the i-th stick is the length |S_i| of the string S_i, and S_i is the sequence of letters on the balls starting from one end of the stick.
Two sticks are considered the same when the sequence of letters on the balls starting from one end of one stick is equal to the sequence of letters starting from one end of the other stick. More formally, for integers i and j between 1 and N, inclusive, the i-th and j-th sticks are considered the same if and only if S_i equals S_j or its reversal.
Print the number of different sticks among the N sticks.
Constraints
- N is an integer.
- 2 \leq N \leq 2 \times 10^5
- S_i is a string consisting of lowercase English letters.
- |S_i| \geq 1
- \sum_{i = 1}^N |S_i| \leq 2 \times 10^5
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print the answer.
Sample Input 1
6 a abc de cba de abc
Sample Output 1
3
- S_2 =
abc
equals the reversal of S_4 =cba
, so the second and fourth sticks are considered the same. - S_2 =
abc
equals S_6 =abc
, so the second and sixth sticks are considered the same. - S_3 =
de
equals S_5 =de
, so the third and fifth sticks are considered the same.
Therefore, there are three different sticks among the six: the first, second (same as the fourth and sixth), and third (same as the fifth).
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
N 行 N 列のグリッドがあり、各マスは空きマスか障害物のあるマスのいずれかです。グリッドの上から i 行目、左から j 列目のマスを (i, j) と表記します。
また、2 人のプレイヤーがグリッド上の相異なる空きマス上におり、各マスの情報は N 個の長さ N の文字列 S_1, S_2, \ldots, S_N として以下の形式で与えられます。
-
S_i の j 文字目が
P
であるとき、(i, j) は空きマスであり、プレイヤーがいる -
S_i の j 文字目が
.
であるとき、(i, j) は空きマスであり、プレイヤーがいない -
S_i の j 文字目が
#
であるとき、(i, j) は障害物のあるマスである
以下の操作を繰り返し 2 人のプレイヤーを同じマスに集めるために必要な操作回数の最小値を求めてください。ただし、操作の繰り返しにより 2 人のプレイヤーを同じマスに集めることができない場合には -1
を出力してください。
- 上下左右のいずれかの方向を決める。そして各プレイヤーはともにその方向に隣接するマスへの移動を試みる。各プレイヤーは移動先のマスが存在し、かつ空きマスであるならば移動し、そうでないならば移動しない。
制約
- N は 2 以上 60 以下の整数
- S_i は長さ N の
P
,.
,#
からなる文字列 - S_i の j 文字目が
P
であるような組 (i, j) の個数はちょうど 2 つ
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
答えを出力せよ。
入力例 1
5 ....# #..#. .P... ..P.. ....#
出力例 1
3
はじめに (3, 2) にいるプレイヤーをプレイヤー 1、(4, 3) にいるプレイヤーをプレイヤー 2 とします。
例えば以下のようにすることで、3 回の操作で 2 人のプレイヤーが同じマスに集まります。
-
左を選択する。プレイヤー 1 は (3, 1) に移動し、プレイヤー 2 は (4, 2) に移動する。
-
上を選択する。プレイヤー 1 は移動せず、プレイヤー 2 は (3, 2) に移動する。
-
左を選択する。プレイヤー 1 は移動せず、プレイヤー 2 は (3, 1) に移動する。
入力例 2
2 P# #P
出力例 2
-1
入力例 3
10 .......... .......... .......... .......... ....P..... .....P.... .......... .......... .......... ..........
出力例 3
10
Score: 400 points
Problem Statement
There is an N \times N grid, where each cell is either empty or contains an obstacle. Let (i, j) denote the cell at the i-th row from the top and the j-th column from the left.
There are also two players on distinct empty cells of the grid. The information about each cell is given as N strings S_1, S_2, \ldots, S_N of length N, in the following format:
-
If the j-th character of S_i is
P
, then (i, j) is an empty cell with a player on it. -
If the j-th character of S_i is
.
, then (i, j) is an empty cell without a player. -
If the j-th character of S_i is
#
, then (i, j) contains an obstacle.
Find the minimum number of moves required to bring the two players to the same cell by repeating the following operation. If it is impossible to bring the two players to the same cell by repeating the operation, print -1
.
- Choose one of the four directions: up, down, left, or right. Then, each player attempts to move to the adjacent cell in that direction. Each player moves if the destination cell exists and is empty, and does not move otherwise.
Constraints
- N is an integer between 2 and 60, inclusive.
- S_i is a string of length N consisting of
P
,.
, and#
. - There are exactly two pairs (i, j) where the j-th character of S_i is
P
.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print the answer.
Sample Input 1
5 ....# #..#. .P... ..P.. ....#
Sample Output 1
3
Let us call the player starting at (3, 2) Player 1 and the player starting at (4, 3) Player 2.
For example, doing the following brings the two players to the same cell in three moves:
-
Choose left. Player 1 moves to (3, 1), and Player 2 moves to (4, 2).
-
Choose up. Player 1 does not move, and Player 2 moves to (3, 2).
-
Choose left. Player 1 does not move, and Player 2 moves to (3, 1).
Sample Input 2
2 P# #P
Sample Output 2
-1
Sample Input 3
10 .......... .......... .......... .......... ....P..... .....P.... .......... .......... .......... ..........
Sample Output 3
10
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
英小文字からなる N 個の文字列 S_1, S_2, \ldots, S_N 、および、英小文字からなる文字列 T が与えられます。
1 以上 N 以下の 2 つの整数からなる組 (i, j) は N^2 個ありますが、そのうち下記の条件を満たすものの個数を出力してください。
- S_i と S_j をこの順に連結して得られる文字列は、T を(連続とは限らない)部分列として含む。
制約
- N は整数
- 1 \leq N \leq 5 \times 10^5
- S_i および T は英小文字からなる長さ 1 以上 5 \times 10^5 以下の文字列
- S_1, S_2, \ldots, S_N の長さの総和は 5 \times 10^5 以下
入力
入力は以下の形式で標準入力から与えられる。
N T S_1 S_2 \vdots S_N
出力
答えを出力せよ。
入力例 1
3 bac abba bcb aaca
出力例 1
3
問題文中の条件を満たす組 (i, j) は、下記に示す 3 個の組 (1, 2), (1, 3), (2, 3) です。
- (i, j) = (1, 2) について、S_1 と S_2 をこの順に連結して得られる文字列
abbabcb
はbac
を部分列として含みます。 - (i, j) = (1, 3) について、S_1 と S_3 をこの順に連結して得られる文字列
abbaaaca
はbac
を部分列として含みます。 - (i, j) = (2, 3) について、S_2 と S_3 をこの順に連結して得られる文字列
bcbaaca
はbac
を部分列として含みます。
入力例 2
5 xx x x x x x
出力例 2
25
入力例 3
1 y x
出力例 3
0
入力例 4
10 ms mkgn m hlms vmsle mxsm nnzdhi umsavxlb ffnsybomr yvmm naouel
出力例 4
68
Score : 500 points
Problem Statement
You are given N strings S_1, S_2, \ldots, S_N consisting of lowercase English letters, and a string T consisting of lowercase English letters.
There are N^2 pairs (i, j) of integers between 1 and N, inclusive. Print the number of pairs among them that satisfy the following condition.
- The concatenation of S_i and S_j in this order contains T as a (not necessarily contiguous) subsequence.
Constraints
- N is an integer.
- 1 \leq N \leq 5 \times 10^5
- S_i and T are strings of length 1 to 5 \times 10^5, inclusive, consisting of lowercase English letters.
- The total length of S_1, S_2, \ldots, S_N is at most 5 \times 10^5.
Input
The input is given from Standard Input in the following format:
N T S_1 S_2 \vdots S_N
Output
Print the answer.
Sample Input 1
3 bac abba bcb aaca
Sample Output 1
3
The pairs (i, j) that satisfy the condition in the problem statement are (1, 2), (1, 3), (2, 3), as seen below.
- For (i, j) = (1, 2), the concatenation
abbabcb
of S_1 and S_2 in this order containsbac
as a subsequence. - For (i, j) = (1, 3), the concatenation
abbaaaca
of S_1 and S_3 in this order containsbac
as a subsequence. - For (i, j) = (2, 3), the concatenation
bcbaaca
of S_2 and S_3 in this order containsbac
as a subsequence.
Sample Input 2
5 xx x x x x x
Sample Output 2
25
Sample Input 3
1 y x
Sample Output 3
0
Sample Input 4
10 ms mkgn m hlms vmsle mxsm nnzdhi umsavxlb ffnsybomr yvmm naouel
Sample Output 4
68
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
縦 N 行、横 M 列の行列があり、はじめ全ての成分は 0 です。
以下のいずれかの形式で表されるクエリを Q 個処理してください。
1 l r x
: l 列目、l+1 列目、\ldots、r 列目の成分全てに x を足す。2 i x
: i 行目の成分全てを x で置き換える。3 i j
: (i, j) 成分を出力する。
制約
- 1 \leq N, M, Q \leq 2 \times 10^5
1 l r x
の形式のクエリについて、1 \leq l \leq r \leq M かつ 1 \leq x \leq 10^92 i x
の形式のクエリについて、1 \leq i \leq N かつ 1 \leq x \leq 10^93 i j
の形式にクエリについて、1 \leq i \leq N かつ 1 \leq j \leq M3 i j
の形式のクエリが一個以上与えられる- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M Q \mathrm{Query}_1 \vdots \mathrm{Query}_Q
i 番目に与えられるクエリを表す \mathrm{Query}_i は以下のいずれかの形式である。
1 l r x
2 i x
3 i j
出力
3 i j
の形式の各クエリについて、答えを一行に出力せよ。
入力例 1
3 3 9 1 1 2 1 3 2 2 2 3 2 3 3 3 3 3 1 1 2 3 3 3 3 2 3 2 3 3 1 2
出力例 1
1 2 2 5 3 4
行列は次のように変化します。
\begin{pmatrix} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \\ \end{pmatrix} \rightarrow \begin{pmatrix} 1 & 1 & 0 \\ 1 & 1 & 0 \\ 1 & 1 & 0 \\ \end{pmatrix} \rightarrow \begin{pmatrix} 1 & 1 & 0 \\ 1 & 1 & 0 \\ 2 & 2 & 2 \\ \end{pmatrix} \rightarrow \begin{pmatrix} 1 & 4 & 3 \\ 1 & 4 & 3 \\ 2 & 5 & 5 \\ \end{pmatrix}
入力例 2
1 1 10 1 1 1 1000000000 1 1 1 1000000000 1 1 1 1000000000 1 1 1 1000000000 1 1 1 1000000000 1 1 1 1000000000 1 1 1 1000000000 1 1 1 1000000000 1 1 1 1000000000 3 1 1
出力例 2
9000000000
入力例 3
10 10 10 1 1 8 5 2 2 6 3 2 1 3 4 7 1 5 9 7 3 3 2 3 2 8 2 8 10 3 8 8 3 1 10
出力例 3
6 5 5 13 10 0
Score : 500 points
Problem Statement
We have an N \times M matrix, whose elements are initially all 0.
Process Q given queries. Each query is in one of the following formats.
1 l r x
: Add x to every element in the l-th, (l+1)-th, \ldots, and r-th column.2 i x
: Replace every element in the i-th row with x.3 i j
: Print the (i, j)-th element.
Constraints
- 1 \leq N, M, Q \leq 2 \times 10^5
- Every query is in one of the formats listed in the Problem Statement.
- For each query in the format
1 l r x
, 1 \leq l \leq r \leq M and 1 \leq x \leq 10^9. - For each query in the format
2 i x
, 1 \leq i \leq N and 1 \leq x \leq 10^9. - For each query in the format
3 i j
, 1 \leq i \leq N and 1 \leq j \leq M. - At least one query in the format
3 i j
is given. - All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M Q \mathrm{Query}_1 \vdots \mathrm{Query}_Q
\mathrm{Query}_i, which denotes the i-th query, is in one of the following formats:
1 l r x
2 i x
3 i j
Output
For each query in the format 3 i j
, print a single line containing the answer.
Sample Input 1
3 3 9 1 1 2 1 3 2 2 2 3 2 3 3 3 3 3 1 1 2 3 3 3 3 2 3 2 3 3 1 2
Sample Output 1
1 2 2 5 3 4
The matrix transitions as follows.
\begin{pmatrix} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \\ \end{pmatrix} \rightarrow \begin{pmatrix} 1 & 1 & 0 \\ 1 & 1 & 0 \\ 1 & 1 & 0 \\ \end{pmatrix} \rightarrow \begin{pmatrix} 1 & 1 & 0 \\ 1 & 1 & 0 \\ 2 & 2 & 2 \\ \end{pmatrix} \rightarrow \begin{pmatrix} 1 & 4 & 3 \\ 1 & 4 & 3 \\ 2 & 5 & 5 \\ \end{pmatrix}
Sample Input 2
1 1 10 1 1 1 1000000000 1 1 1 1000000000 1 1 1 1000000000 1 1 1 1000000000 1 1 1 1000000000 1 1 1 1000000000 1 1 1 1000000000 1 1 1 1000000000 1 1 1 1000000000 3 1 1
Sample Output 2
9000000000
Sample Input 3
10 10 10 1 1 8 5 2 2 6 3 2 1 3 4 7 1 5 9 7 3 3 2 3 2 8 2 8 10 3 8 8 3 1 10
Sample Output 3
6 5 5 13 10 0