A - ABC Preparation

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

高橋君は、プログラミングコンテストを何回か開くことにしました。
コンテストを 1 回開くには、100 点問題、200 点問題、300 点問題、400 点問題が 1 問ずつ必要です。
100, 200, 300, 400 点問題の案がそれぞれ A_1, A_2, A_3, A_4 個あるとき、コンテストを最大で何回開けるでしょうか?
なお、同じ問題案は 1 度しか使えません。

制約

  • 1 \le A_i \le 100 (1 \le i \le 4)
  • 入力は全て整数

入力

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

A_1 \hspace{7pt} A_2 \hspace{7pt} A_3 \hspace{7pt} A_4

出力

コンテストを開催可能な最大回数を表す整数を出力せよ。


入力例 1

5 3 7 11

出力例 1

3

100, 200, 300, 400 点問題の案を 3 つずつ使って、コンテストを 3 回開くことができます。
200 点問題の案が 3 つしかないため、4 回開くことはできません。


入力例 2

100 100 1 100

出力例 2

1

問題案が 1 つでも足りないとコンテストは開催できません。

Score : 100 points

Problem Statement

Takahashi has decided to hold some number of programming contests.
Holding one contest requires one 100-point problem, one 200-point problem, one 300-point problem, and one 400-point problem.
When he has A_1, A_2, A_3, and A_4 drafts of 100-, 200-, 300-, and 400-point problems, respectively, at most how many contests can he hold?
The same draft can be used only once.

Constraints

  • 1 \le A_i \le 100 (1 \le i \le 4)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

A_1 \hspace{7pt} A_2 \hspace{7pt} A_3 \hspace{7pt} A_4

Output

Print an integer representing the maximum number of contests that can be held.


Sample Input 1

5 3 7 11

Sample Output 1

3

By using three drafts for each slot, he can hold three contests. He has just three drafts for 200-point problems, so he cannot hold four.


Sample Input 2

100 100 1 100

Sample Output 2

1

A contest cannot be held even if there is just one missing slot.

B - Smartphone Addiction

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

高橋君のスマートフォンのバッテリー容量は N [mAh] であり、時刻 0.5, 1.5, 2.5, \ldots に、つまり時刻 n + 0.5\,(n は整数) を迎える度にバッテリー残量が 1 [mAh] ずつ減少します。
高橋君はスマートフォンを満充電した状態で時刻 0 に外出し、途中で M 回カフェを訪れ、時刻 T に帰宅します。
i 回目に訪れるカフェには時刻 A_i から時刻 B_i まで滞在します。カフェに滞在している間はスマートフォンを充電するため、バッテリー残量は減少せず、代わりに時刻 n + 0.5\,(n は整数) を迎える度に 1 [mAh] ずつ増加します。ただし既にバッテリー残量がバッテリー容量と等しい場合、バッテリー残量は増えも減りもしません。
高橋君が途中でスマートフォンのバッテリー残量が 0 になることなく帰宅することができるかを判定してください。

制約

  • 1 \le N \le 10^9
  • 1 \le M \le 1000
  • 1 \le T \le 10^9
  • 0 \lt A_1 \lt B_1 \lt A_2 \lt B_2 \lt A_3 \lt B_3 \lt \dots \lt A_M \lt B_M \lt T
  • 入力は全て整数

入力

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

N M T
A_1 B_1
A_2 B_2
A_3 B_3
\hspace{15pt} \vdots
A_M B_M

出力

高橋君が途中でスマートフォンのバッテリー残量が 0 になることなく帰宅することができるなら Yes を、できないなら No を出力せよ。


入力例 1

10 2 20
9 11
13 17

出力例 1

Yes

バッテリー残量は以下のように変化します。

  • 時刻 0 (出発時): 10 [mAh]
  • 時刻 9 (1 番目のカフェへの滞在開始時): 1 [mAh]
  • 時刻 11 (1 番目のカフェへの滞在終了時): 3 [mAh] (カフェでは充電を行います)
  • 時刻 13 (2 番目のカフェへの滞在開始時): 1 [mAh]
  • 時刻 17 (2 番目のカフェへの滞在終了時): 5 [mAh]
  • 時刻 20 (帰宅時): 2 [mAh]

この過程で一度もバッテリー残量が 0 になっていないので、Yes を出力します。


入力例 2

10 2 20
9 11
13 16

出力例 2

No

2 番目のカフェへの滞在をバッテリー残量 1 [mAh] の状態で開始するところまでは入出力例 1 と同じです。
時刻 162 番目のカフェの滞在を終了したときのバッテリー残量は 4 [mAh] になります。
そして時刻 19.5 にバッテリー残量が 0 になってしまうので、No を出力します。


入力例 3

15 3 30
5 8
15 17
24 27

出力例 3

Yes

帰宅するときにはバッテリー残量が 1 [mAh] になっていますが、 1 度も 0 にはなっていません。


入力例 4

20 1 30
20 29

出力例 4

No

時刻 19.5 でバッテリー残量が 0 になります。


入力例 5

20 1 30
1 10

出力例 5

No

バッテリー残量がバッテリー容量と等しい場合は、カフェにいてもバッテリー残量が増えないことに注意して下さい。

Score : 200 points

Problem Statement

The battery of Takahashi's smartphone has N mAh capacity. At time 0.5, 1.5, 2.5, and so on (that is, at time n + 0.5 for every integer n), the battery charge decreases by 1 mAh.
Takahashi will leave his house with his phone fully charged at time 0, visit a cafe M times, and return home at time T.
He will stay at the i-th cafe from time A_i to time B_i. During this stay, he charges his phone, so the battery charge does not decrease. Instead, at time n + 0.5 for every integer n, it increases by 1. However, if it is already equal to the battery capacity, it does not increase nor decrease.
Determine whether he can return home without the battery charge dropping to 0 on the way.

Constraints

  • 1 \le N \le 10^9
  • 1 \le M \le 1000
  • 1 \le T \le 10^9
  • 0 \lt A_1 \lt B_1 \lt A_2 \lt B_2 \lt A_3 \lt B_3 \lt \dots \lt A_M \lt B_M \lt T
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M T
A_1 B_1
A_2 B_2
A_3 B_3
\hspace{15pt} \vdots
A_M B_M

Output

If Takahashi can return home without the battery charge dropping to 0 on the way, print Yes; otherwise, print No.


Sample Input 1

10 2 20
9 11
13 17

Sample Output 1

Yes

The battery charge changes as follows:

  • Time 0 (leaving home): 10 mAh
  • Time 9 (the beginning of the stay at the first cafe): 1 mAh
  • Time 11 (the end of the stay at the first cafe): 3 mAh (He charges his phone in a cafe.)
  • Time 13 (the beginning of the stay at the second cafe): 1 mAh
  • Time 17 (the end of the stay at the second cafe): 5 mAh
  • Time 20 (getting home): 2 mAh

During this process, the battery charge never drops to 0, so we print Yes.


Sample Input 2

10 2 20
9 11
13 16

Sample Output 2

No

This case is the same as Sample Input/Output 1 until he starts his stay at the second cafe with 1 mAh charge.
When he ends his stay there at time 16, the battery charge is 4 mAh.
Then at time 19.5, it drops to 0, so we print No.


Sample Input 3

15 3 30
5 8
15 17
24 27

Sample Output 3

Yes

The battery charge drops to 1 mAh when he gets home, but it never drops to 0 on the way.


Sample Input 4

20 1 30
20 29

Sample Output 4

No

The battery charge drops to 0 at time 19.5.


Sample Input 5

20 1 30
1 10

Sample Output 5

No

Note that when the battery charge is equal to the battery capacity, staying at a cafe does not increase the battery charge.

C - Duodecim Ferra

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

長さ L の鉄の棒が東西方向に横たわっています。この棒を 11 箇所で切断して、12 本に分割します。このとき分割後の各棒の長さが全て正整数になるように分割しなければなりません。
分割のしかたが何通りあるかを求めてください。二つの分割の方法は、一方で分割されているが他方で分割されていない位置が存在する場合に、そしてその場合に限って区別されます。
なお、この問題の制約下で答えは 2^{63} 未満であることが証明できます。

制約

  • 12 \le L \le 200
  • L は整数

入力

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

L

出力

分割のしかたが何通りあるかを表す整数を出力せよ。


入力例 1

12

出力例 1

1

全て長さ 1 の棒になるように切断する 1 通りです。


入力例 2

13

出力例 2

12

ちょうど一つだけ長さ 2 の棒ができますが、切断後の 12 本のうち西から何番目の棒が長さ 2 になるように切断するかで 12 通りの切断方法があります。


入力例 3

17

出力例 3

4368

Score : 300 points

Problem Statement

There is an iron bar of length L lying east-west. We will cut this bar at 11 positions to divide it into 12 bars. Here, each of the 12 resulting bars must have a positive integer length.
Find the number of ways to do this division. Two ways to do the division are considered different if and only if there is a position cut in only one of those ways.
Under the constraints of this problem, it can be proved that the answer is less than 2^{63}.

Constraints

  • 12 \le L \le 200
  • L is an integer.

Input

Input is given from Standard Input in the following format:

L

Output

Print the number of ways to do the division.


Sample Input 1

12

Sample Output 1

1

There is only one way: to cut the bar into 12 bars of length 1 each.


Sample Input 2

13

Sample Output 2

12

Just one of the resulting bars will be of length 2. We have 12 options: one where the westmost bar is of length 2, one where the second bar from the west is of length 2, and so on.


Sample Input 3

17

Sample Output 3

4368
D - Stamp

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

左右方向一列に N 個のマスが並んでいます。左から i 番目のマスをマス i と呼ぶことにします。
この N 個のマスのうち、マス A_1, マス A_2, マス A_3, \dots, マス A_MM 個のマスは青色で、それ以外のマスは白色です。(M = 0 の可能性もあり、その場合青色のマスはありません。)
あなたは一回だけ、正整数 k を一つ選んで幅 k のハンコを作ります。幅 k のハンコを一回使用すると、N 個のマスのうち連続する k マスを選び、それらを赤色に塗り替えることができます。ただしその際、その k 個のマスの中に青色のマスが入っていてはなりません。
k とハンコの使用方法をうまく決めた時、最小で何回ハンコを使用すれば、白色のマスが存在しない状態にすることができるでしょうか。

制約

  • 1 \le N \le 10^9
  • 0 \le M \le 2 \times 10^5
  • 1 \le A_i \le N
  • A_i は互いに異なる
  • 入力は全て整数

入力

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

N M
A_1 \hspace{7pt} A_2 \hspace{7pt} A_3 \hspace{5pt} \dots \hspace{5pt} A_M

出力

最小で何回ハンコを使用すれば白色のマスが存在しない状態にすることができるかを表す整数を出力せよ。


入力例 1

5 2
1 3

出力例 1

3

k として 1 を選び、3 つある白色マスを一回に一つずつ赤色に塗り替えると 3 回で目的を達成でき、最適です。
k として 2 以上を選ぶと、ハンコの使用時に k 個のマスの中に青色のマスが入っていてはいけないという制約のためにマス 2 がどうやっても赤色に塗り替えられなくなってしまいます。


入力例 2

13 3
13 3 9

出力例 2

6

例えば k = 2 とし、以下のようにハンコを使用すると最適です。

  • マス 1, 2 を赤色に塗り替える
  • マス 4, 5 を赤色に塗り替える
  • マス 5, 6 を赤色に塗り替える
  • マス 7, 8 を赤色に塗り替える
  • マス 10, 11 を赤色に塗り替える
  • マス 11, 12 を赤色に塗り替える

ハンコの使用時に選ぶ連続する k 個のマスは青色のマスを含んではいけませんが、既に赤色のマスを含むのは問題ありません。


入力例 3

5 5
5 2 1 4 3

出力例 3

0

最初から白色のマスが存在しない場合、ハンコは 1 回も使わなくてよいです。


入力例 4

1 0

出力例 4

1

M = 0 の可能性もあります。

Score : 400 points

Problem Statement

There are N squares arranged in a row from left to right. Let Square i be the i-th square from the left.
M of those squares, Square A_1, A_2, A_3, \ldots, A_M, are blue; the others are white. (M may be 0, in which case there is no blue square.)
You will choose a positive integer k just once and make a stamp with width k. In one use of a stamp with width k, you can choose k consecutive squares from the N squares and repaint them red, as long as those k squares do not contain a blue square.
At least how many uses of the stamp are needed to have no white square, with the optimal choice of k and the usage of the stamp?

Constraints

  • 1 \le N \le 10^9
  • 0 \le M \le 2 \times 10^5
  • 1 \le A_i \le N
  • A_i are pairwise distinct.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 \hspace{7pt} A_2 \hspace{7pt} A_3 \hspace{5pt} \dots \hspace{5pt} A_M

Output

Print the minimum number of uses of the stamp needed to have no white square.


Sample Input 1

5 2
1 3

Sample Output 1

3

If we choose k = 1 and repaint the three white squares one at a time, three uses are enough, which is optimal.
Choosing k = 2 or greater would make it impossible to repaint Square 2, because of the restriction that does not allow the k squares to contain a blue square.


Sample Input 2

13 3
13 3 9

Sample Output 2

6

One optimal strategy is choosing k = 2 and using the stamp as follows:

  • Repaint Squares 1, 2 red.
  • Repaint Squares 4, 5 red.
  • Repaint Squares 5, 6 red.
  • Repaint Squares 7, 8 red.
  • Repaint Squares 10, 11 red.
  • Repaint Squares 11, 12 red.

Note that, although the k consecutive squares chosen when using the stamp cannot contain blue squares, they can contain already red squares.


Sample Input 3

5 5
5 2 1 4 3

Sample Output 3

0

If there is no white square from the beginning, we do not have to use the stamp at all.


Sample Input 4

1 0

Sample Output 4

1

M may be 0.

E - Sequence Matching

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

長さ N の整数列 A と、長さ M の整数列 B があります。
高橋君は A から、いくつかの要素を取り除き、残った要素をそのままの順番で繋げることで新たな数列 A' を作ります。(一つも取り除かなくても、全部取り除いても構いません。)
B についても同様に、いくつかの要素を取り除き、残った要素をそのままの順番で繋げることで新たな数列 B' を作ります。(一つも取り除かなくても、全部取り除いても構いません。)
このとき、|A'| = |B'| となるような取り除き方をします。(数列 s について |s|s の長さを表します。)
A, B から取り除いた合計要素数を x とし、1 \le i \le |A'| かつ {A'}_i \neq {B'}_i を満たす整数 i の数を y とするとき、x + y として考えられる最小の値を求めてください。

制約

  • 1 \le N, M \le 1000
  • 1 \le A_i, B_i \le 10^9
  • 入力は全て整数

入力

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

N M
A_1 \hspace{7pt} A_2 \hspace{7pt} A_3 \hspace{5pt} \dots \hspace{5pt} A_N
B_1 \hspace{7pt} B_2 \hspace{7pt} B_3 \hspace{5pt} \dots \hspace{5pt} B_M

出力

x + y として考えられる最小の値を出力せよ。


入力例 1

4 3
1 2 1 3
1 3 1

出力例 1

2

A から A_4 を削除して A' を作り、B からは何も削除せず B' を作ることにすると、x = 1 となります。
また、このとき 1 \le i \le |A'| かつ {A'}_i \neq {B'}_i を満たす整数 i2 の一つのみなので y = 1 となります。そして x + y2 となり、これが最小です。


入力例 2

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

出力例 2

3

A からは何も取り除かず、B からは B_4, B_62 要素を削除すると x = 2, y = 1 となり、 x + y3 で、これが最小です。


入力例 3

5 5
1 1 1 1 1
2 2 2 2 2

出力例 3

5

A からも B からも何も取り除かないことも許されます。

Score : 500 points

Problem Statement

We have an integer sequence A of length N and an integer sequence B of length M.
Takahashi will make a new sequence A' by removing some elements (possibly zero or all) from A and concatenating the remaining elements.
Similarly, he will make another new sequence B' by removing some elements (possibly zero or all) from B and concatenating the remaining elements.
Here, he will remove elements so that |A'| = |B'|. (|s| denotes the length of s for a sequence s.)
Let x be the total number of elements removed from A and B, and y be the number of integers i such that 1 \le i \le |A'| and {A'}_i \neq {B'}_i. Print the minimium possible value of x + y.

Constraints

  • 1 \le N, M \le 1000
  • 1 \le A_i, B_i \le 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 \hspace{7pt} A_2 \hspace{7pt} A_3 \hspace{5pt} \dots \hspace{5pt} A_N
B_1 \hspace{7pt} B_2 \hspace{7pt} B_3 \hspace{5pt} \dots \hspace{5pt} B_M

Output

Print the minimum possible value of x + y.


Sample Input 1

4 3
1 2 1 3
1 3 1

Sample Output 1

2

If we make A' by removing A_4 from A, and B' by removing nothing from B, x will be 1.
Here, there is just one integer i such that 1 \le i \le |A'| and {A'}_i \neq {B'}_i: i = 2, so y will be 1, and x + y will be 2, which is the minimum possible value.


Sample Input 2

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

Sample Output 2

3

If we remove nothing from A and remove B_4, B_6 from B, we have x = 2, y = 1, and x + y = 3, which is the minimum possible value.


Sample Input 3

5 5
1 1 1 1 1
2 2 2 2 2

Sample Output 3

5

It is allowed to remove nothing from both A and B.

F - Range Xor Query

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 600

問題文

長さ N の整数列 A があります。
あなたは今からこの数列について Q 個のクエリを処理します。i 番目のクエリでは、 T_i, X_i, Y_i が与えられるので、以下の処理をしてください。

  • T_i = 1 のとき
    A_{X_i}A_{X_i} \oplus Y_i で置き換える
  • T_i = 2 のとき
    A_{X_i} \oplus A_{X_i + 1} \oplus A_{X_i + 2} \oplus \dots \oplus A_{Y_i} を出力する

ただし a \oplus bab のビット単位 xor を表します。

ビット単位 xor とは

整数 A, B のビット単位 xor 、A \oplus B は、以下のように定義されます。

  • A \oplus B を二進表記した際の 2^k (k \geq 0) の位の数は、A, B を二進表記した際の 2^k の位の数のうち一方のみが 1 であれば 1、そうでなければ 0 である。
例えば、3 \oplus 5 = 6 となります (二進表記すると: 011 \oplus 101 = 110)。

制約

  • 1 \le N \le 300000
  • 1 \le Q \le 300000
  • 0 \le A_i \lt 2^{30}
  • T_i1 または 2
  • T_i = 1 なら 1 \le X_i \le N かつ 0 \le Y_i \lt 2^{30}
  • T_i = 2 なら 1 \le X_i \le Y_i \le N
  • 入力は全て整数

入力

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

N Q
A_1 \hspace{7pt} A_2 \hspace{7pt} A_3 \hspace{5pt} \dots \hspace{5pt} A_N
T_1 X_1 Y_1
T_2 X_2 Y_2
T_3 X_3 Y_3
\hspace{22pt} \vdots
T_Q X_Q Y_Q

出力

T_i = 2 であるような各クエリについて、答えを 1 行に 1 つずつ、順に出力せよ。


入力例 1

3 4
1 2 3
2 1 3
2 2 3
1 2 3
2 2 3

出力例 1

0
1
2

1 個目のクエリでは 1 \oplus 2 \oplus 3 = 0 を出力します。
2 個目のクエリでは 2 \oplus 3 = 1 を出力します。
3 個目のクエリでは A_22 \oplus 3 = 1 で置き換えられます。
4 個目のクエリでは 1 \oplus 3 = 2 を出力します。


入力例 2

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

出力例 2

1
0
5
3
0

Score : 600 points

Problem Statement

We have an integer sequence A of length N.
You will process Q queries on this sequence. In the i-th query, given values T_i, X_i, and Y_i, do the following:

  • If T_i = 1, replace A_{X_i} with A_{X_i} \oplus Y_i.
  • If T_i = 2, print A_{X_i} \oplus A_{X_i + 1} \oplus A_{X_i + 2} \oplus \dots \oplus A_{Y_i}.

Here, a \oplus b denotes the bitwise XOR of a and b.

What is bitwise XOR?

The bitwise XOR of integers A and B, A \oplus B, is defined as follows:

  • When A \oplus B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.
For example, 3 \oplus 5 = 6. (In base two: 011 \oplus 101 = 110.)

Constraints

  • 1 \le N \le 300000
  • 1 \le Q \le 300000
  • 0 \le A_i \lt 2^{30}
  • T_i is 1 or 2.
  • If T_i = 1, then 1 \le X_i \le N and 0 \le Y_i \lt 2^{30}.
  • If T_i = 2, then 1 \le X_i \le Y_i \le N.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N Q
A_1 \hspace{7pt} A_2 \hspace{7pt} A_3 \hspace{5pt} \dots \hspace{5pt} A_N
T_1 X_1 Y_1
T_2 X_2 Y_2
T_3 X_3 Y_3
\hspace{22pt} \vdots
T_Q X_Q Y_Q

Output

For each query with T_i = 2 in the order received, print the response in its own line.


Sample Input 1

3 4
1 2 3
2 1 3
2 2 3
1 2 3
2 2 3

Sample Output 1

0
1
2

In the first query, we print 1 \oplus 2 \oplus 3 = 0.
In the second query, we print 2 \oplus 3 = 1.
In the third query, we replace A_2 with 2 \oplus 3 = 1.
In the fourth query, we print 1 \oplus 3 = 2.


Sample Input 2

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

Sample Output 2

1
0
5
3
0