Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
長さ N の非負整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。
A の異なる 2 要素の和として表せる値の中に偶数が存在するか判定し、存在する場合その最大値を求めてください。
制約
- 2\leq N \leq 2\times 10^5
- 0\leq A_i\leq 10^9
- A の要素は相異なる
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
A の異なる 2 要素の和として表せる値の中に偶数が存在しない場合、-1 を出力せよ。
偶数が存在する場合、その最大値を出力せよ。
入力例 1
3 2 3 4
出力例 1
6
A の異なる 2 要素の和として表せる値は 5,6,7 です。この中に偶数は存在し、その最大値は 6 です。
入力例 2
2 1 0
出力例 2
-1
A の異なる 2 要素の和として表せる値は 1 です。この中に偶数は存在しないので、 -1 を出力してください。
Score : 300 points
Problem Statement
You are given a sequence A=(A_1,A_2,\ldots,A_N) of length N consisting of non-negative integers.
Determine if there is an even number represented as the sum of two different elements of A. If it exists, find the maximum such number.
Constraints
- 2\leq N \leq 2\times 10^5
- 0\leq A_i\leq 10^9
- The elements of A are distinct.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print -1 if there is no even number represented as the sum of two different elements of A.
If such an even number exists, print the maximum such number.
Sample Input 1
3 2 3 4
Sample Output 1
6
The values represented as the sum of two distinct elements of A are 5, 6, and 7. We have an even number here, and the maximum is 6.
Sample Input 2
2 1 0
Sample Output 2
-1
The value represented as the sum of two distinct elements of A is 1. We have no even number here, so -1 should be printed.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 人の生徒からなるクラスがあり、i\,(1 \leq i \leq N) 番目の生徒の身長は A_i です。
j=1,2,\ldots,Q について、以下の質問に答えてください。
- N 人のうち、身長が x_j 以上の生徒は何人か?
制約
- 1 \leq N,Q \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq x_j \leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N Q A_1 A_2 \ldots A_N x_1 x_2 \vdots x_Q
出力
Q 行出力せよ。
j\,(1 \leq j \leq Q) 行目には身長が x_j 以上の生徒の数を出力せよ。
入力例 1
3 1 100 160 130 120
出力例 1
2
身長が 120 以上の生徒は 2 番目の生徒と 3 番目の生徒です。
入力例 2
5 5 1 2 3 4 5 6 5 4 3 2
出力例 2
0 1 2 3 4
入力例 3
5 5 804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422
出力例 3
5 3 5 5 5
Score : 300 points
Problem Statement
There is a class with N students. The height of the i-th student (1 \leq i \leq N) is A_i.
For each j=1,2,\ldots,Q, answer the following question.
- How many of the N students have a height of at least x_j?
Constraints
- 1 \leq N,Q \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq x_j \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N Q A_1 A_2 \ldots A_N x_1 x_2 \vdots x_Q
Output
Print Q lines.
The j-th line (1 \leq j \leq Q) should contain the number of students with a height of at least x_j.
Sample Input 1
3 1 100 160 130 120
Sample Output 1
2
The students with a height of at least 120 are the 2-nd and 3-rd ones.
Sample Input 2
5 5 1 2 3 4 5 6 5 4 3 2
Sample Output 2
0 1 2 3 4
Sample Input 3
5 5 804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422
Sample Output 3
5 3 5 5 5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
長さ N の数列 A = (A_1, A_2, \dots, A_N) が与えられます。
Q 個のクエリが与えられるので、順番にすべて処理してください。 q 番目 (1\leq q\leq Q) のクエリは以下の 3 つのいずれかの形式で、それぞれ次のようなクエリを表します。
- 1\ x _ q : A のすべての要素に x _ q を代入する。
- 2\ i _ q\ x _ q : A _ {i _ q} に x _ q を加える。
- 3\ i _ q : A _ {i _ q} の値を出力する。
制約
- 1 \leq N \leq 2\times10^5
- 1 \leq Q \leq 2\times10^5
- 0 \leq A _ i \leq 10^9\ (1\leq i\leq N)
- q 番目 (1\leq q\leq Q) のクエリが 2 番目もしくは 3 番目の形式のとき、1 \leq i _ q \leq N
- q 番目 (1\leq q\leq Q) のクエリが 1 番目もしくは 2 番目の形式のとき、0 \leq x _ q \leq 10^9
- 3 番目の形式のクエリが存在する
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
A_1 A_2 \dots A_N
Q
\operatorname{query}_1
\operatorname{query}_2
\vdots
\operatorname{query}_Q
ただし、\operatorname{query}_q は q 番目のクエリであり、1 x, 2 i x, 3 i の形式のいずれかで与えられる。
出力
\operatorname{query}_q が 3 番目の形式であるような q\ (1\leq q\leq Q) の個数を X として、X 行出力せよ。 j\ (1\leq j\leq X) 行目にはそのようなクエリのうち j 番目のクエリに対する答えを出力せよ。
入力例 1
5 3 1 4 1 5 6 3 2 2 3 4 3 3 1 1 2 3 4 3 3
出力例 1
1 8 5
はじめ、A=(3,1,4,1,5) です。 それぞれのクエリでは、以下のような処理が行われます。
- A_2=1 なので、1 を出力します。
- A_3 に 4 を加えます。A=(3,1,8,1,5) となります。
- A_3=8 なので、8 を出力します。
- A の要素すべてに 1 を代入します。A=(1,1,1,1,1) となります。
- A_3 に 4 を加えます。A=(1,1,5,1,1) となります。
- A_3=5 なので、5 を出力します。
入力例 2
1 1000000000 8 2 1 1000000000 2 1 1000000000 2 1 1000000000 2 1 1000000000 2 1 1000000000 2 1 1000000000 2 1 1000000000 3 1
出力例 2
8000000000
A の要素の値が 32\operatorname{bit} 整数に収まらない可能性があることに注意してください。
入力例 3
10 1 8 4 15 7 5 7 5 8 0 20 2 7 0 3 7 3 8 1 7 3 3 2 4 4 2 4 9 2 10 5 1 10 2 4 2 1 10 2 3 1 2 8 11 2 3 14 2 1 9 3 8 3 8 3 1 2 6 5 3 7
出力例 3
7 5 7 21 21 19 10
Score : 400 points
Problem Statement
You are given a sequence A = (A_1, A_2, \dots, A_N) of length N.
Given Q queries, process all of them in order. The q-th (1\leq q\leq Q) query is in one of the following three formats, which represents the following queries:
- 1\ x _ q: assign x_q to every element of A.
- 2\ i _ q\ x _ q: add x_q to A _ {i _ q}.
- 3\ i _ q: print the value of A _ {i _ q}.
Constraints
- 1 \leq N \leq 2\times10^5
- 1 \leq Q \leq 2\times10^5
- 0 \leq A _ i \leq 10^9\ (1\leq i\leq N)
- If the q-th (1\leq q\leq Q) query is in the second or third format, 1 \leq i _ q \leq N.
- If the q-th (1\leq q\leq Q) query is in the first or second format, 0 \leq x _ q \leq 10^9.
- There exists a query in the third format.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N
A_1 A_2 \dots A_N
Q
\operatorname{query}_1
\operatorname{query}_2
\vdots
\operatorname{query}_Q
Here, \operatorname{query}_q denotes the q-th query, which is in one of following formats: 1 x, 2 i x, and 3 i.
Output
Print X lines, where X is the number of q's (1\leq q\leq Q) such that \operatorname{query}_q is in the third format. The j-th (1\leq j\leq X) line should contain the answer to the j-th such query.
Sample Input 1
5 3 1 4 1 5 6 3 2 2 3 4 3 3 1 1 2 3 4 3 3
Sample Output 1
1 8 5
Initially, A=(3,1,4,1,5). The queries are processed as follows:
- A_2=1, so print 1.
- Add 4 to A_3, making A=(3,1,8,1,5).
- A_3=8, so print 8.
- Assign 1 to every element of A, making A=(1,1,1,1,1).
- Add 4 to A_3, making A=(1,1,5,1,1).
- A_3=5, so print 5.
Sample Input 2
1 1000000000 8 2 1 1000000000 2 1 1000000000 2 1 1000000000 2 1 1000000000 2 1 1000000000 2 1 1000000000 2 1 1000000000 3 1
Sample Output 2
8000000000
Note that the elements of A may not fit into a 32-bit integer type.
Sample Input 3
10 1 8 4 15 7 5 7 5 8 0 20 2 7 0 3 7 3 8 1 7 3 3 2 4 4 2 4 9 2 10 5 1 10 2 4 2 1 10 2 3 1 2 8 11 2 3 14 2 1 9 3 8 3 8 3 1 2 6 5 3 7
Sample Output 3
7 5 7 21 21 19 10
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 450 点
問題文
AtCoder 食堂では主菜と副菜からなる定食が販売されています。
主菜は N 種類あり、順に主菜 1, 主菜 2, \dots, 主菜 N と呼びます。主菜 i の価格は a_i 円です。
副菜は M 種類あり、順に副菜 1, 副菜 2, \dots, 副菜 M と呼びます。副菜 i の価格は b_i 円です。
定食は主菜と副菜を 1 種類ずつ選んで構成されます。定食の価格は選んだ主菜の価格と副菜の価格の和です。
ただし、L 個の相異なる組 (c_1, d_1), \dots, (c_L, d_L) について、主菜 c_i と副菜 d_i からなる定食は食べ合わせが悪いため提供されていません。
つまり、提供されている定食は NM - L 種類あることになります。(提供されている定食が少なくとも 1 種類存在することが制約によって保証されています。)
提供されている定食のうち、最も価格の高い定食の価格を求めてください。
制約
- 1 \leq N, M \leq 10^5
- 0 \leq L \leq \min(10^5, N M - 1)
- 1 \leq a_i, b_i \leq 10^9
- 1 \leq c_i \leq N
- 1 \leq d_j \leq M
- i \neq j ならば (c_i, d_i) \neq (c_j, d_j)
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M L a_1 a_2 \dots a_N b_1 b_2 \dots b_M c_1 d_1 c_2 d_2 \vdots c_L d_L
出力
提供されている定食のうち、最も価格の高い定食が何円であるかを出力せよ。
入力例 1
2 3 3 2 1 10 30 20 1 2 2 1 2 3
出力例 1
31
提供されている定食、及びその価格は次の 3 種類です。
- 主菜 1 と副菜 1 からなる定食。価格は 2 + 10 = 12 円である。
- 主菜 1 と副菜 3 からなる定食。価格は 2 + 20 = 22 円である。
- 主菜 2 と副菜 2 からなる定食。価格は 1 + 30 = 31 円である。
この中で最も高い定食は 3 番目の定食です。よって 31 を出力してください。
入力例 2
2 1 0 1000000000 1 1000000000
出力例 2
2000000000
入力例 3
10 10 10 47718 21994 74148 76721 98917 73766 29598 59035 69293 29127 7017 46004 16086 62644 74928 57404 32168 45794 19493 71590 1 3 2 6 4 5 5 4 5 5 5 6 5 7 5 8 5 10 7 3
出力例 3
149076
Score : 450 points
Problem Statement
AtCoder cafeteria sells meals consisting of a main dish and a side dish.
There are N types of main dishes, called main dish 1, main dish 2, \dots, main dish N. Main dish i costs a_i yen.
There are M types of side dishes, called side dish 1, side dish 2, \dots, side dish M. Side dish i costs b_i yen.
A set meal is composed by choosing one main dish and one side dish. The price of a set meal is the sum of the prices of the chosen main dish and side dish.
However, for L distinct pairs (c_1, d_1), \dots, (c_L, d_L), the set meal consisting of main dish c_i and side dish d_i is not offered because they do not go well together.
That is, NM - L set meals are offered. (The constraints guarantee that at least one set meal is offered.)
Find the price of the most expensive set meal offered.
Constraints
- 1 \leq N, M \leq 10^5
- 0 \leq L \leq \min(10^5, NM - 1)
- 1 \leq a_i, b_i \leq 10^9
- 1 \leq c_i \leq N
- 1 \leq d_j \leq M
- (c_i, d_i) \neq (c_j, d_j) if i \neq j.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M L a_1 a_2 \dots a_N b_1 b_2 \dots b_M c_1 d_1 c_2 d_2 \vdots c_L d_L
Output
Print the price, in yen, of the most expensive set meal offered.
Sample Input 1
2 3 3 2 1 10 30 20 1 2 2 1 2 3
Sample Output 1
31
They offer three set meals, listed below, along with their prices:
- A set meal consisting of main dish 1 and side dish 1, at a price of 2 + 10 = 12 yen.
- A set meal consisting of main dish 1 and side dish 3, at a price of 2 + 20 = 22 yen.
- A set meal consisting of main dish 2 and side dish 2, at a price of 1 + 30 = 31 yen.
Among them, the most expensive is the third one. Thus, print 31.
Sample Input 2
2 1 0 1000000000 1 1000000000
Sample Output 2
2000000000
Sample Input 3
10 10 10 47718 21994 74148 76721 98917 73766 29598 59035 69293 29127 7017 46004 16086 62644 74928 57404 32168 45794 19493 71590 1 3 2 6 4 5 5 4 5 5 5 6 5 7 5 8 5 10 7 3
Sample Output 3
149076
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
縦 N 行、横 M 列のマス目に、黒い飛車の駒 B 個と白い飛車の駒 W 個を設置することを考えましょう。
以下の条件をすべて満たす設置の仕方を いい配置 と呼びます。
- B+W 個の駒すべてが設置されている。
- 1 つのマスに置かれている駒の数は高々 1 つである。
- ある白い駒と黒い駒の組であって、互いが互いを攻撃しているようなものが存在しない。すなわち、ある白い駒と黒い駒の組であって、一方が 1 手の移動によってもう片方が置かれているマスに到達できるようなものが存在しない。
ここで、飛車の駒は、今いる位置から上、下、右、左のいずれかの方向に伸びる直線上にあり、かつ他の駒を飛び越えずに到達できるマスに 1 手で移動することができます。
いい配置としてあり得るものは何通りありますか?答えは非常に大きくなることがあるので、998244353 で割ったあまりを出力してください。
同じ色の駒同士は区別しないものとします。
制約
- 1 \leq N,M \leq 50
- 1 \leq B,W \leq 2500
- B+W \leq N \times M
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M B W
出力
答えを 998244353 で割ったあまりを出力せよ。
入力例 1
2 2 1 1
出力例 1
4
いい配置としてあり得るものは以下の 4 通りです。

入力例 2
1 2 1 1
出力例 2
0
いい配置としてあり得るものが存在しない場合もあります。
入力例 3
40 40 30 30
出力例 3
467620384
998244353 で割ったあまりを出力することに注意してください。
Score : 500 points
Problem Statement
Consider placing B black rooks and W white rooks on a grid with N horizontal rows and M vertical columns.
A placement of the rooks satisfying all of the following conditions is called a good placement.
- All B+W rooks are placed on the grid.
- At most one rook is placed in the same square.
- There is no pair of white rook and black rook attacking each other. That is, there is no pair of white rook and black rook such that one of them can reach the square in which the other is placed in one move.
Here, in one move, a rook can reach any square that is on a horizontal or vertical line from its current position and is reachable without jumping over another rook.
How many good placements are there? Since this count can be enormous, print it modulo 998244353.
Rooks in the same color are not distinguished.
Constraints
- 1 \leq N,M \leq 50
- 1 \leq B,W \leq 2500
- B+W \leq N \times M
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M B W
Output
Print the count modulo 998244353.
Sample Input 1
2 2 1 1
Sample Output 1
4
There are four good placements as follows.

Sample Input 2
1 2 1 1
Sample Output 2
0
There may be no good placement.
Sample Input 3
40 40 30 30
Sample Output 3
467620384
Be sure to print the count modulo 998244353.