A - 宇宙船を迎え撃て

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

配点 : 200

問題文

高橋君は宇宙防衛軍の司令官として、地球から遠ざかる敵の宇宙船を迎撃するミッションを指揮しています。

宇宙空間に一直線の航路があり、地球は座標 0 の位置にあります。敵の宇宙船は座標 D の位置におり、地球から遠ざかる方向(座標が増加する方向)に一定の速度 V で逃走を開始しました。

高橋君は N 機の迎撃ミサイルを発射準備しています。 i 番目のミサイルは速度 S_i で飛行することができます。ミサイルは敵の宇宙船と同じ方向(座標が増加する方向)にのみ飛行でき、時刻 0 に座標 0 から発射されます。

高橋君は、敵の宇宙船に到達できるミサイルを把握する必要があります。ミサイルが敵の宇宙船に到達するとは、ある時刻 t \geq 0 においてミサイルの座標が敵の宇宙船の座標以上になることを意味します。

N 機のミサイルのうち、敵の宇宙船に到達できるミサイルの数を求めてください。

制約

  • 1 \leq N \leq 10^6
  • 1 \leq D \leq 10^9
  • 1 \leq V \leq 10^9
  • 1 \leq S_i \leq 10^9 (1 \leq i \leq N)
  • 入力はすべて整数

入力

N D V
S_1 S_2 \ldots S_N
  • 1 行目には、ミサイルの数を表す N 、敵の宇宙船の初期位置を表す D 、敵の宇宙船の速度を表す V が、スペース区切りで与えられる。
  • 2 行目には、各ミサイルの速度を表す S_1, S_2, \ldots, S_N が、スペース区切りで与えられる。

出力

敵の宇宙船に到達できるミサイルの数を 1 行で出力してください。


入力例 1

5 10 3
2 3 4 5 10

出力例 1

3

入力例 2

4 7 5
1 5 4 2

出力例 2

0

入力例 3

12 100 20
5 20 21 19 100 1 25 20 30 18 22 40

出力例 3

6

入力例 4

30 123456789 500000000
499999999 500000000 500000001 600000000 700000000 1 999999999 250000000 800000000 450000000 510000000 490000000 520000000 530000000 540000000 550000000 560000000 570000000 580000000 590000000 400000000 300000000 200000000 100000000 750000000 650000000 350000000 150000000 900000000 1000000000

出力例 4

18

入力例 5

1 1000000000 1000000000
1000000000

出力例 5

0

Score : 200 pts

Problem Statement

Takahashi is commanding a mission as the commander of the Space Defense Force to intercept an enemy spaceship that is moving away from Earth.

There is a straight route in outer space, and Earth is located at coordinate 0. The enemy spaceship is at coordinate D and has begun fleeing at a constant speed V in the direction away from Earth (the direction of increasing coordinates).

Takahashi is preparing to launch N interceptor missiles. The i-th missile can fly at speed S_i. Missiles can only fly in the same direction as the enemy spaceship (the direction of increasing coordinates), and are launched from coordinate 0 at time 0.

Takahashi needs to determine which missiles can reach the enemy spaceship. A missile reaching the enemy spaceship means that at some time t \geq 0, the missile's coordinate becomes greater than or equal to the enemy spaceship's coordinate.

Find the number of missiles among the N missiles that can reach the enemy spaceship.

Constraints

  • 1 \leq N \leq 10^6
  • 1 \leq D \leq 10^9
  • 1 \leq V \leq 10^9
  • 1 \leq S_i \leq 10^9 (1 \leq i \leq N)
  • All inputs are integers

Input

N D V
S_1 S_2 \ldots S_N
  • The first line contains N representing the number of missiles, D representing the initial position of the enemy spaceship, and V representing the speed of the enemy spaceship, separated by spaces.
  • The second line contains S_1, S_2, \ldots, S_N representing the speeds of each missile, separated by spaces.

Output

Output the number of missiles that can reach the enemy spaceship in one line.


Sample Input 1

5 10 3
2 3 4 5 10

Sample Output 1

3

Sample Input 2

4 7 5
1 5 4 2

Sample Output 2

0

Sample Input 3

12 100 20
5 20 21 19 100 1 25 20 30 18 22 40

Sample Output 3

6

Sample Input 4

30 123456789 500000000
499999999 500000000 500000001 600000000 700000000 1 999999999 250000000 800000000 450000000 510000000 490000000 520000000 530000000 540000000 550000000 560000000 570000000 580000000 590000000 400000000 300000000 200000000 100000000 750000000 650000000 350000000 150000000 900000000 1000000000

Sample Output 4

18

Sample Input 5

1 1000000000 1000000000
1000000000

Sample Output 5

0
B - フルーツの詰め合わせ

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

配点 : 300

問題文

高橋君は果物屋で働いています。店には N 個のフルーツが並んでおり、i 番目のフルーツの甘さは A_i です。

そこに、青木君が仕入れ先から M 個の新しいフルーツを届けてきました。j 番目の新しいフルーツの甘さは B_j です。

高橋君は、これら合計 N + M 個のフルーツの中から、甘さの大きい順に K 個を選び、ギフト用の詰め合わせを作ることにしました。

選ばれた K 個のフルーツの甘さの合計を求めてください。

なお、甘さが等しいフルーツが複数ある場合でも、どの K 個を選んでも甘さの合計は同じ値になります。

制約

  • 1 \leq N, M
  • N + M \leq 150000
  • 1 \leq K \leq N + M
  • 0 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • 0 \leq B_j \leq 10^9 (1 \leq j \leq M)
  • 入力はすべて整数である

入力

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

N M K
A_1
A_2
\vdots
A_N
B_1
B_2
\vdots
B_M
  • 1 行目には、店にあるフルーツの個数 N、新しく届いたフルーツの個数 M、選ぶフルーツの個数 K がスペース区切りで与えられる。
  • 続く N 行のうち i 行目 (1 \leq i \leq N) には、店にある i 番目のフルーツの甘さ A_i が与えられる。
  • 続く M 行のうち j 行目 (1 \leq j \leq M) には、新しく届いた j 番目のフルーツの甘さ B_j が与えられる。

出力

選ばれた K 個のフルーツの甘さの合計を 1 行で出力せよ。


入力例 1

3 2 3
4
1
7
5
2

出力例 1

16

入力例 2

2 3 4
5
5
5
1
0

出力例 2

16

入力例 3

7 6 8
12
3
25
8
17
6
14
9
30
2
17
11
20

出力例 3

146

入力例 4

12 10 15
100
250
400
50
600
700
150
350
800
450
550
650
500
300
900
200
1000
750
125
875
425
575

出力例 4

9525

入力例 5

1 1 2
0
1000000000

出力例 5

1000000000

Score : 300 pts

Problem Statement

Takahashi works at a fruit shop. There are N fruits displayed in the shop, and the sweetness of the i-th fruit is A_i.

Then, Aoki delivers M new fruits from the supplier. The sweetness of the j-th new fruit is B_j.

Takahashi decides to select K fruits from among these N + M fruits in descending order of sweetness to make a gift assortment.

Find the total sweetness of the K selected fruits.

Note that even if there are multiple fruits with the same sweetness, the total sweetness will be the same regardless of which K fruits are chosen.

Constraints

  • 1 \leq N, M
  • N + M \leq 150000
  • 1 \leq K \leq N + M
  • 0 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • 0 \leq B_j \leq 10^9 (1 \leq j \leq M)
  • All input values are integers

Input

The input is given in the following format.

N M K
A_1
A_2
\vdots
A_N
B_1
B_2
\vdots
B_M
  • The first line contains the number of fruits in the shop N, the number of newly delivered fruits M, and the number of fruits to select K, separated by spaces.
  • The following N lines, where the i-th line (1 \leq i \leq N) contains the sweetness A_i of the i-th fruit in the shop.
  • The following M lines, where the j-th line (1 \leq j \leq M) contains the sweetness B_j of the j-th newly delivered fruit.

Output

Print the total sweetness of the K selected fruits on a single line.


Sample Input 1

3 2 3
4
1
7
5
2

Sample Output 1

16

Sample Input 2

2 3 4
5
5
5
1
0

Sample Output 2

16

Sample Input 3

7 6 8
12
3
25
8
17
6
14
9
30
2
17
11
20

Sample Output 3

146

Sample Input 4

12 10 15
100
250
400
50
600
700
150
350
800
450
550
650
500
300
900
200
1000
750
125
875
425
575

Sample Output 4

9525

Sample Input 5

1 1 2
0
1000000000

Sample Output 5

1000000000
C - 商品検索システム

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

配点 : 366

問題文

高橋君はオンラインショップを運営しており、N 個の商品を取り扱っています。商品には 1 から N までの番号が付けられており、商品 i (1 \leq i \leq N) の名前は文字列 S_i で、価格は V_i 円です。異なる商品が同じ名前を持つことや、同じ価格を持つこともあります。

青木君はこのショップの顧客で、Q 件の検索リクエストを送りました。j 番目 (1 \leq j \leq Q) のリクエストでは、整数 X_j を指定し、「価格がちょうど X_j 円の商品をすべて教えてほしい」と頼みます。

しかし、青木君は正確な価格を覚えていないことがあります。そこで高橋君は、青木君の利便性のために、次のルールで検索結果を返すことにしました。

  • 価格がちょうど X_j 円である商品が 1 つ以上存在する場合は、それらの商品の名前を すべて、商品番号の小さい順にスペース区切りで 1 行に出力します。該当する商品の中に同じ名前のものが複数あっても、それぞれ別の商品として 1 回ずつ出力します(つまり名前が重複して出力されることがあります)。
  • 価格がちょうど X_j 円である商品が 1 つも存在しない場合は、「もしかしてこの商品ですか?」という提案として、価格が X_j に最も近い商品を 1 つ選んで出力します。具体的には、価格の差の絶対値 |V_i - X_j| が最小となる商品を候補とします。候補が複数存在する場合(例えば X_j より同じだけ安い商品と高い商品がある場合など)は、その中で商品番号が最も小さいものを選びます。選ばれた商品の名前を 1 つだけ 1 行に出力します。

各リクエストに対する検索結果を求めてください。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq Q \leq 10^5
  • S_i は英小文字のみからなる長さ 1 以上 20 以下の文字列である。
  • 1 \leq V_i \leq 10^9
  • 1 \leq X_j \leq 10^9
  • N, Q, V_i, X_j はすべて整数である。
  • 全リクエストにわたって出力される商品名の文字数の総和(区切りのスペースや改行は含まない)は 10^6 を超えないことが保証される。

入力

N Q
S_1 V_1
S_2 V_2
\vdots
S_N V_N
X_1
X_2
\vdots
X_Q
  • 1 行目には、商品の数 N と検索リクエストの数 Q が、スペース区切りで与えられる。
  • 続く N 行のうち i 番目の行 (1 \leq i \leq N) には、商品 i の名前を表す文字列 S_i と、価格を表す整数 V_i が、スペース区切りで与えられる。
  • 続く Q 行のうち j 番目の行 (1 \leq j \leq Q) には、j 番目の検索リクエストで指定される価格 X_j が与えられる。

出力

Q 件の検索リクエストそれぞれについて、1 行ずつ出力せよ。

  • 価格がちょうど X_j 円である商品が 1 つ以上存在する場合、それらの名前を商品番号の小さい順にスペース区切りで出力せよ。同じ名前の商品が複数該当する場合も、それぞれ別の商品として 1 回ずつ出力せよ。
  • 価格がちょうど X_j 円である商品が存在しない場合、|V_i - X_j| が最小となる商品のうち商品番号が最も小さいものの名前を 1 つだけ出力せよ。

入力例 1

5 4
apple 100
banana 200
cherry 100
date 300
elderberry 500
100
250
300
150

出力例 1

apple cherry
banana
date
apple

入力例 2

4 5
milk 150
bread 150
cheese 300
butter 300
150
300
200
225
450

出力例 2

milk bread
cheese butter
milk
milk
cheese

入力例 3

10 8
notebook 1200
pen 300
eraser 100
ruler 500
pencil 300
marker 800
tape 250
glue 250
scissors 1500
stapler 1200
300
1200
100
700
2000
1
250
999

出力例 3

pen pencil
notebook stapler
eraser
marker
scissors
eraser
tape glue
marker

入力例 4

15 10
alpha 1000
beta 2000
gamma 3000
delta 4000
epsilon 5000
zeta 6000
eta 7000
theta 8000
iota 9000
kappa 10000
lambda 1000
mu 5000
nu 5000
xi 15000
omicron 20000
5000
1000
7500
1
1000000000
10000
15000
12000
20000
3500

出力例 4

epsilon mu nu
alpha lambda
eta
alpha
omicron
kappa
xi
kappa
omicron
gamma

入力例 5

1 1
a 1000000000
1000000000

出力例 5

a

Score : 366 pts

Problem Statement

Takahashi runs an online shop and handles N products. The products are numbered from 1 to N, and product i (1 \leq i \leq N) has the name S_i and a price of V_i yen. Different products may have the same name or the same price.

Aoki is a customer of this shop and has sent Q search requests. In the j-th request (1 \leq j \leq Q), he specifies an integer X_j and asks: "Please tell me all products whose price is exactly X_j yen."

However, Aoki may not remember the exact price. Therefore, for Aoki's convenience, Takahashi decided to return search results according to the following rules:

  • If there exist one or more products whose price is exactly X_j yen, output all of their names on a single line, separated by spaces, in ascending order of product number. Even if multiple matching products have the same name, each is output once as a separate product (meaning names may appear duplicated in the output).
  • If no product has a price of exactly X_j yen, as a suggestion of "Did you mean this product?", select and output one product whose price is closest to X_j. Specifically, the candidates are the products that minimize the absolute difference |V_i - X_j|. If there are multiple candidates (for example, a product that is equally cheaper and one that is equally more expensive than X_j), choose the one with the smallest product number among them. Output only one name of the selected product on a single line.

Determine the search results for each request.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq Q \leq 10^5
  • S_i is a string of length between 1 and 20 inclusive, consisting only of lowercase English letters.
  • 1 \leq V_i \leq 10^9
  • 1 \leq X_j \leq 10^9
  • N, Q, V_i, X_j are all integers.
  • It is guaranteed that the total number of characters of product names output across all requests (excluding separating spaces and newlines) does not exceed 10^6.

Input

N Q
S_1 V_1
S_2 V_2
\vdots
S_N V_N
X_1
X_2
\vdots
X_Q
  • The first line contains the number of products N and the number of search requests Q, separated by a space.
  • The i-th of the following N lines (1 \leq i \leq N) contains the string S_i representing the name of product i and the integer V_i representing its price, separated by a space.
  • The j-th of the following Q lines contains the price X_j specified in the j-th search request.

Output

For each of the Q search requests, output one line.

  • If there exist one or more products whose price is exactly X_j yen, output their names separated by spaces in ascending order of product number. Even if multiple matching products have the same name, output each as a separate product.
  • If no product has a price of exactly X_j yen, output only the name of the product with the smallest product number among those that minimize |V_i - X_j|.

Sample Input 1

5 4
apple 100
banana 200
cherry 100
date 300
elderberry 500
100
250
300
150

Sample Output 1

apple cherry
banana
date
apple

Sample Input 2

4 5
milk 150
bread 150
cheese 300
butter 300
150
300
200
225
450

Sample Output 2

milk bread
cheese butter
milk
milk
cheese

Sample Input 3

10 8
notebook 1200
pen 300
eraser 100
ruler 500
pencil 300
marker 800
tape 250
glue 250
scissors 1500
stapler 1200
300
1200
100
700
2000
1
250
999

Sample Output 3

pen pencil
notebook stapler
eraser
marker
scissors
eraser
tape glue
marker

Sample Input 4

15 10
alpha 1000
beta 2000
gamma 3000
delta 4000
epsilon 5000
zeta 6000
eta 7000
theta 8000
iota 9000
kappa 10000
lambda 1000
mu 5000
nu 5000
xi 15000
omicron 20000
5000
1000
7500
1
1000000000
10000
15000
12000
20000
3500

Sample Output 4

epsilon mu nu
alpha lambda
eta
alpha
omicron
kappa
xi
kappa
omicron
gamma

Sample Input 5

1 1
a 1000000000
1000000000

Sample Output 5

a
D - 肥料の配分

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

配点 : 400

問題文

高橋君は農園で N 本の果樹を育てています。i 番目の果樹 (1 \leq i \leq N) の初期の成長度は A_i です。

高橋君は収穫シーズンに向けて、合計でちょうど K 袋の肥料をこれらの果樹に配分しようとしています。i 番目の果樹に与える肥料の袋数を B_i とするとき、以下の条件を満たすように配分しなければなりません。

  • B_i0 以上の整数である。(1 本の果樹に与える肥料の袋数に上限はありません。また、1 袋も与えない果樹があっても構いません。)
  • B_1 + B_2 + \cdots + B_N = K

肥料を配分した後、i 番目の果樹の成長度は A_i + B_i となります。この農園では、収穫量がすべての果樹の成長度の積で決まることが知られており、収穫量は

(A_1 + B_1) \times (A_2 + B_2) \times \cdots \times (A_N + B_N)

となります。

高橋君が収穫量を最大化するように最適に肥料を配分したとき、その最大の収穫量を 10^9 + 7 で割った余りを求めてください。

ただし、最大化の判定は 10^9 + 7 で割る前の真の値に基づいて行います。すなわち、真の収穫量が最も大きくなるような配分を選び、その収穫量を 10^9 + 7 で割った余りを出力してください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq 10^{18}
  • 1 \leq A_i \leq 10^9
  • 入力はすべて整数である

入力

N K
A_1 A_2 \cdots A_N
  • 1 行目には、果樹の本数を表す整数 N と、肥料の総袋数を表す整数 K が、スペース区切りで与えられる。
  • 2 行目には、各果樹の初期の成長度を表す N 個の整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。

出力

高橋君が収穫量を最大化するように最適に肥料を配分した後の収穫量を 10^9 + 7 で割った余りを、1行で出力せよ。


入力例 1

3 5
1 2 3

出力例 1

48

入力例 2

4 3
2 2 5 8

出力例 2

480

入力例 3

8 100
1 7 3 20 15 2 9 30

出力例 3

505781965

入力例 4

20 1000000000000
1000000000 1 500000000 123456789 987654321 42 314159265 271828182 999999937 100 200 300 400 500 600 700 800 900 1000 12345

出力例 4

134759236

入力例 5

1 1000000000000000000
1000000000

出力例 5

42

Score : 400 pts

Problem Statement

Takahashi is growing N fruit trees on his farm. The initial growth level of the i-th tree (1 \leq i \leq N) is A_i.

In preparation for the harvest season, Takahashi plans to distribute exactly K bags of fertilizer in total among these fruit trees. Let B_i denote the number of bags of fertilizer given to the i-th tree. The distribution must satisfy the following conditions:

  • Each B_i is a non-negative integer. (There is no upper limit on the number of bags given to a single tree. It is also acceptable for some trees to receive no bags at all.)
  • B_1 + B_2 + \cdots + B_N = K

After distributing the fertilizer, the growth level of the i-th tree becomes A_i + B_i. In this farm, it is known that the harvest yield is determined by the product of the growth levels of all fruit trees, so the harvest yield is

(A_1 + B_1) \times (A_2 + B_2) \times \cdots \times (A_N + B_N)

When Takahashi distributes the fertilizer optimally to maximize the harvest yield, find the maximum harvest yield modulo 10^9 + 7.

Note that the maximization is based on the true value before taking the modulo 10^9 + 7. That is, choose the distribution that maximizes the true harvest yield, and output that harvest yield modulo 10^9 + 7.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq 10^{18}
  • 1 \leq A_i \leq 10^9
  • All inputs are integers

Input

N K
A_1 A_2 \cdots A_N
  • The first line contains an integer N representing the number of fruit trees and an integer K representing the total number of bags of fertilizer, separated by a space.
  • The second line contains N integers A_1, A_2, \ldots, A_N representing the initial growth levels of each fruit tree, separated by spaces.

Output

Output in one line the harvest yield modulo 10^9 + 7 after Takahashi distributes the fertilizer optimally to maximize the harvest yield.


Sample Input 1

3 5
1 2 3

Sample Output 1

48

Sample Input 2

4 3
2 2 5 8

Sample Output 2

480

Sample Input 3

8 100
1 7 3 20 15 2 9 30

Sample Output 3

505781965

Sample Input 4

20 1000000000000
1000000000 1 500000000 123456789 987654321 42 314159265 271828182 999999937 100 200 300 400 500 600 700 800 900 1000 12345

Sample Output 4

134759236

Sample Input 5

1 1000000000000000000
1000000000

Sample Output 5

42
E - 休憩時間の最適化

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

配点 : 466

問題文

高橋君は、半開区間 [0, T) で表される営業時間帯に窓口の担当をしています。時刻は整数で扱います。

高橋君は、営業時間中に連続する長さ D の休憩をちょうど 1 回取らなければなりません。休憩の開始時刻を S とすると、休憩中(窓口が閉まっている時間帯)は半開区間 [S, S+D) です。S0 \leq S \leq T - D を満たす整数から選びます。すなわち、休憩は営業時間帯に完全に収まります。休憩中でない時間帯 [0, S) \cup [S+D, T) には窓口は開いています。

窓口を利用したい客が N 人います。初期状態では、i 番目の客(1 \leq i \leq N)は時間帯 [L_i, R_i) の間だけ窓口を訪れます。i 番目の客の手続きが完了しない条件は、その滞在時間帯 [L_i, R_i) が休憩の時間帯 [S, S+D) に完全に含まれること、すなわち S \leq L_i かつ R_i \leq S+D が成り立つことです。言い換えると、滞在時間帯のうち窓口が開いている時刻が 1 つでもあれば手続きは完了します。

高橋君に対して、Q 個の操作が順に与えられます。操作は以下の 2 種類です。

  • 変更操作1 i L R):i 番目の客の滞在時間帯を [L, R) に変更する。この変更は以降のすべての操作に反映される。同じ客に対して複数回の変更操作が行われることもあり、常に最新の変更が有効である。
  • 質問操作2):その時点での各客の滞在時間帯に基づき、手続きが完了しない客の人数を最小にする休憩開始時刻 S を求める。そのような S が複数ある場合は最も小さいものを答える。

制約

  • 1 \leq T \leq 2 \times 10^5
  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq D \leq T
  • 1 \leq Q \leq 10^5
  • N + 2Q \leq 2 \times 10^5
  • 0 \leq L_i < R_i \leq T(初期状態の各客について)
  • 変更操作 1 i L R において、1 \leq i \leq N, 0 \leq L < R \leq T
  • 質問操作 2Q 個の操作の中に 1 つ以上含まれる
  • 入力はすべて整数である

入力

T N D Q
L_1 R_1
L_2 R_2
\vdots
L_N R_N
query_1
query_2
\vdots
query_Q
  • 1 行には、営業時間の長さ T、客の人数 N、休憩の長さ D、操作の個数 Q がスペース区切りで与えられる。
  • 続く N 行には、初期状態での各客の滞在時間帯が与えられる。このうち i 行目(1 \leq i \leq N)には、i 番目の客の滞在時間帯 [L_i, R_i) を表す整数 L_i, R_i がスペース区切りで与えられる。
  • 続く Q 行には、操作が 1 行に 1 つずつ与えられる。各操作は次のいずれかの形式である。
  • 1 i L Ri 番目の客の滞在時間帯を [L, R) に変更する。
  • 2:質問操作を行う。

出力

質問操作 2 が与えられるたびに 1 行出力してください(出力は質問操作の回数だけ行われます)。

各行には、手続きが完了しない客の人数を最小にする最も小さい休憩開始時刻 S と、そのときに手続きが完了しない客の人数を、この順にスペース区切りで出力してください。


入力例 1

10 3 3 5
0 2
4 6
7 10
2
1 2 3 5
2
1 1 7 10
2

出力例 1

1 0
1 0
0 0

入力例 2

8 4 2 6
0 1
2 4
5 8
3 7
2
1 3 6 7
2
1 1 1 3
2
2

出力例 2

1 0
1 0
0 0
0 0

入力例 3

30 10 7 12
0 4
3 8
6 12
9 15
14 18
17 25
20 27
1 29
11 13
24 30
2
1 4 10 16
2
1 7 0 3
1 2 22 30
2
1 10 14 20
2
1 1 5 6
1 5 23 29
2
2

出力例 3

4 0
4 0
1 0
1 0
12 0
12 0

入力例 4

1000 30 120 25
0 50
20 180
100 160
150 300
250 260
270 400
390 510
500 620
610 750
740 900
880 1000
5 995
123 456
321 654
600 601
700 701
800 850
50 70
75 125
200 350
360 365
420 480
490 495
520 700
710 930
940 990
30 900
111 222
333 444
555 666
2
1 5 10 130
1 12 0 120
2
1 15 119 120
1 16 120 121
1 17 121 240
2
1 1 880 950
1 30 0 1000
2
1 8 480 500
1 9 500 510
1 10 510 520
2
1 20 100 220
1 21 221 222
1 22 222 342
2
1 3 340 460
1 4 460 580
2
1 25 0 1
1 26 999 1000
2

出力例 4

101 0
101 0
122 0
122 0
122 0
223 0
223 0
223 0

入力例 5

1 1 1 1
0 1
2

出力例 5

0 1

Score : 466 pts

Problem Statement

Takahashi is in charge of a service counter during business hours represented by the half-open interval [0, T). Time is handled as integers.

During business hours, Takahashi must take exactly one continuous break of length D. If the break starts at time S, then the break period (when the counter is closed) is the half-open interval [S, S+D). S is chosen from integers satisfying 0 \leq S \leq T - D. That is, the break fits completely within business hours. The counter is open during the non-break period [0, S) \cup [S+D, T).

There are N customers who wish to use the counter. Initially, the i-th customer (1 \leq i \leq N) visits the counter only during the time period [L_i, R_i). The condition for the i-th customer's procedure to not be completed is that their stay period [L_i, R_i) is completely contained within the break period [S, S+D), that is, S \leq L_i and R_i \leq S+D hold. In other words, if there exists at least one time within the stay period when the counter is open, the procedure is completed.

Takahashi is given Q operations in order. There are two types of operations:

  • Update operation (1 i L R): Change the stay period of the i-th customer to [L, R). This change is reflected in all subsequent operations. Multiple update operations may be performed on the same customer, and the most recent change is always in effect.
  • Query operation (2): Based on the current stay periods of all customers, determine the break start time S that minimizes the number of customers whose procedures are not completed. If there are multiple such S, output the smallest one.

Constraints

  • 1 \leq T \leq 2 \times 10^5
  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq D \leq T
  • 1 \leq Q \leq 10^5
  • N + 2Q \leq 2 \times 10^5
  • 0 \leq L_i < R_i \leq T (for each customer in the initial state)
  • For update operations 1 i L R: 1 \leq i \leq N, 0 \leq L < R \leq T
  • At least one query operation 2 is included among the Q operations
  • All input values are integers

Input

T N D Q
L_1 R_1
L_2 R_2
\vdots
L_N R_N
query_1
query_2
\vdots
query_Q
  • The first line contains the business hours length T, the number of customers N, the break length D, and the number of operations Q, separated by spaces.
  • The following N lines give the initial stay periods of each customer. The i-th of these lines (1 \leq i \leq N) contains integers L_i and R_i separated by a space, representing the stay period [L_i, R_i) of the i-th customer.
  • The following Q lines each contain one operation. Each operation is in one of the following formats:
  • 1 i L R: Change the stay period of the i-th customer to [L, R).
  • 2: Perform a query operation.

Output

Output one line each time a query operation 2 is given (the number of output lines equals the number of query operations).

On each line, output the smallest break start time S that minimizes the number of customers whose procedures are not completed, followed by the number of customers whose procedures are not completed at that time, separated by a space.


Sample Input 1

10 3 3 5
0 2
4 6
7 10
2
1 2 3 5
2
1 1 7 10
2

Sample Output 1

1 0
1 0
0 0

Sample Input 2

8 4 2 6
0 1
2 4
5 8
3 7
2
1 3 6 7
2
1 1 1 3
2
2

Sample Output 2

1 0
1 0
0 0
0 0

Sample Input 3

30 10 7 12
0 4
3 8
6 12
9 15
14 18
17 25
20 27
1 29
11 13
24 30
2
1 4 10 16
2
1 7 0 3
1 2 22 30
2
1 10 14 20
2
1 1 5 6
1 5 23 29
2
2

Sample Output 3

4 0
4 0
1 0
1 0
12 0
12 0

Sample Input 4

1000 30 120 25
0 50
20 180
100 160
150 300
250 260
270 400
390 510
500 620
610 750
740 900
880 1000
5 995
123 456
321 654
600 601
700 701
800 850
50 70
75 125
200 350
360 365
420 480
490 495
520 700
710 930
940 990
30 900
111 222
333 444
555 666
2
1 5 10 130
1 12 0 120
2
1 15 119 120
1 16 120 121
1 17 121 240
2
1 1 880 950
1 30 0 1000
2
1 8 480 500
1 9 500 510
1 10 510 520
2
1 20 100 220
1 21 221 222
1 22 222 342
2
1 3 340 460
1 4 460 580
2
1 25 0 1
1 26 999 1000
2

Sample Output 4

101 0
101 0
122 0
122 0
122 0
223 0
223 0
223 0

Sample Input 5

1 1 1 1
0 1
2

Sample Output 5

0 1