Codeforces 482B Interesting Array

Source: Internet
Author: User

Description

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 T O 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 are represented as "&", in Pascal-as "and".

Input

The first line contains-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 <) describing the i-th limit.

Output

If the interesting array exists, in the first line print "YES" (without the quotes) and the second line print n integer S a[1], a[2], ..., A[n] (0≤a[i] <) decribing the interesting array. If There is multiple answers, print any of them.

If the interesting array doesn ' t exist, print "NO" (without the quotes) in the.

Sample Input Input

3 1
1) 3 3
Output
YES
3 3 3
Input
3 2
1 3 3
1 3 2
Output
NO


/** Test Instructions: give n number and m operation, each operation shape such as: l R x, means A[l] & A[l+1] & ... &a[r] = x;
                    Q: Is there a sequence that satisfies the given operation?
                There are: output Yes, and output this sequence.
    No: Output No.
                Analysis: Consider A[i], for all operations that contain it, if the operation is X, the binary of X is 1 bits, and A[i] is also 1.
                The other bits are 0 sure to be satisfied.
                So what we can do with all x or, what we get is a[i].
                The segment tree interval operation is not much to say.
   Finally, the test sequence meets the requirements. */#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <
Set> using namespace std;
const int N = 100001;
int ans[n],mak[n<<2];
int ql[n],qr[n],qx[n];
    void pushdown (int rt) {if (!mak[rt]) return;
    mak[rt<<1]|=mak[rt];
    mak[rt<<1|1]|=mak[rt];
MAK[RT] = 0;
        } void Update (int l, int r, int x, int l, int r, int rt) {if (l<=l && r>=r) {mak[rt]|=x;
    Return
    } int m = l+r>>1;
    if (l<=m) update (L,R,X,L,M,RT&LT;&LT;1);
if (r>m) update (L,R,X,M+1,R,RT&LT;&LT;1|1); }
void Solve (int l, int r, int rt) {if (l==r) {ans[l] = Mak[rt];
    return;
    } int m = l+r>>1;
    Pushdown (RT);
    Solve (l,m,rt<<1);
Solve (m+1,r,rt<<1|1);
        } void Build (int l, int r, int rt) {if (l==r) {Mak[rt] = ans[l];
    return;
    } int m = l+r>>1;
    Build (l,m,rt<<1);
    Build (m+1,r,rt<<1|1);
MAK[RT] = mak[rt<<1]&mak[rt<<1|1];
    } int query (int l, int r, int l, int r, int rt) {if (l<=l && r>=r) return MAK[RT];
    int m = l+r>>1;
    int s = (1<<30)-1;
    if (l<=m) s&=query (l,r,l,m,rt<<1);
    if (r>m) s&=query (l,r,m+1,r,rt<<1|1);
return s;
    } int main () {int i,j,k,m,n;
        while (scanf ("%d%d", &n,&m) ==2) {memset (mak,0,sizeof (MAK));
            for (I=1; i<=m; i++) {scanf ("%d%d%d", ql+i,qr+i,qx+i);
        Update (ql[i],qr[i],qx[i],1,n,1); } Solve (1,n,1);
        Build (1,n,1);
        bool OK = true;
            for (I=1; i<=m; i++) {int a = query (ql[i],qr[i],1,n,1);
                if (A!=qx[i]) {OK = false;
            Break
            }} if (!ok) {puts ("NO");
        Continue
        };
        Puts ("YES");
        for (I=1; i<n; i++) printf ("%d", ans[i]);
    printf ("%d\n", Ans[n]);
} return 0;
 }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.