A - Repeat ACL

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 100 points

Problem Statement

You are given an integer K. Print the string obtained by repeating the string ACL K times and concatenating them.

For example, if K = 3, print ACLACLACL.

Constraints

  • 1 \leq K \leq 5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

K

Output

Print the string obtained by repeating the string ACL K times and concatenating them.


Sample Input 1

3

Sample Output 1

ACLACLACL

配点 : 100

問題文

整数 K が与えられます。 文字列 ACLK 回繰り返してつなげることで得られる文字列を出力してください。

たとえば、K = 3 ならば、 ACLACLACL を出力してください。

制約

  • 1 \leq K \leq 5
  • 入力は全て整数である。

入力

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

K

出力

文字列 ACLK 回繰り返してつなげることで得られる文字列を出力せよ。


入力例 1

3

出力例 1

ACLACLACL
B - Integer Preference

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 200 points

Problem Statement

Snuke likes integers that are greater than or equal to A, and less than or equal to B. Takahashi likes integers that are greater than or equal to C, and less than or equal to D.

Does there exist an integer liked by both people?

Constraints

  • 0 \leq A \leq B \leq 10^{18}
  • 0 \leq C \leq D \leq 10^{18}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print Yes or No.


Sample Input 1

10 30 20 40

Sample Output 1

Yes

For example, both like 25.


Sample Input 2

10 20 30 40

Sample Output 2

No

配点 : 200

問題文

すぬけ君は A 以上 B 以下の整数が好きです。 高橋君は C 以上 D 以下の整数が好きです。

どちらも好きな整数は存在しますか?

制約

  • 0 \leq A \leq B \leq 10^{18}
  • 0 \leq C \leq D \leq 10^{18}
  • 入力は全て整数である。

入力

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

A B C D

出力

Yes または No と出力せよ。


入力例 1

10 30 20 40

出力例 1

Yes

たとえば、どちらも 25 が好きです。


入力例 2

10 20 30 40

出力例 2

No
C - Connect Cities

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 300 points

Problem Statement

There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i.

Snuke can perform the following operation zero or more times:

  • Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities.

After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times).

What is the minimum number of roads he must build to achieve the goal?

Constraints

  • 2 \leq N \leq 100,000
  • 1 \leq M \leq 100,000
  • 1 \leq A_i < B_i \leq N
  • No two roads connect the same pair of cities.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
:
A_M B_M

Output

Print the answer.


Sample Input 1

3 1
1 2

Sample Output 1

1

Initially, there are three cities, and there is a road between City 1 and City 2.

Snuke can achieve the goal by building one new road, for example, between City 1 and City 3. After that,

  • We can travel between 1 and 2 directly.
  • We can travel between 1 and 3 directly.
  • We can travel between 2 and 3 by following both roads (2 - 1 - 3).

配点 : 300

問題文

N 個の都市 (1 番から N 番まで) と M 個の双方向道路 (1 番から M 番まで) があります。 道路 i は都市 A_i と都市 B_i を結びます。

すぬけ君は、以下の操作を 0 回以上行うことができます。

  • 道路で直接結ばれていない二つの異なる都市を選び、間に道路を作る。

操作を終えた後、どの都市からどの都市へも (場合によっては複数回) 道路をたどることで到達できるようになっていなければいけません。

目的を達成するために、最低何個の道路を作ればよいですか?

制約

  • 2 \leq N \leq 100,000
  • 1 \leq M \leq 100,000
  • 1 \leq A_i < B_i \leq N
  • どの二つの道路も同じ都市のペアを結ばない。
  • 入力は全て整数である。

入力

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

N M
A_1 B_1
:
A_M B_M

出力

答えを出力せよ。


入力例 1

3 1
1 2

出力例 1

1

最初に、都市が三つあり、都市 1 と都市 2 の間に道があります。

すぬけ君は、たとえば都市 1 と都市 3 の間に道を作ることによって目的を達成できます。 道を作った後、

  • 都市 12 の間を直接旅行できます。
  • 都市 13 の間を直接旅行できます。
  • 都市 23 の間を両方の道を通ることで旅行できます。 (2 - 1 - 3)
D - Flat Subsequence

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 400 points

Problem Statement

You are given a sequence A_1, A_2, ..., A_N and an integer K.

Print the maximum possible length of a sequence B that satisfies the following conditions:

  • B is a (not necessarily continuous) subsequence of A.
  • For each pair of adjacents elements of B, the absolute difference of the elements is at most K.

Constraints

  • 1 \leq N \leq 300,000
  • 0 \leq A_i \leq 300,000
  • 0 \leq K \leq 300,000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1
A_2
:
A_N

Output

Print the answer.


Sample Input 1

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

Sample Output 1

7

For example, B = (1, 4, 3, 6, 9, 7, 4) satisfies the conditions.

  • It is a subsequence of A = (1, 5, 4, 3, 8, 6, 9, 7, 2, 4).
  • All of the absolute differences between two adjacent elements (|1-4|, |4-3|, |3-6|, |6-9|, |9-7|, |7-4|) are at most K = 3.

配点 : 400

問題文

数列 A_1, A_2, ..., A_N と整数 K が与えられます。

以下の条件を満たす数列 B の長さとして考えられる最大値を出力してください。

  • BA の (連続とは限らない) 部分列である。
  • どの B の隣り合う要素の差の絶対値も K 以下である。

制約

  • 1 \leq N \leq 300,000
  • 0 \leq A_i \leq 300,000
  • 0 \leq K \leq 300,000
  • 入力は全て整数である。

入力

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

N K
A_1
A_2
:
A_N

出力

答えを出力せよ。


入力例 1

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

出力例 1

7

たとえば、 B = (1, 4, 3, 6, 9, 7, 4) は条件を満たします。

  • これは A = (1, 5, 4, 3, 8, 6, 9, 7, 2, 4) の部分列です。
  • 全ての隣り合う要素の差の絶対値 (|1-4|, |4-3|, |3-6|, |6-9|, |9-7|, |7-4|) は K = 3 以下です。
E - Replace Digits

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 500 points

Problem Statement

You have a string S of length N. Initially, all characters in S are 1s.

You will perform queries Q times. In the i-th query, you are given two integers L_i, R_i and a character D_i (which is a digit). Then, you must replace all characters from the L_i-th to the R_i-th (inclusive) with D_i.

After each query, read the string S as a decimal integer, and print its value modulo 998,244,353.

Constraints

  • 1 \leq N, Q \leq 200,000
  • 1 \leq L_i \leq R_i \leq N
  • 1 \leq D_i \leq 9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N Q
L_1 R_1 D_1
:
L_Q R_Q D_Q

Output

Print Q lines. In the i-th line print the value of S after the i-th query, modulo 998,244,353.


Sample Input 1

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

Sample Output 1

11222211
77772211
77333333
72333333
72311333

Sample Input 2

200000 1
123 456 7

Sample Output 2

641437905

Don't forget to take the modulo.

配点 : 500

問題文

長さ N の文字列 S があります。 最初は S のすべての文字が 1 です。

クエリを Q 回処理します。 i 番目のクエリでは、整数 L_i, R_i と文字 (数字) D_i が与えられます。 L_i 番目から R_i 番目までの全ての文字を D_i に書き換えてください。

各クエリの後、S を十進法で書かれた整数とみなし、その値を 998,244,353 でわった余りを出力してください。

制約

  • 1 \leq N, Q \leq 200,000
  • 1 \leq L_i \leq R_i \leq N
  • 1 \leq D_i \leq 9
  • 入力は全て整数である。

入力

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

N Q
L_1 R_1 D_1
:
L_Q R_Q D_Q

出力

Q 行出力せよ。 i 行目には i 番目のクエリの後の S の値を modulo 998,244,353 で出力せよ。


入力例 1

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

出力例 1

11222211
77772211
77333333
72333333
72311333

入力例 2

200000 1
123 456 7

出力例 2

641437905

あまりをとるのを忘れないでください。

F - Heights and Pairs

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 600 points

Problem Statement

There are 2N people numbered 1 through 2N. The height of Person i is h_i.

How many ways are there to make N pairs of people such that the following conditions are satisfied? Compute the answer modulo 998,244,353.

  • Each person is contained in exactly one pair.
  • For each pair, the heights of the two people in the pair are different.

Two ways are considered different if for some p and q, Person p and Person q are paired in one way and not in the other.

Constraints

  • 1 \leq N \leq 50,000
  • 1 \leq h_i \leq 100,000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
h_1
:
h_{2N}

Output

Print the answer.


Sample Input 1

2
1
1
2
3

Sample Output 1

2

There are two ways:

  • Form the pair (Person 1, Person 3) and the pair (Person 2, Person 4).
  • Form the pair (Person 1, Person 4) and the pair (Person 2, Person 3).

Sample Input 2

5
30
10
20
40
20
10
10
30
50
60

Sample Output 2

516

配点 : 600

問題文

2N 人の人 (1 番から 2N 番まで) がいます。 人 i の身長は h_i です。

以下の条件を満たすように、N 個の人のペアを作る方法は何通りありますか? 答えを modulo 998,244,353 で求めてください。

  • どの人もちょうど一つのペアに含まれる。
  • どのペアも、そのペアに属する二人の人の身長が異なる。

ある pq に対し、人 p と人 q がペアになったかどうかが異なる場合、異なる方法であるとみなします。

制約

  • 1 \leq N \leq 50,000
  • 1 \leq h_i \leq 100,000
  • 入力は全て整数である。

入力

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

N
h_1
:
h_{2N}

出力

答えを出力せよ。


入力例 1

2
1
1
2
3

出力例 1

2

二通りあります:

  • ペア (人 1, 人 3) とペア (人 2, 人 4) を作る。
  • ペア (人 1, 人 4) とペア (人 2, 人 3) を作る。

入力例 2

5
30
10
20
40
20
10
10
30
50
60

出力例 2

516