Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
正整数 D が与えられます。
直径が D の円の面積を求めて下さい。
制約
- 1\le D\le 100
- 入力される値は整数
入力
入力は以下の形式で標準入力から与えられる。
D
出力
答えを出力せよ。
真の解との絶対誤差または相対誤差が 10^{-6} 以下のとき正解と判定される。
入力例 1
2
出力例 1
3.141592653589793
直径が 2 の円の面積は 3.141592653589793\ldots です。
入力例 2
7
出力例 2
38.48451000647496
入力例 3
98
出力例 3
7542.9639612690935
Score : 100 points
Problem Statement
You are given a positive integer D.
Find the area of a circle with diameter D.
Constraints
- 1\le D\le 100
- The input value is an integer.
Input
The input is given from Standard Input in the following format:
D
Output
Output the answer.
Your answer is considered correct if the absolute or relative error from the true answer is at most 10^{-6}.
Sample Input 1
2
Sample Output 1
3.141592653589793
The area of a circle with diameter 2 is 3.141592653589793\ldots.
Sample Input 2
7
Sample Output 2
38.48451000647496
Sample Input 3
98
Sample Output 3
7542.9639612690935
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
H 行 W 列のブロックからなる長方形状のチョコレートがあります。
Q 個のクエリが与えられるので、順に処理したときの各クエリの答えを求めてください。各クエリは、以下のいずれかの形式です。
-
タイプ 1 : 整数 R が与えられる。下 R 行のチョコレートのブロックの個数を求め、それらを食べる。
-
タイプ 2 : 整数 C が与えられる。右 C 列のチョコレートのブロックの個数を求め、それらを食べる。
なお、クエリを順に処理したとき、各クエリを処理した後もチョコレートは長方形状であり、タイプ 1 のクエリを処理する直前の時点でチョコレートは R + 1 行以上存在し、タイプ 2 のクエリを処理する直前の時点でチョコレートは C + 1 列以上存在します。
制約
- 2 \leq H, W \leq 100
- 1 \leq Q \leq 100
- タイプ 1 のクエリについて、1 \leq R
- クエリを順に処理したとき、タイプ 1 のクエリを処理する直前にチョコレートは R + 1 行以上存在する
- タイプ 2 のクエリについて、1 \leq C
- クエリを順に処理したとき、タイプ 2 のクエリを処理する直前にチョコレートは C + 1 列以上存在する
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
H W Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
ただし、\text{query}_i は i 番目のクエリであり、以下のいずれかの形式で与えられる。
1 R
2 C
出力
Q 行出力せよ。 i (1 \leq i \leq Q) 行目には i 番目のクエリに対する答えを出力せよ。
入力例 1
7 9 5 2 4 1 3 2 1 2 1 1 3
出力例 1
28 15 4 4 9
はじめ、チョコレートは 7 行 9 列の長方形状です。
1 番目のクエリでは、右 4 列のチョコレートの個数は 28 個であるため 28 を出力します。チョコレートは 7 行 5 列となります。
2 番目のクエリでは、下 3 行のチョコレートの個数は 15 個であるため 15 を出力します。チョコレートは 4 行 5 列となります。
3 番目のクエリでは、右 1 列のチョコレートの個数は 4 個であるため 4 を出力します。チョコレートは 4 行 4 列となります。
4 番目のクエリでは、右 1 列のチョコレートの個数は 4 個であるため 4 を出力します。チョコレートは 4 行 3 列となります。
5 番目のクエリでは、下 3 行のチョコレートの個数は 9 個であるため 9 を出力します。チョコレートは 1 行 3 列となります。
Score : 200 points
Problem Statement
There is a rectangular chocolate consisting of H rows and W columns of blocks.
You are given Q queries; process them in order and find the answer to each query. Each query is in one of the following formats:
-
Type 1: An integer R is given. Find the number of chocolate blocks in the bottom R rows, then eat them.
-
Type 2: An integer C is given. Find the number of chocolate blocks in the rightmost C columns, then eat them.
When the queries are processed in order, the chocolate remains rectangular after each query is processed, and it has at least R + 1 rows immediately before processing a type 1 query and has at least C + 1 columns immediately before processing a type 2 query.
Constraints
- 2 \leq H, W \leq 100
- 1 \leq Q \leq 100
- For type 1 queries, 1 \leq R.
- When the queries are processed in order, the chocolate has at least R + 1 rows immediately before processing a type 1 query.
- For type 2 queries, 1 \leq C.
- When the queries are processed in order, the chocolate has at least C + 1 columns immediately before processing a type 2 query.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
H W Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
Here, \text{query}_i is the i-th query, given in one of the following formats:
1 R
2 C
Output
Output Q lines. The i-th line (1 \leq i \leq Q) should contain the answer to the i-th query.
Sample Input 1
7 9 5 2 4 1 3 2 1 2 1 1 3
Sample Output 1
28 15 4 4 9
Initially, the chocolate is a rectangle with 7 rows and 9 columns.
For the first query, the number of chocolate blocks in the rightmost 4 columns is 28, so output 28. The chocolate becomes 7 rows and 5 columns.
For the second query, the number of chocolate blocks in the bottom 3 rows is 15, so output 15. The chocolate becomes 4 rows and 5 columns.
For the third query, the number of chocolate blocks in the rightmost 1 column is 4, so output 4. The chocolate becomes 4 rows and 4 columns.
For the fourth query, the number of chocolate blocks in the rightmost 1 column is 4, so output 4. The chocolate becomes 4 rows and 3 columns.
For the fifth query, the number of chocolate blocks in the bottom 3 rows is 9, so output 9. The chocolate becomes 1 row and 3 columns.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
英小文字からなる長さ N の文字列 S が与えられます。
整数の組 (i, j) であって、以下の条件をすべて満たすものの個数を求めてください。
- 1 \leq i \leq j \leq N
- S_i = S_j
- L \leq j - i \leq R
制約
- 2 \leq N \leq 5 \times 10^5
- 1 \leq L \leq R \leq N - 1
- N, L, R は整数
- S は長さ N の英小文字からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
N L R S
出力
答えを出力せよ。
入力例 1
6 2 4 aabcba
出力例 1
2
問題文中の条件をすべて満たす整数の組は (i, j) = (2, 6), (3, 5) の 2 つです。
入力例 2
9 3 6 aaaaaaaaa
出力例 2
18
入力例 3
10 2 6 aabbccaabb
出力例 3
6
Score : 300 points
Problem Statement
You are given a string S of length N consisting of lowercase English letters.
Find the number of pairs of integers (i, j) satisfying all of the following conditions:
- 1 \leq i \leq j \leq N
- S_i = S_j
- L \leq j - i \leq R
Constraints
- 2 \leq N \leq 5 \times 10^5
- 1 \leq L \leq R \leq N - 1
- N, L, R are integers.
- S is a string of length N consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
N L R S
Output
Output the answer.
Sample Input 1
6 2 4 aabcba
Sample Output 1
2
The pairs of integers satisfying all the conditions in the problem statement are (i, j) = (2, 6), (3, 5), for a total of two pairs.
Sample Input 2
9 3 6 aaaaaaaaa
Sample Output 2
18
Sample Input 3
10 2 6 aabbccaabb
Sample Output 3
6
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 425 点
問題文
2 次元座標平面があり、座標が (x, y) である格子点は \max(|x|, |y|) が偶数のとき黒、奇数のとき白で塗られています。
L \leq x \leq R かつ D \leq y \leq U を満たす整数の組 (x, y) のうち、座標 (x, y) が黒く塗られているものの個数を求めてください。
制約
- -10^6 \leq L \leq R \leq 10^6
- -10^6 \leq D \leq U \leq 10^6
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
L R D U
出力
答えを出力せよ。
入力例 1
-4 3 1 3
出力例 1
10

上の図のように、求める答えは 10 となります。
入力例 2
-14 14 -14 14
出力例 2
449
Score : 425 points
Problem Statement
There is a two-dimensional coordinate plane. A lattice point with coordinates (x, y) is painted black if \max(|x|, |y|) is even, and white if it is odd.
Among the pairs of integers (x, y) satisfying L \leq x \leq R and D \leq y \leq U, find the number of those for which the point (x, y) is painted black.
Constraints
- -10^6 \leq L \leq R \leq 10^6
- -10^6 \leq D \leq U \leq 10^6
- All input values are integers.
Input
The input is given from Standard Input in the following format:
L R D U
Output
Output the answer.
Sample Input 1
-4 3 1 3
Sample Output 1
10

As shown in the figure above, the answer is 10.
Sample Input 2
-14 14 -14 14
Sample Output 2
449
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 475 点
問題文
整数 N,M と各要素が 1 以上 M 以下である長さ N の整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。
この整数列 A に対して以下の操作を 10^{100} 回行います。
- 1 以上 M 以下の整数のうち A における出現回数が最も少ないものを v とする。ただし、そのような v が複数存在する場合はその中で値が最小のものとする。そして、A の末尾に v を追加する。
Q 個のクエリが与えられます。 i 番目のクエリでは整数 X_i が与えられるので、操作を 10^{100} 回行った後の A_{X_i} の値を求めてください。
制約
- 1\le N,M\le 5\times 10^5
- 1\le A_i \le M
- 1\le Q\le 2\times 10^5
- 1\le X_i \le 10^{18}
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \ldots A_N Q X_1 X_2 \vdots X_Q
出力
Q 行出力せよ。
i 行目には、i 番目のクエリに対する答えを出力せよ。
入力例 1
3 3 1 1 2 8 1 2 3 4 5 6 7 8
出力例 1
1 1 2 3 2 3 1 2
はじめ A=(1,1,2) です。各操作で A は以下のように変化します。
- 1 回目:A に含まれる 1,2,3 の個数はそれぞれ 2,1,0 であるため、v=3 とする。v を A の末尾に追加し、A=(1,1,2,3) となる。
- 2 回目:A に含まれる 1,2,3 の個数はそれぞれ 2,1,1 であるため、v=2 とする。v を A の末尾に追加し、A=(1,1,2,3,2) となる。
- 3 回目:A に含まれる 1,2,3 の個数はそれぞれ 2,2,1 であるため、v=3 とする。v を A の末尾に追加し、A=(1,1,2,3,2,3) となる。
- \vdots
操作を 10^{100} 回行った後の A は A=(1,1,2,3,2,3,1,2,\ldots) となります。
入力例 2
7 30 20 26 3 14 4 4 9 10 31 9 21 23 97 99 30 79 57 3
出力例 2
30 2 18 21 7 9 29 19 27 3
Score : 475 points
Problem Statement
You are given integers N, M and an integer sequence A=(A_1,A_2,\ldots,A_N) of length N where each element is between 1 and M, inclusive.
The following operation is performed 10^{100} times on this integer sequence A:
- Let v be the integer between 1 and M, inclusive, with the fewest occurrences in A. If there are multiple such v, take the smallest among them. Then, append v to the end of A.
You are given Q queries. The i-th query gives an integer X_i, so find the value of A_{X_i} after performing the operation 10^{100} times.
Constraints
- 1\le N,M\le 5\times 10^5
- 1\le A_i \le M
- 1\le Q\le 2\times 10^5
- 1\le X_i \le 10^{18}
- 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 Q X_1 X_2 \vdots X_Q
Output
Output Q lines.
The i-th line should contain the answer to the i-th query.
Sample Input 1
3 3 1 1 2 8 1 2 3 4 5 6 7 8
Sample Output 1
1 1 2 3 2 3 1 2
Initially, A=(1,1,2). With each operation, A changes as follows:
- First operation: The counts of 1, 2, 3 in A are 2, 1, 0 respectively, so v=3. Append v to the end of A, giving A=(1,1,2,3).
- Second operation: The counts of 1, 2, 3 in A are 2, 1, 1 respectively, so v=2. Append v to the end of A, giving A=(1,1,2,3,2).
- Third operation: The counts of 1, 2, 3 in A are 2, 2, 1 respectively, so v=3. Append v to the end of A, giving A=(1,1,2,3,2,3).
- \vdots
After performing the operation 10^{100} times, A becomes A=(1,1,2,3,2,3,1,2,\ldots).
Sample Input 2
7 30 20 26 3 14 4 4 9 10 31 9 21 23 97 99 30 79 57 3
Sample Output 2
30 2 18 21 7 9 29 19 27 3
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
H 行 W 列のグリッドがあります。上から r 行目、左から c 列目のマスをマス (r,c) と呼びます。各マスは黒か白で塗られており、k=1,2,\ldots,N に対しマス (R_k,C_k) は黒で、それ以外の HW-N マスは白で塗られています。
このグリッドの中の縦 h 行、横 w 列の長方形領域であって、含まれるマスが全て白で塗られているようなものがいくつあるか求めてください。
より厳密には、以下の条件を全て満たす整数の組 (r_0, c_0) の個数を求めてください。
- 1\le r_0 \le H-h+1
- 1\le c_0 \le W-w+1
- 0\le i< h,\ 0\le j< w を満たす全ての整数の組 (i,j) に対し、マス (r_0+i,c_0+j) は白で塗られている。
制約
- 1\le h\le H\le 10^9
- 1\le w\le W\le 10^9
- 0\le N\le 2\times 10^5
- 1\le R_k\le H
- 1\le C_k\le W
- (R_{k_1},C_{k_1}) \neq (R_{k_2},C_{k_2}) (k_1 \neq k_2)
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
H W h w N R_1 C_1 R_2 C_2 \vdots R_N C_N
出力
答えを出力せよ。
入力例 1
3 4 2 2 3 1 3 2 4 3 1
出力例 1
2
下図の赤で囲まれた 2 つの長方形領域が条件を全て満たします。

入力例 2
4 4 3 2 2 2 2 3 4
出力例 2
0
条件を全て満たす長方形領域は存在しません。
入力例 3
449 449 3 14 0
出力例 3
194892
入力例 4
31 9 5 7 10 14 8 8 4 18 8 12 1 8 5 9 6 18 1 14 7 5 6 26 7
出力例 4
12
Score : 500 points
Problem Statement
There is a grid with H rows and W columns. The cell at the r-th row from the top and c-th column from the left is called cell (r,c). Each cell is painted black or white: cell (R_k,C_k) is black for k=1,2,\ldots,N, and the remaining HW-N cells are white.
Find the number of rectangular regions in this grid with h rows and w columns such that all cells contained in them are painted white.
More formally, find the number of pairs of integers (r_0, c_0) satisfying all of the following conditions:
- 1\le r_0 \le H-h+1
- 1\le c_0 \le W-w+1
- Cell (r_0+i,c_0+j) is painted white for all pairs of integers (i,j) satisfying 0\le i< h,\ 0\le j< w.
Constraints
- 1\le h\le H\le 10^9
- 1\le w\le W\le 10^9
- 0\le N\le 2\times 10^5
- 1\le R_k\le H
- 1\le C_k\le W
- (R_{k_1},C_{k_1}) \neq (R_{k_2},C_{k_2}) (k_1 \neq k_2)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
H W h w N R_1 C_1 R_2 C_2 \vdots R_N C_N
Output
Output the answer.
Sample Input 1
3 4 2 2 3 1 3 2 4 3 1
Sample Output 1
2
The two rectangular regions enclosed in red in the figure below satisfy all the conditions.

Sample Input 2
4 4 3 2 2 2 2 3 4
Sample Output 2
0
No rectangular region satisfies all the conditions.
Sample Input 3
449 449 3 14 0
Sample Output 3
194892
Sample Input 4
31 9 5 7 10 14 8 8 4 18 8 12 1 8 5 9 6 18 1 14 7 5 6 26 7
Sample Output 4
12
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 600 点
問題文
正整数 N, M が与えられます。
正整数 d に対し、d 桁の repunit を整数 \displaystyle\sum_{i = 0}^{d - 1} 10^i として定義します。
相異なるとは限らない 1 桁以上 M 桁以下の repunit N 個の和として表すことのできる整数の個数を 998244353 で割った余りを求めてください。
制約
- 1 \leq N \leq 10^5
- 1 \leq M \leq 10^9
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M
出力
答えを出力せよ。
入力例 1
2 3
出力例 1
6
1 桁以上 3 桁以下の repunit は 1, 11, 111 の 3 つです。これら 2 つの和として表すことのできる整数は 2, 12, 22, 112, 122, 222 の 6 つです。
入力例 2
10 10
出力例 2
92378
入力例 3
12345 123456789
出力例 3
133394021
Score : 600 points
Problem Statement
You are given positive integers N, M.
For a positive integer d, define the repunit with d digits as the integer \displaystyle\sum_{i = 0}^{d - 1} 10^i.
Find the number, modulo 998244353, of integers that can be expressed as the sum of (not necessarily distinct) N repunits, each with at least 1 digit and at most M digits.
Constraints
- 1 \leq N \leq 10^5
- 1 \leq M \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
Output
Output the answer.
Sample Input 1
2 3
Sample Output 1
6
We have 3 repunits with at least 1 digit and at most 3 digits: 1, 11, 111. As the sum of 2 of them, we can express 6 integers: 2, 12, 22, 112, 122, 222.
Sample Input 2
10 10
Sample Output 2
92378
Sample Input 3
12345 123456789
Sample Output 3
133394021