QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100

#3703. 区间查询

统计

frog 有一个 $\{1, 2, \dots, n\}$ 的排列 $p(1), p(2), \dots, p(n)$。 她还有 $m_1 + m_2$ 条关于该排列的记录 $(a_i, b_i, c_i)$。

  • 对于 $1 \leq i \leq m_1$,$(a_i, b_i, c_i)$ 表示 $\min\{p(a_i), p(a_i + 1), \dots, p(b_i)\} = c_i$;
  • 对于 $m_1 < i \leq m_1 + m_2$,$(a_i, b_i, c_i)$ 表示 $\max\{p(a_i), p(a_i + 1), \dots, p(b_i)\} = c_i$。

请找出一个符合上述记录的排列,或者指出这些记录自相矛盾。如果存在多个合法的排列,请找出字典序最小的那一个。

排列 $p(1), p(2), \dots, p(n)$ 的字典序小于 $q(1), q(2), \dots, q(n)$ 当且仅当存在 $1 \leq i \leq n$ 使得 $p(i) < q(i)$,且对于所有 $1 \leq j < i$,都有 $p(j) = q(j)$。

输入包含多组测试数据。对于每组测试数据:

第一行包含 $3$ 个整数 $n, m_1, m_2$ ($1 \leq n \leq 50, 0 \leq m_1 + m_2 \leq 50$)。 接下来的 $(m_1 + m_2)$ 行,每行包含 $3$ 个整数 $a_i, b_i, c_i$ ($1 \leq a_i \leq b_i \leq n, 1 \leq c_i \leq n$)。

对于每组测试数据,输出 $n$ 个整数 $p(1), p(2), \dots, p(n)$,表示字典序最小的排列;如果记录自相矛盾,则输出 -1

样例

输入格式 1

5 1 1
1 5 1
1 5 5
3 1 1
1 2 2
1 2 2

输出格式 1

1 2 3 4 5
-1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.