Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
4 種類の牡蠣 1,2,3,4 があります。 このうちちょうど 1 種類の牡蠣については、食べるとお腹を壊してしまいます。 それ以外の牡蠣については、食べてもお腹を壊しません。
高橋君が牡蠣 1,2 を食べ、青木君が牡蠣 1,3 を食べました。
二人がこれによってお腹を壊したかどうかの情報が二つの文字列 S_1,S_2 によって与えられます。
具体的には、S_1= sick
であるとき高橋君がお腹を壊したことを、S_1= fine
であるとき高橋君がお腹を壊さなかったことを表します。
同様に、S_2= sick
であるとき青木君がお腹を壊したことを、S_2= fine
であるとき青木君がお腹を壊さなかったことを表します。
与えられた情報をもとに、どの種類の牡蠣を食べるとお腹を壊すか判定してください。
制約
- S_1, S_2 はそれぞれ
sick
またはfine
入力
入力は以下の形式で標準入力から与えられる。
S_1 S_2
出力
食べるとお腹を壊す牡蠣の種類の番号を出力せよ。
入力例 1
sick fine
出力例 1
2
牡蠣 1,2 を食べた高橋君はお腹を壊し、牡蠣 1,3 を食べた青木君はお腹を壊さなかったので、牡蠣 2 を食べるとお腹を壊すことがわかります。
入力例 2
fine fine
出力例 2
4
牡蠣 1,2 を食べた高橋君も牡蠣 1,3 を食べた青木君もお腹を壊さなかったので、残る牡蠣 4 を食べるとお腹を壊すことがわかります。
Score : 100 points
Problem Statement
There are four types of oysters, labeled 1, 2, 3, and 4. Exactly one of these types causes stomach trouble if eaten. The other types do not cause stomach trouble when eaten.
Takahashi ate oysters 1 and 2, and Aoki ate oysters 1 and 3. The information on whether each person got sick is given as two strings S_1 and S_2. Specifically, S_1 = sick
means Takahashi got sick, and S_1 = fine
means Takahashi did not get sick. Likewise, S_2 = sick
means Aoki got sick, and S_2 = fine
means Aoki did not get sick.
Based on the given information, find which type of oyster causes stomach trouble.
Constraints
- Each of S_1 and S_2 is
sick
orfine
.
Input
The input is given from Standard Input in the following format:
S_1 S_2
Output
Print the label of the oyster that causes stomach trouble if eaten.
Sample Input 1
sick fine
Sample Output 1
2
Takahashi (who ate oysters 1 and 2) got sick, and Aoki (who ate oysters 1 and 3) did not get sick, so it can be concluded that oyster 2 causes stomach trouble.
Sample Input 2
fine fine
Sample Output 2
4
Neither Takahashi (who ate oysters 1 and 2) nor Aoki (who ate oysters 1 and 3) got sick, so it can be concluded that oyster 4 causes stomach trouble.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 150 点
問題文
(1,2,3,4,5) を並び替えた整数列 A=(A_1,A_2,A_3,A_4,A_5) が与えられます。
A の隣り合う 2 つの項を入れ替える操作を ちょうど 1 回 行うことで A を昇順にすることができるか判定してください。
制約
- A は (1,2,3,4,5) を並び替えてできる長さ 5 の整数列
入力
入力は以下の形式で標準入力から与えられる。
A_1 A_2 A_3 A_4 A_5
出力
ちょうど 1 回の操作で A を昇順にすることができるならば Yes
を、できないならば No
を出力せよ。
入力例 1
1 2 4 3 5
出力例 1
Yes
A_3 と A_4 を入れ替えることで A=(1,2,3,4,5) となり、 A を昇順に並び替えることができます。したがって、 Yes
を出力してください。
入力例 2
5 3 2 4 1
出力例 2
No
どのような操作をしても A を昇順に並び替えることはできません。
入力例 3
1 2 3 4 5
出力例 3
No
ちょうど 1 回操作をする必要があります。
入力例 4
2 1 3 4 5
出力例 4
Yes
Score : 150 points
Problem Statement
You are given an integer sequence A=(A_1,A_2,A_3,A_4,A_5) obtained by permuting (1,2,3,4,5).
Determine whether A can be sorted in ascending order by performing exactly one operation of swapping two adjacent elements in A.
Constraints
- A is an integer sequence of length 5 obtained by permuting (1,2,3,4,5).
Input
The input is given from Standard Input in the following format:
A_1 A_2 A_3 A_4 A_5
Output
If A can be sorted in ascending order by exactly one operation, print Yes
; otherwise, print No
.
Sample Input 1
1 2 4 3 5
Sample Output 1
Yes
By swapping A_3 and A_4, A becomes (1,2,3,4,5), so it can be sorted in ascending order. Therefore, print Yes
.
Sample Input 2
5 3 2 4 1
Sample Output 2
No
No matter what operation is performed, it is impossible to sort A in ascending order.
Sample Input 3
1 2 3 4 5
Sample Output 3
No
You must perform exactly one operation.
Sample Input 4
2 1 3 4 5
Sample Output 4
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
英小文字のみからなる N 個の文字列 S_1,S_2,\ldots,S_N が与えられます。
1 以上 N 以下の 相異なる 整数 i,j であって、S_i と S_j をこの順に連結した文字列が回文となるようなものが存在するか判定してください。
ただし、長さ M の文字列 T が回文であるとは、任意の 1\leq i\leq M について、T の i 文字目と (M+1-i) 文字目が一致していることをいいます。
制約
- 2\leq N\leq 100
- 1\leq \lvert S_i\rvert \leq 50
- N は整数
- S_i は英小文字のみからなる文字列
- S_i はすべて異なる。
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
問題文の条件をみたす i,j が存在するならば Yes
を、そうでないならば No
を出力せよ。
入力例 1
5 ab ccef da a fe
出力例 1
Yes
(i,j)=(1,4) とすると、S_1=ab
と S_4=a
をこの順に連結した文字列は aba
となり、
これは回文であるため条件をみたしています。
よって、Yes
を出力します。
また、(i,j)=(5,2) としても、S_5=fe
と S_2=ccef
をこの順に連結した文字列は feccef
となり、やはり条件をみたしています。
入力例 2
3 a b aba
出力例 2
No
S_1, S_2, S_3 のうち、どの相異なる 2 つの文字列を繋げても回文となりません。
よって、No
を出力します。
問題文における i,j は相異なる必要があることに注意してください。
入力例 3
2 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
出力例 3
Yes
Score : 200 points
Problem Statement
You are given N strings S_1,S_2,\ldots,S_N consisting of lowercase English letters.
Determine if there are distinct integers i and j between 1 and N, inclusive, such that the concatenation of S_i and S_j in this order is a palindrome.
A string T of length M is a palindrome if and only if the i-th character and the (M+1-i)-th character of T are the same for every 1\leq i\leq M.
Constraints
- 2\leq N\leq 100
- 1\leq \lvert S_i\rvert \leq 50
- N is an integer.
- S_i is a string consisting of lowercase English letters.
- All S_i are distinct.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
If there are i and j that satisfy the condition in the problem statement, print Yes
; otherwise, print No
.
Sample Input 1
5 ab ccef da a fe
Sample Output 1
Yes
If we take (i,j)=(1,4), the concatenation of S_1=ab
and S_4=a
in this order is aba
, which is a palindrome, satisfying the condition.
Thus, print Yes
.
Here, we can also take (i,j)=(5,2), for which the concatenation of S_5=fe
and S_2=ccef
in this order is feccef
, satisfying the condition.
Sample Input 2
3 a b aba
Sample Output 2
No
No two distinct strings among S_1, S_2, and S_3 form a palindrome when concatenated.
Thus, print No
.
Note that the i and j in the statement must be distinct.
Sample Input 3
2 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
N 種類の元素があり、元素には 1, 2, \ldots, N の番号が付けられています。
元素どうしは合成させることができ、元素 i と元素 j を合成すると i \geq j のとき元素 A_{i, j} に、i < j のとき元素 A_{j, i} に変化します。
元素 1 に対して元素 1, 2, \ldots, N をこの順に合成したとき、最終的に得られる元素を求めてください。
制約
- 1 \leq N \leq 100
- 1 \leq A_{i, j} \leq N
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_{1, 1} A_{2, 1} A_{2, 2} \vdots A_{N, 1} A_{N, 2} \ldots A_{N, N}
出力
最終的に得られる元素の番号を出力せよ。
入力例 1
4 3 2 4 3 1 2 2 1 2 4
出力例 1
2
-
元素 1 と元素 1 を合成すると、元素 3 が得られます。
-
元素 3 と元素 2 を合成すると、元素 1 が得られます。
-
元素 1 と元素 3 を合成すると、元素 3 が得られます。
-
元素 3 と元素 4 を合成すると、元素 2 が得られます。
したがって、出力するべき値は 2 です。
入力例 2
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
出力例 2
5
入力例 3
6 2 1 5 1 6 3 2 6 1 4 2 1 1 1 6 5 6 1 2 2 5
出力例 3
5
Score : 200 points
Problem Statement
There are N types of elements numbered 1, 2, \ldots, N.
Elements can be combined with each other. When elements i and j are combined, they transform into element A_{i, j} if i \geq j, and into element A_{j, i} if i < j.
Starting with element 1, combine it with elements 1, 2, \ldots, N in this order. Find the final element obtained.
Constraints
- 1 \leq N \leq 100
- 1 \leq A_{i, j} \leq N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_{1, 1} A_{2, 1} A_{2, 2} \vdots A_{N, 1} A_{N, 2} \ldots A_{N, N}
Output
Print the number representing the final element obtained.
Sample Input 1
4 3 2 4 3 1 2 2 1 2 4
Sample Output 1
2
-
Combining element 1 with element 1 results in element 3.
-
Combining element 3 with element 2 results in element 1.
-
Combining element 1 with element 3 results in element 3.
-
Combining element 3 with element 4 results in element 2.
Therefore, the value to be printed is 2.
Sample Input 2
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
Sample Output 2
5
Sample Input 3
6 2 1 5 1 6 3 2 6 1 4 2 1 1 1 6 5 6 1 2 2 5
Sample Output 3
5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
H_1 行 W_1 列の行列 A と、H_2 行 W_2 列の行列 B が与えられます。
- 1 \leq i \leq H_1 かつ 1 \leq j \leq W_1 を満たす整数の組 (i, j) について、行列 A の i 行目 j 列目の要素は A_{i, j} です。
- 1 \leq i \leq H_2 かつ 1 \leq j \leq W_2 を満たす整数の組 (i, j) について、行列 B の i 行目 j 列目の要素は B_{i, j} です。
行列 A に対して、下記の 2 つの操作のうちどちらかを行うことを、好きなだけ( 0 回でも良い)繰り返すことができます。
- A の行を任意に 1 つ選んで削除する。
- A の列を任意に 1 つ選んで削除する。
行列 A を行列 B に一致させることができるかどうかを判定して下さい。
制約
- 1 \leq H_2 \leq H_1 \leq 10
- 1 \leq W_2 \leq W_1 \leq 10
- 1 \leq A_{i, j} \leq 10^9
- 1 \leq B_{i, j} \leq 10^9
- 入力中の値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
H_1 W_1 A_{1, 1} A_{1, 2} \ldots A_{1, W_1} A_{2, 1} A_{2, 2} \ldots A_{2, W_1} \vdots A_{H_1, 1} A_{H_1, 2} \ldots A_{H_1, W_1} H_2 W_2 B_{1, 1} B_{1, 2} \ldots B_{1, W_2} B_{2, 1} B_{2, 2} \ldots B_{2, W_2} \vdots B_{H_2, 1} B_{H_2, 2} \ldots B_{H_2, W_2}
出力
行列 A を行列 B に一致させることができる場合は Yes
を、
一致させることができない場合は No
を出力せよ。
ジャッジは英小文字と英大文字を厳密に区別することに注意せよ。
入力例 1
4 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2 3 6 8 9 16 18 19
出力例 1
Yes
初期状態の行列 A から 2 列目を削除すると、行列 A は
1 3 4 5 6 8 9 10 11 13 14 15 16 18 19 20
となります。そこからさらに 3 行目を削除すると、行列 A は
1 3 4 5 6 8 9 10 16 18 19 20
となります。そこからさらに 1 行目を削除すると、行列 A は
6 8 9 10 16 18 19 20
となります。そこからさらに 4 列目を削除すると、行列 A は
6 8 9 16 18 19
となります。これは行列 B と一致します。
操作の繰り返しによって行列 A を行列 B に一致させることができるので Yes
を出力します。
入力例 2
3 3 1 1 1 1 1 1 1 1 1 1 1 2
出力例 2
No
どのように操作を行っても、 行列 A を行列 B に一致させることはできません。
よって、No
を出力します。
Score : 300 points
Problem Statement
You are given a matrix A with H_1 rows and W_1 columns, and a matrix B with H_2 rows and W_2 columns.
- For all integer pairs (i, j) such that 1 \leq i \leq H_1 and 1 \leq j \leq W_1, the element at the i-th row and j-th column of matrix A is A_{i, j}.
- For all integer pairs (i, j) such that 1 \leq i \leq H_2 and 1 \leq j \leq W_2, the element at the i-th row and j-th column of matrix B is B_{i, j}.
You may perform the following operations on the matrix A any number of (possibly 0) times in any order:
- Choose an arbitrary row of A and remove it.
- Choose an arbitrary column of A and remove it.
Determine if it is possible to make the matrix A equal the matrix B.
Constraints
- 1 \leq H_2 \leq H_1 \leq 10
- 1 \leq W_2 \leq W_1 \leq 10
- 1 \leq A_{i, j} \leq 10^9
- 1 \leq B_{i, j} \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
H_1 W_1 A_{1, 1} A_{1, 2} \ldots A_{1, W_1} A_{2, 1} A_{2, 2} \ldots A_{2, W_1} \vdots A_{H_1, 1} A_{H_1, 2} \ldots A_{H_1, W_1} H_2 W_2 B_{1, 1} B_{1, 2} \ldots B_{1, W_2} B_{2, 1} B_{2, 2} \ldots B_{2, W_2} \vdots B_{H_2, 1} B_{H_2, 2} \ldots B_{H_2, W_2}
Output
Print Yes
if it is possible to make the matrix A equal the matrix B;
print No
otherwise.
Note that the judge is case-sensitive.
Sample Input 1
4 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2 3 6 8 9 16 18 19
Sample Output 1
Yes
Removing the 2-nd column from the initial A results in:
1 3 4 5 6 8 9 10 11 13 14 15 16 18 19 20
Then, removing the 3-rd row from A results in:
1 3 4 5 6 8 9 10 16 18 19 20
Then, removing the 1-st row from A results in:
6 8 9 10 16 18 19 20
Then, removing the 4-th column from A results in:
6 8 9 16 18 19
Now the matrix equals the matrix B.
Thus, we can make the matrix A equal the matrix B by repeating the operations, so Yes
should be printed.
Sample Input 2
3 3 1 1 1 1 1 1 1 1 1 1 1 2
Sample Output 2
No
Regardless of how we perform the operations, we cannot make the matrix A equal the matrix B,
so No
should be printed.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
縦 H マス, 横 W マスのグリッドがあります。上から i 行目、左から j 列目のマスを (i, j) と呼びます。
はじめ、グリッド上には、ある 縦横 2 マス以上 の部分長方形の内部にあるマスにクッキーが 1 枚ずつ置かれていて、それ以外のマスにはクッキーが置かれていません。
形式的に説明すると、以下の条件を全て満たす 4 つの整数の組 (a,b,c,d) がただ 1 つ存在します。
- 1 \leq a \lt b \leq H
- 1 \leq c \lt d \leq W
- グリッド上のマスのうち、a \leq i \leq b, c \leq j \leq d を満たす全てのマス (i, j) にはクッキーが 1 枚ずつ置かれていて、それ以外のマスにはクッキーが置かれていない。
ところが、すぬけ君がグリッド上のクッキーのどれか 1 枚を取って食べてしまいました。
すぬけ君がクッキーを取ったマスは、クッキーが置かれていない状態に変わります。
すぬけ君がクッキーを食べた後のグリッドの状態が入力として与えられます。
マス (i, j) の状態は文字 S_{i,j} として与えられて、#
はクッキーが置かれているマスを, .
はクッキーが置かれていないマスを意味します。
すぬけ君が食べたクッキーが元々置かれていたマスを答えてください。(答えは一意に定まります。)
制約
- 2 \leq H, W \leq 500
- S_{i,j} は
#
または.
入力
入力は以下の形式で標準入力から与えられる。
H W S_{1,1}S_{1,2}\dotsS_{1,W} S_{2,1}S_{2,2}\dotsS_{2,W} \vdots S_{H,1}S_{H,2}\dotsS_{H,W}
出力
すぬけ君が食べたクッキーが元々置かれていたマスを (i, j) とする。i, j をこの順に空白区切りで出力せよ。
入力例 1
5 6 ...... ..#.#. ..###. ..###. ......
出力例 1
2 4
はじめ、クッキーは (2, 3) を左上、(4, 5) を右下とする部分長方形の内部にあるマスに置かれていて、すぬけ君は (2, 4) にあるクッキーを食べたことがわかります。よって (2, 4) を出力します。
入力例 2
3 2 #. ## ##
出力例 2
1 2
はじめ、クッキーは (1, 1) を左上、(3, 2) を右下とする部分長方形の内部にあるマスに置かれていて、すぬけ君は (1, 2) にあるクッキーを食べたことがわかります。
入力例 3
6 6 ..#### ..##.# ..#### ..#### ..#### ......
出力例 3
2 5
Score : 300 points
Problem Statement
There is a grid with H rows and W columns. Let (i, j) denote the square at the i-th row from the top and the j-th column from the left.
Initially, there was one cookie on each square inside a rectangle whose height and width were at least 2 squares long, and no cookie on the other squares.
Formally, there was exactly one quadruple of integers (a,b,c,d) that satisfied all of the following conditions.
- 1 \leq a \lt b \leq H
- 1 \leq c \lt d \leq W
- There was one cookie on each square (i, j) such that a \leq i \leq b, c \leq j \leq d, and no cookie on the other squares.
However, Snuke took and ate one of the cookies on the grid.
The square that contained that cookie is now empty.
As the input, you are given the state of the grid after Snuke ate the cookie.
The state of the square (i, j) is given as the character S_{i,j}, where #
means a square with a cookie, and .
means a square without one.
Find the square that contained the cookie eaten by Snuke. (The answer is uniquely determined.)
Constraints
- 2 \leq H, W \leq 500
- S_{i,j} is
#
or.
.
Input
The input is given from Standard Input in the following format:
H W S_{1,1}S_{1,2}\dotsS_{1,W} S_{2,1}S_{2,2}\dotsS_{2,W} \vdots S_{H,1}S_{H,2}\dotsS_{H,W}
Output
Let (i, j) the square contained the cookie eaten by Snuke. Print i and j in this order, separated by a space.
Sample Input 1
5 6 ...... ..#.#. ..###. ..###. ......
Sample Output 1
2 4
Initially, cookies were on the squares inside the rectangle with (2, 3) as the top-left corner and (4, 5) as the bottom-right corner, and Snuke ate the cookie on (2, 4). Thus, you should print (2, 4).
Sample Input 2
3 2 #. ## ##
Sample Output 2
1 2
Initially, cookies were placed on the squares inside the rectangle with (1, 1) as the top-left corner and (3, 2) as the bottom-right corner, and Snuke ate the cookie at (1, 2).
Sample Input 3
6 6 ..#### ..##.# ..#### ..#### ..#### ......
Sample Output 3
2 5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
あるオンラインゲームがあり、
N 人のプレイヤーが登録しています。
サービス開始日から 10^{100} 日を迎えた今日、
開発者である高橋君がログイン履歴を調べたところ、
i 番目のプレイヤーはサービス開始日を 1 日目として、
A_i 日目から B_i 日間連続でログインし、
それ以外の日はログインしていなかったことが判明しました。
すなわち、i 番目のプレイヤーはサービス開始日から、A_i , A_i+1 , \ldots , A_i+B_i-1 日目に、
かつそれらの日にのみログインしていたことが分かりました。
1\leq k\leq N をみたす各整数 k について、
サービス開始日から今日までの間で、ちょうど k 人がログインしていた日数を答えてください。
制約
- 1 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq B_i \leq 10^9
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N A_1 B_1 A_2 B_2 : A_N B_N
出力
次のように空白区切りで N 個の整数を出力せよ。
D_1 D_2 \cdots D_N
ただし、 D_i はちょうど i 人がゲームにログインしていた日数を表す。
入力例 1
3 1 2 2 3 3 1
出力例 1
2 2 0
1 番目のプレイヤーは 1 日目と 2 日目に、 2 番目のプレイヤーは 2 日目と 3 日目と 4 日目に、 3 番目のプレイヤーは 3 日目だけにログインしています。 よって、1, 4 日目には 1 人が、2, 3 日目には 2 人がログインしており、 それ以外の日は誰もログインしていない事が分かります。 答えはちょうど 1 人がログインした日数が 2 日、 ちょうど 2 人がログインした日数が 2 日、 ちょうど 3 人がログインした日数が 0 日となります。
入力例 2
2 1000000000 1000000000 1000000000 1000000000
出力例 2
0 1000000000
2 人以上のプレイヤーがちょうど同じ期間にログインしていることもあり得ます。
Score : 400 points
Problem Statement
There is an online game with N registered players.
Today, which is the 10^{100}-th day since its launch, the developer Takahashi examined the users' login history. It turned out that the i-th player logged in for B_i consecutive days from Day A_i, where Day 1 is the launch day, and did not log in for the other days.
In other words, the i-th player logged in on Day A_i, A_i+1, \ldots, A_i+B_i-1, and only on those days.
For each integer k such that 1\leq k\leq N, find the number of days on which exactly k players logged in.
Constraints
- 1 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq B_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 B_1 A_2 B_2 : A_N B_N
Output
Print N integers with spaces in between, as follows:
D_1 D_2 \cdots D_N
Here, D_i denotes the number of days on which exactly k players logged in.
Sample Input 1
3 1 2 2 3 3 1
Sample Output 1
2 2 0
The first player logged in on Day 1, 2, the second player logged in on Day 2, 3, 4, and the third player logged in on Day 3 only.
Thus, we can see that Day 1, 4 had 1 player logged in, Day 2, 3 had 2 players logged in, and the other days had no players logged in.
The answer is: there were 2 days with exactly 1 player logged in, 2 days with exactly 2 players logged in, and 0 days with exactly 3 players logged in.
Sample Input 2
2 1000000000 1000000000 1000000000 1000000000
Sample Output 2
0 1000000000
There may be two or more players who logged in during the same period.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
空の列 A があります。クエリが Q 個与えられるので、与えられた順番に処理してください。
クエリは次の 3 種類のいずれかです。
1 x
: A の最後尾に x を追加する。2
: A の最初の要素を出力する。その後、その要素を削除する。このクエリが与えられるとき、A は空でないことが保証される。3
: A を昇順にソートする。
制約
- 1 \leq Q \leq 2 \times 10^5
- 0 \leq x \leq 10^9
- クエリ
2
が与えられるとき、A は空でない。 - 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
Q \mathrm{query} 1 \mathrm{query} 2 \vdots \mathrm{query} Q
i 番目のクエリ \mathrm{query} i では、まずクエリの種類 c_i( 1, 2, 3 のいずれか)が与えられる。 c_i = 1 の場合はさらに整数 x が追加で与えられる。
すなわち、各クエリは以下に示す 3 つの形式のいずれかである。
1 x
2
3
出力
c_i = 2 を満たすクエリの回数を q として q 行出力せよ。
j (1 \leq j \leq q) 行目では j 番目のそのようなクエリに対する答えを出力せよ。
入力例 1
8 1 4 1 3 1 2 1 1 3 2 1 0 2
出力例 1
1 2
入力例 1 において、 i 番目のクエリを処理した後の A の状態を i 行目に示すと以下のようになります。
- (4)
- (4, 3)
- (4, 3, 2)
- (4, 3, 2, 1)
- (1, 2, 3, 4)
- (2, 3, 4)
- (2, 3, 4, 0)
- (3, 4, 0)
入力例 2
9 1 5 1 5 1 3 2 3 2 1 6 3 2
出力例 2
5 3 5
入力例 2 において、 i 番目のクエリを処理した後の A の状態を i 行目に示すと以下のようになります。
- (5)
- (5, 5)
- (5, 5, 3)
- (5, 3)
- (3, 5)
- (5)
- (5, 6)
- (5, 6)
- (6)
Score : 500 points
Problem Statement
We have an empty sequence A. You will be given Q queries, which should be processed in the order they are given. Each query is of one of the three kinds below:
1 x
: Append x to the end of A.2
: Print the element at the beginning of A. Then, delete that element. It is guaranteed that A will not empty when this query is given.3
: Sort A in ascending order.
Constraints
- 1 \leq Q \leq 2 \times 10^5
- 0 \leq x \leq 10^9
- A will not be empty when a query
2
is given. - All values in input are integers.
Input
Input is given from Standard Input in the following format:
Q \mathrm{query} 1 \mathrm{query} 2 \vdots \mathrm{query} Q
The i-th query, \mathrm{query} i, begins with the kind of query c_i (1, 2, or 3). If c_i = 1, the line additionally has an integer x.
In other words, each query is in one of the three formats below.
1 x
2
3
Output
Print q lines, where q is the number of queries with c_i = 2.
The j-th line (1 \leq j \leq q) should contain the response for the j-th such query.
Sample Input 1
8 1 4 1 3 1 2 1 1 3 2 1 0 2
Sample Output 1
1 2
The i-th line below shows the contents of A after the i-th query is processed in Sample Input 1.
- (4)
- (4, 3)
- (4, 3, 2)
- (4, 3, 2, 1)
- (1, 2, 3, 4)
- (2, 3, 4)
- (2, 3, 4, 0)
- (3, 4, 0)
Sample Input 2
9 1 5 1 5 1 3 2 3 2 1 6 3 2
Sample Output 2
5 3 5
The i-th line below shows the contents of A after the i-th query is processed in Sample Input 2.
- (5)
- (5, 5)
- (5, 5, 3)
- (5, 3)
- (3, 5)
- (5)
- (5, 6)
- (5, 6)
- (6)
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 550 点
問題文
ビル 1, ビル 2, \ldots, ビル N の N 棟がこの順で東西に一列に並んでおり、ビル 1 が最も西に、ビル N が最も東に建っています。ビル i\ (1\leq i\leq N) の高さは H_i です。
整数の組 (i,j)\ (1\leq i\lt j\leq N) に対して、以下の条件を満たすとき ビル i からビル j を見ることができます。
- ビル i とビル j の間にビル j より高いビルが存在しない。すなわち、H_k\gt H_j を満たす整数 k\ (i\lt k\lt j) が存在しない。
Q 個の質問に答えてください。i 番目の質問では整数の組 (l_i,r_i)\ (l_i\lt r_i) が与えられるので、ビル r_i より東にあるビル(ビル r_i+1, ビル r_i+2,\ldots,ビル N )のうちビル l_i とビル r_i の両方から見ることができるものの個数を答えてください。
制約
- 2\leq N\leq 2\times 10^5
- 1\leq Q\leq 2\times 10^5
- 1\leq H_i\leq N
- H_i\neq H_j\ (i\neq j)
- 1\leq l_i\lt r_i\leq N
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N Q H_1 H_2 \ldots H_N l_1 r_1 l_2 r_2 \vdots l_Q r_Q
出力
Q 行出力せよ。i\ (1\leq i\leq Q) 行目には i 番目の質問に対する答えを出力せよ。
入力例 1
5 3 2 1 4 3 5 1 2 3 5 1 4
出力例 1
2 0 1
- 1 つ目の質問について、ビル 2 より東にあるビルのうち ビル 1 とビル 2 の両方から見ることができるものはビル 3,5 の 2 つです。
- 2 つ目の質問について、ビル 5 より東にあるビルは存在しません。
- 3 つ目の質問について、ビル 4 より東にあるビルのうち、ビル 1,4 の両方から見ることができるビルはビル 5 の 1 つです。
入力例 2
10 10 2 1 5 3 4 6 9 8 7 10 3 9 2 5 4 8 5 6 3 8 2 10 7 8 6 7 8 10 4 10
出力例 2
1 3 1 2 1 0 1 1 0 0
Score : 550 points
Problem Statement
There are N buildings, building 1, building 2, \ldots, building N, arranged in this order in a straight line from west to east. Building 1 is the westernmost, and building N is the easternmost. The height of building i\ (1\leq i\leq N) is H_i.
For a pair of integers (i,j)\ (1\leq i\lt j\leq N), building j can be seen from building i if the following condition is satisfied.
- There is no building taller than building j between buildings i and j. In other words, there is no integer k\ (i\lt k\lt j) such that H_k > H_j.
You are given Q queries. In the i-th query, given a pair of integers (l_i,r_i)\ (l_i\lt r_i), find the number of buildings to the east of building r_i (that is, buildings r_i + 1, r_i + 2, \ldots, N) that can be seen from both buildings l_i and r_i.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq H_i \leq N
- H_i\neq H_j\ (i\neq j)
- 1 \leq l_i < r_i \leq N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N Q H_1 H_2 \ldots H_N l_1 r_1 l_2 r_2 \vdots l_Q r_Q
Output
Print Q lines. The i-th line (1 \leq i \leq Q) should contain the answer to the i-th query.
Sample Input 1
5 3 2 1 4 3 5 1 2 3 5 1 4
Sample Output 1
2 0 1
- For the first query, among the buildings to the east of building 2, buildings 3 and 5 can be seen from both buildings 1 and 2, so the answer is 2.
- For the second query, there are no buildings to the east of building 5.
- For the third query, among the buildings to the east of building 4, building 5 can be seen from both buildings 1 and 4, so the answer is 1.
Sample Input 2
10 10 2 1 5 3 4 6 9 8 7 10 3 9 2 5 4 8 5 6 3 8 2 10 7 8 6 7 8 10 4 10
Sample Output 2
1 3 1 2 1 0 1 1 0 0