A - 内積の計算

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

高橋君は、大学の線形代数の授業で内積の計算練習をしています。

7 次元のベクトル \mathbf{a} = (A_1, A_2, \ldots, A_7)\mathbf{b} = (B_1, B_2, \ldots, B_7) が与えられるので、これらの内積 \mathbf{a} \cdot \mathbf{b} = A_1 \times B_1 + A_2 \times B_2 + \cdots + A_7 \times B_7 を求めてください。

制約

  • -100 \leq A_i \leq 100 (1 \leq i \leq 7)
  • -100 \leq B_i \leq 100 (1 \leq i \leq 7)
  • 入力はすべて整数である。

入力

A_1 A_2 A_3 A_4 A_5 A_6 A_7
B_1 B_2 B_3 B_4 B_5 B_6 B_7
  • 1 行目には、ベクトル \mathbf{a} の各成分を表す 7 個の整数 A_1, A_2, \ldots, A_7 がスペース区切りで与えられる。
  • 2 行目には、ベクトル \mathbf{b} の各成分を表す 7 個の整数 B_1, B_2, \ldots, B_7 がスペース区切りで与えられる。

出力

2 つのベクトルの内積 A_1 \times B_1 + A_2 \times B_2 + \cdots + A_7 \times B_7 の値を 1 行で出力してください。


入力例 1

1 2 3 4 5 6 7
1 1 1 1 1 1 1

出力例 1

28

入力例 2

3 -1 4 1 -5 9 2
2 7 -1 8 2 -3 6

出力例 2

-22

入力例 3

100 -100 100 -100 100 -100 100
100 100 -100 -100 100 100 -100

出力例 3

-10000

Score : 200 pts

Problem Statement

Takahashi is practicing dot product calculations in his university linear algebra class.

Given two 7-dimensional vectors \mathbf{a} = (A_1, A_2, \ldots, A_7) and \mathbf{b} = (B_1, B_2, \ldots, B_7), compute their dot product \mathbf{a} \cdot \mathbf{b} = A_1 \times B_1 + A_2 \times B_2 + \cdots + A_7 \times B_7.

Constraints

  • -100 \leq A_i \leq 100 (1 \leq i \leq 7)
  • -100 \leq B_i \leq 100 (1 \leq i \leq 7)
  • All inputs are integers.

Input

A_1 A_2 A_3 A_4 A_5 A_6 A_7
B_1 B_2 B_3 B_4 B_5 B_6 B_7
  • The first line contains 7 integers A_1, A_2, \ldots, A_7 separated by spaces, representing the components of vector \mathbf{a}.
  • The second line contains 7 integers B_1, B_2, \ldots, B_7 separated by spaces, representing the components of vector \mathbf{b}.

Output

Print the value of the dot product of the two vectors, A_1 \times B_1 + A_2 \times B_2 + \cdots + A_7 \times B_7, on a single line.


Sample Input 1

1 2 3 4 5 6 7
1 1 1 1 1 1 1

Sample Output 1

28

Sample Input 2

3 -1 4 1 -5 9 2
2 7 -1 8 2 -3 6

Sample Output 2

-22

Sample Input 3

100 -100 100 -100 100 -100 100
100 100 -100 -100 100 100 -100

Sample Output 3

-10000
B - 最初のアラート

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 233

問題文

高橋君はサーバーの監視システムを担当しています。このシステムでは、 N 件のログが順番に届きます。

各ログには「重要度」を表す整数値が設定されており、 i 番目( 1 \leq i \leq N )に届くログの重要度は P_i です。

高橋君は効率的な監視のため、独自のルールを設定しています。ログを 1 番目から順に確認していき、重要度が閾値 K 以上であるログを初めて見つけたら、すぐにアラートを発報して対応に向かうことにしています。一度アラートを発報したら、それ以降のログは確認しません。

高橋君がアラートを発報することになるログの番号(何番目に届いたログか)を求めてください。もし N 件すべてのログの重要度が K 未満であり、アラートを一度も発報しなかった場合は -1 を出力してください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq 10^9
  • 1 \leq P_i \leq 10^9 (1 \leq i \leq N)
  • 入力はすべて整数

入力

N K
P_1 P_2 \ldots P_N
  • 1 行目には、ログの件数を表す整数 N と、アラートを発報する重要度の閾値を表す整数 K が、スペース区切りで与えられる。
  • 2 行目には、各ログの重要度を表す整数 P_1, P_2, \ldots, P_N が、スペース区切りで与えられる。
  • P_ii 番目に届くログの重要度を表す。

出力

高橋君がアラートを発報することになるログの番号を 1 行で出力してください。ここでログの番号とは、何番目に届いたログかを表す 1 以上 N 以下の整数です。アラートを一度も発報しなかった場合は -1 を出力してください。


入力例 1

5 50
10 30 55 80 20

出力例 1

3

入力例 2

4 100
25 50 75 90

出力例 2

-1

入力例 3

10 1000000000
100 200 300 400 500 600 700 800 900 1000000000

出力例 3

10

Score : 233 pts

Problem Statement

Takahashi is in charge of a server monitoring system. In this system, N logs arrive in order.

Each log has an integer value representing its "severity level." The severity level of the i-th log (1 \leq i \leq N) to arrive is P_i.

For efficient monitoring, Takahashi has set up his own rule. He checks the logs in order starting from the 1st one, and as soon as he finds a log with a severity level of at least the threshold K, he immediately triggers an alert and goes to respond. Once an alert is triggered, he does not check any subsequent logs.

Determine the number of the log (i.e., which log in the arrival order) that causes Takahashi to trigger an alert. If the severity levels of all N logs are less than K and no alert is ever triggered, output -1.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq 10^9
  • 1 \leq P_i \leq 10^9 (1 \leq i \leq N)
  • All input values are integers.

Input

N K
P_1 P_2 \ldots P_N
  • The first line contains an integer N representing the number of logs and an integer K representing the severity threshold for triggering an alert, separated by a space.
  • The second line contains integers P_1, P_2, \ldots, P_N representing the severity levels of each log, separated by spaces.
  • P_i represents the severity level of the i-th log to arrive.

Output

Print the number of the log that causes Takahashi to trigger an alert, on a single line. Here, the log number is an integer between 1 and N inclusive, representing which log it is in the arrival order. If no alert is ever triggered, print -1.


Sample Input 1

5 50
10 30 55 80 20

Sample Output 1

3

Sample Input 2

4 100
25 50 75 90

Sample Output 2

-1

Sample Input 3

10 1000000000
100 200 300 400 500 600 700 800 900 1000000000

Sample Output 3

10
C - 対戦カードの組み合わせ

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 333

問題文

高橋君はスポーツ大会の対戦表を作成しています。

大会には N 人の選手が参加しており、選手には 1 から N までの番号が付けられています。選手 i (1 \leq i \leq N) には「競技番号」 P_i と「所属チーム番号」 Q_i という2つの整数が割り当てられています。競技番号はその選手がエントリーしている競技の識別番号を、所属チーム番号はその選手が所属するチームの識別番号を表します。

この大会では、選手 i と選手 j (1 \leq i < j \leq N) が対戦できるのは、同じ競技にエントリーしていて、かつ異なるチームに所属している場合に限ります。すなわち、P_i = P_j かつ Q_i \neq Q_j であるときに限り対戦が成立します。

なお、競技番号と所属チーム番号の組がまったく同じ選手が複数存在することもあります。そのような選手同士は選手番号によって区別される別々の選手ですが、同じチームに所属しているため Q_i \neq Q_j の条件を満たさず、互いに対戦することはできません。

対戦が成立する2人の選手の組(順序を区別しない)の総数を求めてください。

制約

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq P_i \leq 10^5
  • 1 \leq Q_i \leq 10^5
  • 入力はすべて整数である
  • 答えは 2^{63} - 1 以下であることが保証される

入力

入力は以下の形式で標準入力から与えられる。

N
P_1 Q_1
P_2 Q_2
\vdots
P_N Q_N

1 行目には、選手の人数を表す整数 N が与えられる。続く N 行のうち、上から i 番目の行 (1 \leq i \leq N) には、選手 i の競技番号 P_i と所属チーム番号 Q_i が空白区切りで与えられる。

出力

対戦が成立する2人の選手の組の総数を1行で出力せよ。


入力例 1

4
1 1
1 2
2 1
1 1

出力例 1

2

入力例 2

6
1 1
1 2
1 3
2 1
2 1
2 2

出力例 2

5

入力例 3

10
1 1
1 1
1 2
1 2
1 3
2 1
2 2
2 3
3 1
3 1

出力例 3

11

Score : 333 pts

Problem Statement

Takahashi is creating a match schedule for a sports tournament.

There are N players participating in the tournament, numbered from 1 to N. Each player i (1 \leq i \leq N) is assigned two integers: a "sport number" P_i and a "team number" Q_i. The sport number represents the identifier of the sport the player has entered, and the team number represents the identifier of the team the player belongs to.

In this tournament, player i and player j (1 \leq i < j \leq N) can compete against each other only if they are entered in the same sport and belong to different teams. That is, a match is possible only when P_i = P_j and Q_i \neq Q_j.

Note that there may be multiple players with exactly the same combination of sport number and team number. Such players are considered distinct players distinguished by their player numbers, but since they belong to the same team, they do not satisfy the condition Q_i \neq Q_j and cannot compete against each other.

Find the total number of unordered pairs of players that can compete against each other.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq P_i \leq 10^5
  • 1 \leq Q_i \leq 10^5
  • All input values are integers
  • It is guaranteed that the answer is at most 2^{63} - 1

Input

Input is given from standard input in the following format:

N
P_1 Q_1
P_2 Q_2
\vdots
P_N Q_N

The first line contains an integer N representing the number of players. In the following N lines, the i-th line (1 \leq i \leq N) contains the sport number P_i and team number Q_i of player i, separated by a space.

Output

Output the total number of unordered pairs of players that can compete against each other, in a single line.


Sample Input 1

4
1 1
1 2
2 1
1 1

Sample Output 1

2

Sample Input 2

6
1 1
1 2
1 3
2 1
2 1
2 2

Sample Output 2

5

Sample Input 3

10
1 1
1 1
1 2
1 2
1 3
2 1
2 2
2 3
3 1
3 1

Sample Output 3

11
D - アルバイトのシフト割り当て

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 366

問題文

高橋君は大学の学園祭で模擬店の運営責任者を務めています。彼は N 人の調理担当スタッフと M 個の調理タスクを管理しています。

各調理担当スタッフには「スキルレベル」が設定されており、i 番目のスタッフのスキルレベルは A_i です。同様に、各調理タスクには「必要スキルレベル」が設定されており、j 番目のタスクの必要スキルレベルは B_j です。

スタッフがタスクを担当できるのは、そのスタッフのスキルレベルがタスクの必要スキルレベル以上である場合に限ります。つまり、i 番目のスタッフが j 番目のタスクを担当できるのは A_i \geq B_j のときに限ります。

高橋君は、スタッフとタスクの間で1対1の割り当てを行います。すなわち、各スタッフには最大 1 つのタスクを割り当てることができ、各タスクには最大 1 人のスタッフしか割り当てられません。すべてのスタッフにタスクを割り当てる必要はなく、またスタッフが割り当てられないタスクがあっても構いません。

スタッフが割り当てられたタスクは完了し、その成果として料理が 1 品完成します。完成した料理はすべて 1 品あたり C 円で販売されます。すなわち、完了したタスクの数を K とすると、売上金額は K \times C 円です。

高橋君がスタッフとタスクの割り当てを最適に選んだとき、得られる最大の売上金額を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq 2 \times 10^5
  • 1 \leq C \leq 10^9
  • 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq B_j \leq 10^9 (1 \leq j \leq M)
  • 入力はすべて整数

入力

N M C
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M
  • 1 行目には、スタッフの人数を表す N 、タスクの個数を表す M 、料理 1 品あたりの販売価格を表す C が、スペース区切りで与えられる。
  • 2 行目には、各スタッフのスキルレベルを表す A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
  • 3 行目には、各タスクの必要スキルレベルを表す B_1, B_2, \ldots, B_M が、スペース区切りで与えられる。

出力

高橋君が得られる最大の売上金額を 1 行で出力してください。なお、答えは 2 \times 10^{14} 以下の非負整数となります。


入力例 1

3 3 500
5 3 1
2 4 6

出力例 1

1000

入力例 2

5 4 1000
10 3 7 1 8
5 2 9 4

出力例 2

4000

入力例 3

7 8 1000000000
100 50 80 30 60 90 10
20 40 60 80 100 55 35 75

出力例 3

6000000000

Score : 366 pts

Problem Statement

Takahashi is the manager of a food stall at his university's school festival. He manages N cooking staff members and M cooking tasks.

Each cooking staff member has a "skill level"; the skill level of the i-th staff member is A_i. Similarly, each cooking task has a "required skill level"; the required skill level of the j-th task is B_j.

A staff member can handle a task only if their skill level is at least the required skill level of the task. In other words, the i-th staff member can handle the j-th task only when A_i \geq B_j.

Takahashi assigns staff members to tasks in a one-to-one manner. That is, each staff member can be assigned to at most 1 task, and each task can be assigned to at most 1 staff member. It is not necessary to assign a task to every staff member, and it is acceptable for some tasks to have no staff member assigned to them.

A task to which a staff member is assigned is completed, producing 1 dish as a result. All completed dishes are sold at C yen each. In other words, if K tasks are completed, the total sales amount is K \times C yen.

Find the maximum sales amount Takahashi can obtain when he optimally chooses the assignment of staff members to tasks.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq 2 \times 10^5
  • 1 \leq C \leq 10^9
  • 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq B_j \leq 10^9 (1 \leq j \leq M)
  • All inputs are integers

Input

N M C
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M
  • The first line contains N, the number of staff members, M, the number of tasks, and C, the selling price per dish, separated by spaces.
  • The second line contains the skill levels of each staff member, A_1, A_2, \ldots, A_N, separated by spaces.
  • The third line contains the required skill levels of each task, B_1, B_2, \ldots, B_M, separated by spaces.

Output

Print the maximum sales amount Takahashi can obtain in a single line. Note that the answer is a non-negative integer not exceeding 2 \times 10^{14}.


Sample Input 1

3 3 500
5 3 1
2 4 6

Sample Output 1

1000

Sample Input 2

5 4 1000
10 3 7 1 8
5 2 9 4

Sample Output 2

4000

Sample Input 3

7 8 1000000000
100 50 80 30 60 90 10
20 40 60 80 100 55 35 75

Sample Output 3

6000000000
E - 花の種類を数えよう

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 466

問題文

高橋君は植物園の管理人として働いています。植物園には一直線に並んだ N 個の花壇があり、左から順に 1, 2, \ldots, N の番号が付けられています。各花壇 i (1 \leq i \leq N) には、品種番号 P_i の花が植えられています。品種番号は 1 以上 N 以下の整数であり、異なる花壇に同じ品種番号の花が植えられていることもあります。

植物園では Q 回の見学ツアーが予定されています。i 回目 (1 \leq i \leq Q) のツアーでは、花壇 L_i から花壇 R_i までの範囲(両端を含む)を見学します。

高橋君は、各ツアーの案内を準備するために、見学範囲内に何種類の花があるかを事前に把握しておきたいと考えています。

各ツアーについて、花壇 L_i から花壇 R_i の範囲に含まれる異なる品種番号の数を求めてください。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq Q \leq 10^5
  • 1 \leq P_i \leq N (1 \leq i \leq N)
  • 1 \leq L_i \leq R_i \leq N (1 \leq i \leq Q)
  • 入力はすべて整数

入力

N Q
P_1 P_2 \ldots P_N
L_1 R_1
L_2 R_2
\vdots
L_Q R_Q
  • 1 行目には、花壇の数を表す整数 N と、ツアーの回数を表す整数 Q が、スペース区切りで与えられる。
  • 2 行目には、各花壇に植えられている花の品種番号を表す整数 P_1, P_2, \ldots, P_N が、スペース区切りで与えられる。
  • 続く Q 行では、各ツアーの見学範囲が与えられる。
  • そのうち i 行目 (1 \leq i \leq Q) には、i 回目のツアーにおける見学範囲の左端 L_i と右端 R_i が、スペース区切りで与えられる。

出力

Q 行にわたって出力せよ。i 行目 (1 \leq i \leq Q) には、i 回目のツアーにおいて、花壇 L_i から花壇 R_i の範囲に含まれる異なる品種番号の数を出力せよ。


入力例 1

5 3
1 2 1 3 2
1 3
2 5
1 5

出力例 1

2
3
3

入力例 2

10 5
3 1 4 1 5 9 2 6 5 3
1 5
3 7
1 10
5 5
2 8

出力例 2

4
5
7
1
6

入力例 3

20 8
5 3 5 2 1 4 3 2 1 5 4 3 2 1 5 4 3 2 1 4
1 20
1 1
10 15
5 10
1 10
11 20
7 14
3 8

出力例 3

5
1
5
5
5
5
5
5

Score : 466 pts

Problem Statement

Takahashi works as a caretaker at a botanical garden. The garden has N flower beds arranged in a straight line, numbered 1, 2, \ldots, N from left to right. Each flower bed i (1 \leq i \leq N) contains a flower of species number P_i. Species numbers are integers between 1 and N inclusive, and different flower beds may contain flowers of the same species number.

The botanical garden has Q tour visits scheduled. The i-th tour (1 \leq i \leq Q) visits the range from flower bed L_i to flower bed R_i (inclusive).

Takahashi wants to know in advance how many distinct types of flowers are in each tour's visiting range, in order to prepare the guide for each tour.

For each tour, determine the number of distinct species numbers contained in the range from flower bed L_i to flower bed R_i.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq Q \leq 10^5
  • 1 \leq P_i \leq N (1 \leq i \leq N)
  • 1 \leq L_i \leq R_i \leq N (1 \leq i \leq Q)
  • All inputs are integers

Input

N Q
P_1 P_2 \ldots P_N
L_1 R_1
L_2 R_2
\vdots
L_Q R_Q
  • The first line contains an integer N representing the number of flower beds and an integer Q representing the number of tours, separated by a space.
  • The second line contains integers P_1, P_2, \ldots, P_N representing the species numbers of the flowers planted in each flower bed, separated by spaces.
  • The following Q lines give the visiting range for each tour.
  • The i-th of these lines (1 \leq i \leq Q) contains the left endpoint L_i and right endpoint R_i of the visiting range for the i-th tour, separated by a space.

Output

Output Q lines. The i-th line (1 \leq i \leq Q) should contain the number of distinct species numbers in the range from flower bed L_i to flower bed R_i for the i-th tour.


Sample Input 1

5 3
1 2 1 3 2
1 3
2 5
1 5

Sample Output 1

2
3
3

Sample Input 2

10 5
3 1 4 1 5 9 2 6 5 3
1 5
3 7
1 10
5 5
2 8

Sample Output 2

4
5
7
1
6

Sample Input 3

20 8
5 3 5 2 1 4 3 2 1 5 4 3 2 1 5 4 3 2 1 4
1 20
1 1
10 15
5 10
1 10
11 20
7 14
3 8

Sample Output 3

5
1
5
5
5
5
5
5