#P3588. [POI 2015 R2] 沙漠 Desert

    ID: 2639 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2015线段树POISpecial Judge记忆化搜索拓扑排序

[POI 2015 R2] 沙漠 Desert

Description

Given a positive integer sequence aa of length nn, where each number is in the range 11 to 10910^9. You are told ss of the numbers, and given mm pieces of information. Each piece contains three numbers l,r,kl, r, k followed by kk positive integers, meaning that among al,al+1,,ar1,ara_l, a_{l+1}, \ldots, a_{r-1}, a_r, each of the values at those kk positions is strictly greater than each of the values at the remaining rl+1kr - l + 1 - k positions (strictly greater; no equality).

Construct any sequence that satisfies all the conditions, or determine that there is no solution.

Input Format

The first line contains three positive integers n,s,mn, s, m (1sn1051 \leq s \leq n \leq 10^5, 1m2×1051 \leq m \leq 2 \times 10^5). The next ss lines each contain two positive integers pi,dip_i, d_i, meaning api=dia_{p_i} = d_i. It is guaranteed that the pip_i are in increasing order.

The next mm lines: each line begins with three positive integers li,ri,kil_i, r_i, k_i (1li<rin1 \leq l_i < r_i \leq n, 1kirili1 \leq k_i \leq r_i - l_i), followed by kik_i positive integers x1,x2,,xkix_1, x_2, \ldots, x_{k_i} (lix1<x2<<xkiril_i \leq x_1 < x_2 < \cdots < x_{k_i} \leq r_i), indicating that in ali,ali+1,,aria_{l_i}, a_{l_i+1}, \ldots, a_{r_i}, each of these kik_i positions has a value strictly greater than each of the other rili+1kir_i - l_i + 1 - k_i positions. (ki3×105\sum k_i \leq 3 \times 10^5.)

Output Format

If there is no solution, output NIE. Otherwise, output TAK on the first line, and on the second line output nn positive integers, the sequence aa in order.

5 2 2
2 7
5 3
1 4 2 2 3
4 5 1 4
TAK
6 7 1000000000 6 3
3 2 1
2 3
3 5
1 3 1 2

NIE

2 1 1
1 1000000000
1 2 1 2
NIE

Hint

Original title: Pustynia.

Two additional sample tests are provided and can be downloaded from the attachments.

Translated by ChatGPT 5