B. Interesting Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output
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.
InputThe 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.
OutputIf 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.
Sample test(s) input3 1 1 3 3output
YES 3 3 3input
3 2 1 3 3 1 3 2output
NO題意:給m個區間及區間內每個數&值,問存不存在這樣一個數列滿足。
分析:對於每一個區間[l,r]&值為q,那麼說明這個區間每一個數都得或q。用線段樹維護下區間更新,,注意向下更新是或,向上合並是與。最後查詢下各自的區間看值是否滿足。滿足再輸出對應的單個點的值。
/** * @author neko01 */ //#pragma comment(linker, /STACK:102400000,102400000) #include#include #include #include #include #include #include #include #include #include