CF796F.Sequence Recovery

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Zane once had a good sequence a consisting of n integers _a_1, _a_2, ..., a__n — but he has lost it.

A sequence is said to be good if and only if all of its integers are non-negative and do not exceed 109 in value.

However, Zane remembers having played around with his sequence by applying m operations to it.

There are two types of operations:

1. Find the maximum value of integers with indices i such that l ≤ i ≤ r, given l and r.

2. Assign d as the value of the integer with index k, given k and d.

After he finished playing, he restored his sequence to the state it was before any operations were applied. That is, sequence a was no longer affected by the applied type 2 operations. Then, he lost his sequence at some time between now and then.

Fortunately, Zane remembers all the operations and the order he applied them to his sequence, along with the distinct results of all type 1 operations. Moreover, among all good sequences that would produce the same results when the same operations are applied in the same order, he knows that his sequence a has the greatest cuteness.

We define cuteness of a sequence as the bitwise OR result of all integers in such sequence. For example, the cuteness of Zane's sequence a is _a_1 OR _a_2 OR ... OR a__n.

Zane understands that it might not be possible to recover exactly the lost sequence given his information, so he would be happy to get any good sequence b consisting of n integers _b_1, _b_2, ..., b__n that:

1. would give the same results when the same operations are applied in the same order, and

2. has the same cuteness as that of Zane's original sequence a.

If there is such a sequence, find it. Otherwise, it means that Zane must have remembered something incorrectly, which is possible.

泽恩曾经拥有一个由 nn 个整数 a1, a2, …, ana_1,\,a_2,\,\dots,\,a_n 构成的“好序列” aa——但如今它已丢失。

当且仅当序列中所有整数均为非负数且不超过 10910^9 时,该序列被称为“好序列”。

然而,泽恩记得自己曾对该序列执行了 mm 次操作。

操作共分两类:

  1. 给定 ll 和 rr,求下标 ii 满足 l≤i≤rl \le i \le r 的所有整数中的最大值;

  2. 给定 kk 和 dd,将下标为 kk 的整数赋值为 dd。

完成所有操作后,他将序列恢复为初始状态(即所有类型 2 的赋值操作均被撤销),此时序列 aa 不再受这些赋值操作影响。随后,在此之后的某个时刻,他丢失了该序列。

幸运的是,泽恩完整记得所有操作及其执行顺序,也记得所有类型 1 操作所得的互不相同的查询结果。此外,在所有能产生完全相同操作结果(即在相同顺序下执行相同操作时得到相同类型 1 查询结果)的“好序列”中,他知道自己的原始序列 aa 具有最大的“可爱度”。

我们定义一个序列的“可爱度”为该序列中所有整数按位或(bitwise OR)的结果。例如,泽恩的序列 aa 的可爱度为 a1 OR a2 OR … OR ana_1\ \text{OR}\ a_2\ \text{OR}\ \dots\ \text{OR}\ a_n。

泽恩明白,仅凭上述信息可能无法唯一确定丢失的序列,因此他愿意接受任意一个满足以下条件的“好序列” b=(b1, b2, …, bn)b = (b_1,\,b_2,\,\dots,\,b_n):

  1. 在相同顺序下执行相同操作时,能得到完全相同的类型 1 查询结果;

  2. 其可爱度与泽恩原始序列 aa 的可爱度相等。

若存在这样的序列,请找出一个;否则说明泽恩必定在记忆中出现了错误(这是可能的)。

输入格式

The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the number of integers in Zane's original sequence and the number of operations that have been applied to the sequence, respectively.

The i-th of the following m lines starts with one integer t__i () — the type of the i-th operation.

If the operation is type 1 (t__i = 1), then three integers l__i, r__i, and x__i follow (1 ≤ l__i ≤ r__i ≤ n, 0 ≤ x__i ≤ 109) — the leftmost index to be considered, the rightmost index to be considered, and the maximum value of all integers with indices between l__i and r__i, inclusive, respectively.

If the operation is type 2 (t__i = 2), then two integers k__i and d__i follow (1 ≤ k__i ≤ n, 0 ≤ d__i ≤ 109) — meaning that the integer with index k__i should become d__i after this operation.

It is guaranteed that x__i ≠ x__j for all pairs (i, j) where 1 ≤ i < j ≤ m and t__i = t__j = 1.

The operations are given in the same order they were applied. That is, the operation that is given first was applied first, the operation that is given second was applied second, and so on.

第一行包含两个整数 nn 和 mm(1≤n,m≤3⋅1051 \leq n, m \leq 3 \cdot 10^5)—— 分别表示 Zane 原始序列中整数的个数,以及已对该序列执行的操作次数。

接下来的 mm 行中,第 ii 行以一个整数 tit_i()开头——表示第 ii 个操作的类型。

若该操作为类型 1(ti=1t_i = 1),则随后给出三个整数 lil_i、rir_i 和 xix_i(1≤li≤ri≤n1 \leq l_i \leq r_i \leq n,0≤xi≤1090 \leq x_i \leq 10^9)—— 分别表示需考虑的最左下标、最右下标,以及下标在 lil_i 到 rir_i(含端点)之间的所有整数的最大值。

若该操作为类型 2(ti=2t_i = 2),则随后给出两个整数 kik_i 和 did_i(1≤ki≤n1 \leq k_i \leq n,0≤di≤1090 \leq d_i \leq 10^9)—— 表示经过此次操作后,下标为 kik_i 的整数应变为 did_i。

保证对所有满足 1≤i<j≤m1 \leq i < j \leq m 且 ti=tj=1t_i = t_j = 1 的数对 (i,j)(i, j),均有 xi≠xjx_i \neq x_j。

所给操作的顺序即为其实际应用顺序:即最先给出的操作最先执行,第二个给出的操作第二个执行,依此类推。

输出格式

If there does not exist a valid good sequence, print "NO" (without quotation marks) in the first line.

Otherwise, print "YES" (without quotation marks) in the first line, and print n space-separated integers _b_1, _b_2, ..., b__n (0 ≤ b__i ≤ 109) in the second line.

If there are multiple answers, print any of them.

如果不存在合法的“好序列”,则在第一行输出 "NO"(不带引号)。

否则,在第一行输出 "YES"(不带引号),并在第二行输出 n 个用空格分隔的整数 _b_₁, _b_₂, ..., b__n(0 ≤ b__i ≤ 10⁹)。

如果有多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    5 4
    1 1 5 19
    1 2 5 1
    2 5 100
    1 1 5 100

    输出#1

    YES
    19 0 0 0 1
  • 输入#2

    5 2
    1 1 5 0
    1 1 5 100

    输出#2

    NO

说明/提示

In the first sample, it is easy to verify that this good sequence is valid. In particular, its cuteness is 19 OR 0 OR 0 OR 0 OR 1  =  19.

In the second sample, the two operations clearly contradict, so there is no such good sequence.

在第一个样例中,容易验证该“好序列”是合法的。特别地,其“可爱值”为 19 OR 0 OR 0 OR 0 OR 1=1919\ \text{OR}\ 0\ \text{OR}\ 0\ \text{OR}\ 0\ \text{OR}\ 1 = 19。

在第二个样例中,两次操作明显矛盾,因此不存在这样的“好序列”。

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

首页