Codeforces 482B. Interesting Array 線段樹,codeforces482b

來源:互聯網
上載者:User

Codeforces 482B. Interesting Array 線段樹,codeforces482b



B. Interesting Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard 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".

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.

Sample test(s)input
3 11 3 3
output
YES3 3 3
input
3 21 3 31 3 2
output
NO

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>using namespace std;const int maxn=100005;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1int a[maxn<<2],n,m;int OR[maxn<<2];struct IA{    int l,r,q;}ia[maxn];void push_up(int rt){    a[rt]=a[rt<<1]&a[rt<<1|1];}void push_down(int rt){    if(OR[rt])    {        a[rt<<1]|=OR[rt]; a[rt<<1|1]|=OR[rt];        OR[rt<<1]|=OR[rt]; OR[rt<<1|1]|=OR[rt];        OR[rt]=0;    }}void update(int L,int R,int C,int l,int r,int rt){    if(L<=l&&r<=R)    {        OR[rt]|=C;        a[rt]|=C;        return ;    }    push_down(rt);    int m=(l+r)/2;    if(L<=m) update(L,R,C,lson);    if(R>m) update(L,R,C,rson);    push_up(rt);}int query(int L,int R,int l,int r,int rt){   if(L<=l&&r<=R)   {       return a[rt];   }   int m=(l+r)/2;   push_down(rt);   int part1=-1,part2=-1;   if(L<=m) part1=query(L,R,lson);   if(R>m) part2=query(L,R,rson);   if(part1==-1) return part2;   if(part2==-1) return part1;   return part1&part2;}vector<int> ans;void showit(int l,int r,int rt){    if(l==r)    {        ans.push_back(a[rt]);        return ;    }    int m=(l+r)/2;    push_down(rt);    showit(lson);    showit(rson);}int main(){    scanf("%d%d",&n,&m);    for(int i=0;i<m;i++)    {        scanf("%d%d%d",&ia[i].l,&ia[i].r,&ia[i].q);        update(ia[i].l,ia[i].r,ia[i].q,1,n,1);    }    bool flag=true;    for(int i=0;i<m&&flag;i++)    {        int Q=query(ia[i].l,ia[i].r,1,n,1);        if(Q!=ia[i].q) flag=false;    }    if(!flag) puts("NO");    else    {        puts("YES");        ans.clear();        showit(1,n,1);        for(int i=0,sz=ans.size();i<sz;i++)            printf("%d ",ans[i]);        putchar(10);    }    return 0;}








聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.