Interesting Array CodeForces - 483D(思维+线段树)
We’ll call an array of n non-negative integers a[1],?a[2],?…,?a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1?≤?li?≤?ri?≤?n) meaning that value should be equal to qi.
Your task is to find any interesting array of n elements or state that such array doesn’t exist.
Expression x&y means the bitwise AND of numbers x and y. In programming languages C++, Java and Python this operation is represented as “&”, in Pascal — as “and”.
Input
The first line contains two integers n, m (1?≤?n?≤?105, 1?≤?m?≤?105) — the number of elements in the array and the number of limits.
Each of the next m lines contains three integers li, ri, qi (1?≤?li?≤?ri?≤?n, 0?≤?qi?<?230) describing the i-th limit.
Output
If the interesting array exists, in the first line print “YES” (without the quotes) and in the second line print n integers a[1],?a[2],?…,?a[n] (0?≤?a[i]?<?230) decribing the interesting array. If there are multiple answers, print any of them.
If the interesting array doesn’t exist, print “NO” (without the quotes) in the single line.
Examples
Input
3 1
1 3 3
Output
YES
3 3 3
Input
3 2
1 3 3
1 3 2
Output
NO
一個(gè)構(gòu)造題。給m個(gè)操作,使得l到r的值與起來(lái)是q。要求構(gòu)造出這樣的一個(gè)數(shù)組。
我們要求一個(gè)區(qū)間內(nèi)的數(shù)與起來(lái)都是q,那么這個(gè)區(qū)間內(nèi)的數(shù)的二進(jìn)制位上都得是1。那么我們|(或)起來(lái),就相當(dāng)于把所有的位上都變成1。最后再與起來(lái)。如果是0,就不用管了。
代碼如下:
努力加油a啊,(o)/~
總結(jié)
以上是生活随笔為你收集整理的Interesting Array CodeForces - 483D(思维+线段树)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Governing sand(权值线段树
- 下一篇: Codechef REBXOR HYSB