CF2190G.Maximize Determinant
NOI/NOI+/CTSC
通过率:0%
时间限制:4.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
An n×n matrix B is called an interval matrix if for each row i, there exists a contiguous range of columns [li,ri] (1≤li≤ri≤n) filled with ones, while all other elements in the row are zero. Formally, Bi,j=1 if li≤j≤ri, and Bi,j=0 otherwise.
You are given an integer n and an initial interval matrix A, described by n triples (li,ri,ai). The i-th row of A corresponds to the interval [li,ri], and ai is the cost associated with modifying this row.
Let S be the set of all possible n×n interval matrices. We define X as the maximum possible determinant among them: $$ X = \max\limits_{B \in \mathcal{S}} \operatorname{det}(B). $$ (Note that ∣S∣=(2n(n+1))n, as each row can be any valid interval)
Your goal is to transform A into a matrix A′ such that det(A′)=X. To achieve this, you can perform the following operation any number of times:
- Choose a row index i (1≤i≤n) and a new valid interval [L,R] (1≤L≤R≤n).
- Replace the current interval of the i-th row with [L,R].
- The cost of this operation is ai.
Find the minimum total cost required to make the determinant of the matrix equal to X.
一个 n×n 矩阵 B 被称为区间矩阵,如果对每一行 i,均存在一个连续的列区间 [li,ri](其中 1≤li≤ri≤n),使得该区间内的所有元素均为 1,而该行其余位置的元素均为 0。形式化地,Bi,j=1 当且仅当 li≤j≤ri;否则 Bi,j=0。
给定一个整数 n 和一个初始区间矩阵 A,它由 n 个三元组 (li,ri,ai) 描述:第 i 行对应区间 [li,ri],而 ai 是修改该行所需付出的代价。
令 S 表示所有可能的 n×n 区间矩阵构成的集合。我们定义 X 为该集合中矩阵行列式的最大可能值:
X=B∈Smaxdet(B).
(注意:∣S∣=(2n(n+1))n,因为每行可独立选取任意一个合法区间)
你的目标是将 A 变换为某个矩阵 A′,使得 det(A′)=X。为此,你可以执行以下操作任意多次:
- 选择一个行索引 i(1≤i≤n)和一个新的合法区间 [L,R](1≤L≤R≤n);
- 将第 i 行当前的区间替换为 [L,R];
- 此操作的代价为 ai。
求使矩阵行列式等于 X 所需的最小总代价。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤5⋅104). The description of the test cases follows.
The first line of each test case contains a single integer n (1≤n≤106) — the size of the matrix.
The next n lines describe the rows of the matrix A. The i-th of these lines contains three integers li, ri, and ai (1≤li≤ri≤n, 1≤ai≤109) — the interval boundaries and the cost of modifying the i-th row.
It is guaranteed that the sum of n over all test cases does not exceed 106.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤5⋅104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤106)—— 矩阵的大小。
接下来的 n 行描述矩阵 A 的各行。其中第 i 行包含三个整数 li、ri 和 ai(1≤li≤ri≤n,1≤ai≤109)—— 分别表示第 i 行的区间边界及修改该行的代价。
保证所有测试用例中 n 的总和不超过 106。
输出格式
For each test case, print a single integer — the minimum total cost required to make det(A)=X.
对于每个测试用例,输出一个整数——使 det(A)=X 所需的最小总成本。
输入输出样例
输入#1
6 2 1 1 1 2 2 1 2 2 2 1 1 1 1 4 1 4 4 2 2 3 4 4 6 2 4 5 6 1 6 1 5 5 1000 2 4 1000 6 6 1000 3 3 1000 4 4 1000 5 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 5 1 4 15 4 4 14 2 3 16 2 2 14 3 5 15
输出#1
0 2 3 1000 4000000000 14
说明/提示
In the first example, n=2 and it can be shown that X=1. The matrix is A=[1001]. Since det(A)=1, no operations are needed.
In the second example, X is still 1, but the matrix is A=[0110]. The determinant is −1, so we must transform the matrix.
It can be proven that it is impossible to reach a determinant of 1 with a single operation. Therefore, we must modify both rows. One possible sequence of operations is:
\\begin{bmatrix} 0 & 1\\\\1 & 0\\end{bmatrix} \\xrightarrow{i = 2, \\, L = 2, \\, R = 2} \\begin{bmatrix} 0 & 1\\\\0 & 1\\end{bmatrix} \\xrightarrow{i = 1, \\, L = 1, \\, R = 2} \\begin{bmatrix} 1 & 1\\\\0 & 1\\end{bmatrix}The final matrix has a determinant of 1. The total cost is a2+a1=1+1=2, which is the answer.
在第一个例子中,n=2,且可以证明 X=1。矩阵为 A=[1001]。由于 det(A)=1,因此无需任何操作。
在第二个例子中,X 仍为 1,但矩阵为 A=[0110]。其行列式为 −1,因此必须对该矩阵进行变换。
可以证明,仅通过一次操作无法使行列式变为 1。因此,我们必须修改两行。一种可能的操作序列为:
[0110]i=2,L=2,R=2[0011]i=1,L=1,R=2[1011]
最终矩阵的行列式为 1。总代价为 a2+a1=1+1=2,即为答案。
输入解题思路,AI测评打分。不知道怎么写?