Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 800 点
問題文
(1,2,\ldots,N) の順列 P=(P_1,P_2,\ldots,P_N) が与えられます.
あなたは以下の操作を 0 回以上行うことができます.
- 整数 i (1 \leq i \leq N-1) を選び,P_i と P_{i+1} の値を入れ替える.
ただしここで,以下の条件を両方満たす必要がある.
- 操作の直前において,P_i>P_{i+1} が成立する.
- 操作の前後で,P の最長増加部分列の長さが変化しない.
操作後の P としてありうる順列のうち,辞書順で最小のものを求めてください.
1 つの入力につき,T 個のテストケースを解いてください.
数列の辞書順とは?
数列 S = (S_1,S_2,\ldots,S_{|S|}) が数列 T = (T_1,T_2,\ldots,T_{|T|}) より辞書順で小さいとは,下記の 1. と 2. のどちらかが成り立つことを言います. ここで,|S|, |T| はそれぞれ S, T の長さを表します.
- |S| \lt |T| かつ (S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|}).
- ある整数 1 \leq i \leq \min\lbrace |S|, |T| \rbrace が存在して,下記の 2 つがともに成り立つ.
- (S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1})
- S_i が T_i より(数として)小さい.
制約
- 1 \leq T \leq 250000
- 1 \leq N \leq 250000
- P は (1,2,\ldots,N) の順列である
- 1 つの入力における N の総和は 250000 を超えない
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる.
T case_1 case_2 \vdots case_T
各テストケースは以下の形式で与えられる.
N P_1 P_2 \cdots P_N
出力
各テストケースに対し,答えを出力せよ.
入力例 1
4 3 2 3 1 3 3 2 1 7 5 7 6 4 2 3 1 15 6 4 5 14 15 1 3 9 12 8 10 2 7 13 11
出力例 1
2 1 3 3 2 1 5 2 1 7 6 4 3 4 1 6 5 3 2 9 8 7 14 12 10 15 13 11
1 つめのテストケースについて説明します. P=(2,3,1) に対しては,i=1 では操作できませんが,i=2 を選んで操作することが可能です. 操作後 P=(2,1,3) となりますが,ここから更に操作することはできません. P=(2,3,1) からスタートして到達できる順列の中で辞書順最小のものは (2,1,3) になります.
Score : 800 points
Problem Statement
You are given a permutation P=(P_1,P_2,\ldots,P_N) of (1,2,\ldots,N).
You can perform the following operation zero or more times:
- Choose an integer i (1 \leq i \leq N-1) and swap the values of P_i and P_{i+1}.
Here, both of the following conditions must be satisfied:
- P_i>P_{i+1} holds immediately before the operation.
- The operation does not change the length of the longest increasing subsequence of P.
Find the lexicographically smallest permutation among all permutations that can be obtained as P after operations.
Solve T test cases for each input.
What is lexicographic order on sequences?
A sequence S = (S_1,S_2,\ldots,S_{|S|}) is lexicographically smaller than a sequence T = (T_1,T_2,\ldots,T_{|T|}) if either of the following conditions 1. and 2. holds. Here, |S| and |T| represent the lengths of S and T, respectively.
- |S| \lt |T| and (S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|}).
- There exists an integer 1 \leq i \leq \min\lbrace |S|, |T| \rbrace such that both of the following hold:
- (S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1}).
- S_i is (numerically) smaller than T_i.
Constraints
- 1 \leq T \leq 250000
- 1 \leq N \leq 250000
- P is a permutation of (1,2,\ldots,N).
- The sum of N over all test cases in each input does not exceed 250000.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
T case_1 case_2 \vdots case_T
Each test case is given in the following format:
N P_1 P_2 \cdots P_N
Output
For each test case, output the answer.
Sample Input 1
4 3 2 3 1 3 3 2 1 7 5 7 6 4 2 3 1 15 6 4 5 14 15 1 3 9 12 8 10 2 7 13 11
Sample Output 1
2 1 3 3 2 1 5 2 1 7 6 4 3 4 1 6 5 3 2 9 8 7 14 12 10 15 13 11
Let us explain the first test case. For P=(2,3,1), the operation cannot be performed with i=1, but can be performed with i=2. After the operation, P=(2,1,3), and no further operations can be performed from here. Among the permutations reachable starting from P=(2,3,1), the lexicographically smallest one is (2,1,3).
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 1000 点
問題文
maroon くんの夏休みは Day 1 から Day N までの N 日間あります. また夏休み期間中には,1 から M までの番号のついた M 本の映画の上映が予定されており,映画 i は Day L_i から Day R_i まで見られます.
映画全体の部分集合 s に対し,f(s) を以下のように定義します.
- maroon くんが 1 日に 1 本以下の映画を見られるとき,夏休みを通して見られる s 内の映画の本数の最大値を f(s) とする. なお,同じ映画を複数回見てもそれは 1 本とカウントするものとする.
s としてあり得る集合は 2^M 通りあります. それら全てに対する f(s) の総和を 998244353 で割ったあまりを求めてください.
制約
- 1 \leq N \leq 100
- 1 \leq M \leq N \times (N+1) /2
- 1 \leq L_i \leq R_i \leq N
- (L_i,R_i) \neq (L_j,R_j) (i \neq j)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる.
N M L_1 R_1 L_2 R_2 \vdots L_M R_M
出力
答えを出力せよ.
入力例 1
2 3 1 1 2 2 1 2
出力例 1
11
ほとんどの s に対して,f(s)=|s| が成り立ちます. 唯一の例外は s=\{1,2,3\} で,このとき f(s)=2 となります. すべての s に対する f(s) の総和は 11 です.
入力例 2
3 3 1 1 2 2 3 3
出力例 2
12
入力例 3
4 10 3 3 2 4 2 3 4 4 3 4 1 3 1 1 2 2 1 2 1 4
出力例 3
3796
入力例 4
7 20 1 3 4 5 3 3 3 5 1 4 4 7 2 3 1 7 6 7 4 6 2 4 6 6 3 6 2 5 7 7 3 4 2 2 5 5 2 6 1 2
出力例 4
7113137
Score : 1000 points
Problem Statement
Maroon's summer vacation lasts N days from Day 1 through Day N. During the vacation, M movies numbered from 1 through M are scheduled to be screened, and movie i can be watched from Day L_i through Day R_i.
For a subset s of all movies, define f(s) as follows:
- f(s) is the maximum number of movies in s that can be watched throughout the vacation when he can watch at most one movie per day. Here, watching the same movie multiple times counts as one movie.
There are 2^M possible sets for s. Find the sum, modulo 998244353, of f(s) over all of them.
Constraints
- 1 \leq N \leq 100
- 1 \leq M \leq N \times (N+1) /2
- 1 \leq L_i \leq R_i \leq N
- (L_i,R_i) \neq (L_j,R_j) (i \neq j)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M L_1 R_1 L_2 R_2 \vdots L_M R_M
Output
Output the answer.
Sample Input 1
2 3 1 1 2 2 1 2
Sample Output 1
11
f(s)=|s| holds for most s. The only exception is s=\{1,2,3\}, where f(s)=2. The sum of f(s) over all s is 11.
Sample Input 2
3 3 1 1 2 2 3 3
Sample Output 2
12
Sample Input 3
4 10 3 3 2 4 2 3 4 4 3 4 1 3 1 1 2 2 1 2 1 4
Sample Output 3
3796
Sample Input 4
7 20 1 3 4 5 3 3 3 5 1 4 4 7 2 3 1 7 6 7 4 6 2 4 6 6 3 6 2 5 7 7 3 4 2 2 5 5 2 6 1 2
Sample Output 4
7113137
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 1400 点
問題文
1 以上 N 以下の整数が書かれたボールがあります. 具体的には,整数 i (1 \leq i \leq N) の書かれたボールが A_i 個あります.
S=A_1+A_2+\cdots+A_N と定義します. ここで,S が正の偶数であることが保証されます. S 個のボールを S/2 個のペアに分けます. ペアになった 2 つのボールに書かれた整数は異なる必要があります. なお,この問題の制約下でこのようなペア分けが可能であることが証明できます.
各ペアについて,以下の操作を行います.
- 2 つのボールに書かれた整数がそれぞれ x,y (x < y) であるとする. これらのボールに書かれている数を,それぞれ x+0.5,y-0.5 で置き換える.
すべてのペアについて操作を終えたあと,同じ数が書かれているボールの個数の最大値を d とおきます. d としてありうる最小値を求めてください.
1 つの入力につき,T 個のテストケースを解いてください.
制約
- 1 \leq T \leq 125000
- 2 \leq N \leq 250000
- 0 \leq A_i \leq 10^9
- S=A_1+A_2+\cdots+A_N は正の偶数である
- A_i \leq S/2
- 1 つの入力における N の総和は 250000 を超えない
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる.
T case_1 case_2 \vdots case_T
各テストケースは以下の形式で与えられる.
N A_1 A_2 \cdots A_N
出力
各テストケースに対し,答えを出力せよ.
入力例 1
4 4 1 2 2 1 4 2 2 5 1 7 101 2 203 304 5 106 107 20 239276621 320064891 910500852 164832983 245532750 198319686 715892722 967824729 769431650 80707349 459924867 257261830 777045523 583882654 950300098 438099970 322288793 532405019 256358887 45539860
出力例 1
2 6 203 613287276
1 つ目のテストケースについて考えます. 整数 x,y の書かれたボールのペアを (x,y) で表すことにします.
例えば,(1,3),(2,3),(2,4) とペア分けすると,操作後にボール書かれている数は 1.5,2.5,2.5,2.5,2.5,3.5 になります. 同じ数が書かれているボールの個数の最大値は d=4 です.
一方,(1,2),(2,3),(3,4) とペア分けすると,操作後にボール書かれている数は 1.5,1.5,2.5,2.5,3.5,3.5 になります. 同じ数が書かれているボールの個数の最大値は d=2 となります.
d を 2 より小さくすることはできないので,2 が答えになります.
Score : 1400 points
Problem Statement
There are balls with integers from 1 to N written on them. Specifically, there are A_i balls with integer i (1 \leq i \leq N) written on them.
Define S=A_1+A_2+\cdots+A_N. Here, it is guaranteed that S is a positive even number. Divide the S balls into S/2 pairs. The integers written on the two balls in a pair must be different. It can be proved that such pairing is possible under the constraints of this problem.
For each pair, perform the following operation:
- Let the integers written on the two balls be x and y (x < y). Replace the numbers written on these balls with x+0.5 and y-0.5, respectively.
After completing the operation for all pairs, let d be the maximum number of balls with the same number written on them. Find the minimum possible value of d.
Solve T test cases for each input.
Constraints
- 1 \leq T \leq 125000
- 2 \leq N \leq 250000
- 0 \leq A_i \leq 10^9
- S=A_1+A_2+\cdots+A_N is a positive even number.
- A_i \leq S/2
- The sum of N over all test cases in each input does not exceed 250000.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
T case_1 case_2 \vdots case_T
Each test case is given in the following format:
N A_1 A_2 \cdots A_N
Output
For each test case, output the answer.
Sample Input 1
4 4 1 2 2 1 4 2 2 5 1 7 101 2 203 304 5 106 107 20 239276621 320064891 910500852 164832983 245532750 198319686 715892722 967824729 769431650 80707349 459924867 257261830 777045523 583882654 950300098 438099970 322288793 532405019 256358887 45539860
Sample Output 1
2 6 203 613287276
Consider the first test case. Let (x,y) denote a pair of balls with integers x,y written on them.
For example, if we pair as (1,3),(2,3),(2,4), the numbers written on the balls after the operation are 1.5,2.5,2.5,2.5,2.5,3.5. The maximum number of balls with the same number written on them is d=4.
On the other hand, if we pair as (1,2),(2,3),(3,4), the numbers written on the balls after the operation are 1.5,1.5,2.5,2.5,3.5,3.5. The maximum number of balls with the same number written on them is d=2.
d cannot be made smaller than 2, so the answer is 2.
Time Limit: 6 sec / Memory Limit: 1024 MiB
配点 : 1400 点
問題文
整数 N が与えられます. 以下の条件を満たす根付き木 T を,BFS-ordered 木と呼ぶことにします.
- T は 1 から N までの番号がついた N 頂点からなる根付き木である.
- 根は頂点 1 である.
- 各頂点 i (2 \leq i \leq N) の親を頂点 p_i とするとき,p_2 \leq p_3 \leq \cdots \leq p_N が成立する.
各 d=1,2,\ldots,(N-1) に対し,以下の条件を満たす BFS-ordered 木 T の個数を 998244353 で割ったあまりを求めてください.
- T において,頂点 (N-1) と頂点 N の距離がちょうど d である. より正確に述べれば,T を無向木として見て頂点 (N-1) と頂点 N を結ぶパスを考えたとき,そのパス内の辺の個数がちょうど d である.
制約
- 2 \leq N \leq 10^6
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる.
N
出力
N-1 行出力せよ. i 行目には,d=i のときの答えを出力せよ.
入力例 1
2
出力例 1
1
入力例 2
3
出力例 2
1 1
入力例 3
4
出力例 3
2 2 1
入力例 4
5
出力例 4
5 5 3 1
入力例 5
20
出力例 5
477638700 477638700 178405156 178405139 109639972 108787985 86366256 69212603 43976909 22930595 9698374 3355343 947052 215710 38814 5324 524 33 1
Score : 1400 points
Problem Statement
You are given an integer N. We call a rooted tree T satisfying the following conditions a BFS-ordered tree.
- T is a rooted tree with N vertices numbered from 1 to N.
- The root is vertex 1.
- Let vertex p_i be the parent of each vertex i (2 \leq i \leq N). Then, p_2 \leq p_3 \leq \cdots \leq p_N holds.
For each d=1,2,\ldots,(N-1), find the number, modulo 998244353, of BFS-ordered trees T satisfying the following condition.
- The distance between vertices (N-1) and N in T is exactly d. More precisely, when considering T as an undirected tree and the path connecting vertices (N-1) and N, the number of edges in that path is exactly d.
Constraints
- 2 \leq N \leq 10^6
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
Output
Output N-1 lines. The i-th line should contain the answer for d=i.
Sample Input 1
2
Sample Output 1
1
Sample Input 2
3
Sample Output 2
1 1
Sample Input 3
4
Sample Output 3
2 2 1
Sample Input 4
5
Sample Output 4
5 5 3 1
Sample Input 5
20
Sample Output 5
477638700 477638700 178405156 178405139 109639972 108787985 86366256 69212603 43976909 22930595 9698374 3355343 947052 215710 38814 5324 524 33 1
Time Limit: 8 sec / Memory Limit: 1024 MiB
配点 : 2000 点
問題文
整数 N,C,K が与えられます. 長さ N の整数列 x=(x_1,x_2,\ldots,x_N) であって,以下の条件を満たすものの個数を 998244353 で割ったあまりを求めてください.
- 1 \leq x_i \leq N (1 \leq i \leq N)
- 1 から N までの番号がついた N 頂点からなる無向グラフを考える. このグラフには N 本の辺があり,i 番目の辺は頂点 i と頂点 x_i を結ぶものとする. このとき,グラフの連結成分の個数がちょうど C である.
- i<x_i を満たす i の個数がちょうど K である.
制約
- 1 \leq N \leq 250000
- 1 \leq C \leq N
- 0 \leq K \leq N-1
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる.
N C K
出力
答えを出力せよ.
入力例 1
3 1 2
出力例 1
6
条件を満たす x は以下の 6 つです.
- x=(2,3,1)
- x=(2,3,2)
- x=(2,3,3)
- x=(3,3,1)
- x=(3,3,2)
- x=(3,3,3)
入力例 2
3 2 2
出力例 2
0
入力例 3
6 3 0
出力例 3
225
入力例 4
20 4 7
出力例 4
476087626
入力例 5
250000 2025 125000
出力例 5
410390562
Score : 2000 points
Problem Statement
You are given integers N, C, and K. Find the number, modulo 998244353, of length-N integer sequences x=(x_1,x_2,\ldots,x_N) satisfying the following conditions.
- 1 \leq x_i \leq N (1 \leq i \leq N).
- Consider an undirected graph with N vertices numbered from 1 to N. This graph has N edges, and the i-th edge connects vertices i and x_i. Then, the number of connected components of the graph is exactly C.
- The number of i satisfying i<x_i is exactly K.
Constraints
- 1 \leq N \leq 250000
- 1 \leq C \leq N
- 0 \leq K \leq N-1
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N C K
Output
Output the answer.
Sample Input 1
3 1 2
Sample Output 1
6
The following six sequences x satisfy the conditions:
- x=(2,3,1)
- x=(2,3,2)
- x=(2,3,3)
- x=(3,3,1)
- x=(3,3,2)
- x=(3,3,3)
Sample Input 2
3 2 2
Sample Output 2
0
Sample Input 3
6 3 0
Sample Output 3
225
Sample Input 4
20 4 7
Sample Output 4
476087626
Sample Input 5
250000 2025 125000
Sample Output 5
410390562