CF1697F.Too Many Constraints

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are asked to build an array aa, consisting of nn integers, each element should be from 11 to kk.

The array should be non-decreasing (ai≤ai+1a_i \le a_{i+1} for all ii from 11 to n−1n-1).

You are also given additional constraints on it. Each constraint is of one of three following types:

  • 1 i x1~i~x: aia_i should not be equal to xx;
  • 2 i j x2~i~j~x: ai+aja_i + a_j should be less than or equal to xx;
  • 3 i j x3~i~j~x: ai+aja_i + a_j should be greater than or equal to xx.

Build any non-decreasing array that satisfies all constraints or report that no such array exists.

你需要构造一个由 nn 个整数组成的数组 aa,其中每个元素取值范围为 11 到 kk(含端点)。

该数组必须是非递减的(即对所有从 11 到 n−1n-1 的 ii,满足 ai≤ai+1a_i \le a_{i+1})。

此外,你还需满足若干额外约束条件。每条约束属于以下三种类型之一:

  • 1 i x1~i~x:aia_i 不能等于 xx;
  • 2 i j x2~i~j~x:ai+aja_i + a_j 必须 小于或等于 xx;
  • 3 i j x3~i~j~x:ai+aja_i + a_j 必须 大于或等于 xx。

请构造出任意一个满足所有约束的非递减数组;若不存在这样的数组,则报告无解。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of testcases.

The first line of each testcase contains three integers n,mn, m and kk (2≤n≤2⋅1042 \le n \le 2 \cdot 10^4; 0≤m≤2⋅1040 \le m \le 2 \cdot 10^4; 2≤k≤102 \le k \le 10).

The ii-th of the next mm lines contains a description of a constraint. Each constraint is of one of three following types:

  • 1 i x1~i~x (1≤i≤n1 \le i \le n; 1≤x≤k1 \le x \le k): aia_i should not be equal to xx;
  • 2 i j x2~i~j~x (1≤i<j≤n1 \le i \lt j \le n; 2≤x≤2⋅k2 \le x \le 2 \cdot k): ai+aja_i + a_j should be less than or equal to xx;
  • 3 i j x3~i~j~x (1≤i<j≤n1 \le i \lt j \le n; 2≤x≤2⋅k2 \le x \le 2 \cdot k): ai+aja_i + a_j should be greater than or equal to xx.

The sum of nn over all testcases doesn't exceed 2⋅1042 \cdot 10^4. The sum of mm over all testcases doesn't exceed 2⋅1042 \cdot 10^4.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

每个测试用例的第一行包含三个整数 nn、mm 和 kk(2≤n≤2⋅1042 \le n \le 2 \cdot 10^4;0≤m≤2⋅1040 \le m \le 2 \cdot 10^4;2≤k≤102 \le k \le 10)。

接下来的 mm 行中,第 ii 行描述一条约束。每条约束属于以下三种类型之一:

  • 1 i x1~i~x(1≤i≤n1 \le i \le n;1≤x≤k1 \le x \le k):aia_i 不应等于 xx;
  • 2 i j x2~i~j~x(1≤i<j≤n1 \le i \lt j \le n;2≤x≤2⋅k2 \le x \le 2 \cdot k):ai+aja_i + a_j 应小于或等于 xx;
  • 3 i j x3~i~j~x(1≤i<j≤n1 \le i \lt j \le n;2≤x≤2⋅k2 \le x \le 2 \cdot k):ai+aja_i + a_j 应大于或等于 xx。

所有测试用例的 nn 之和不超过 2⋅1042 \cdot 10^4。所有测试用例的 mm 之和不超过 2⋅1042 \cdot 10^4。

输出格式

For each testcase, determine if there exists a non-decreasing array that satisfies all conditions. If there is no such array, then print -1. Otherwise, print any valid array — nn integers from 11 to kk.

对于每个测试用例,判断是否存在一个非递减数组满足所有条件。如果不存在这样的数组,则输出 -1;否则,输出任意一个合法数组——即由 nn 个介于 11 到 kk 之间的整数组成的数组。

输入输出样例

  • 输入#1

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

    输出#1

    1 2 3 4
    1 3
    -1
    1 2 2 5 5

输入解题思路,AI测评打分。不知道怎么写?

首页