ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

线段树之区间更新Interesting Array

2022-07-18 22:33:40  阅读:126  来源: 互联网

标签:rt integers int Interesting 线段 interesting qi Array array


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 liriqi (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 nm (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 liriqi (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 Input

Input
3 1
1 3 3
Output
YES
3 3 3
Input
3 2
1 3 3
1 3 2
Output
NO
#include<cstdio>
using namespace std;

const int N=1e5+5;
int f[N<<2],lazy[N<<2],le[N],ri[N],q[N];

void build(int root,int left,int right){
    
    if(left==right){
        f[root]=lazy[root]=0;
        return;
    }
    
    int mid,rt;
    
    mid=(left+right)>>1;
    rt=root<<1;
    
    build(rt,left,mid);
    build(rt+1,mid+1,right);
}

void pushdown(int root){
    int rt=root<<1;
    
    lazy[rt]|=lazy[root];
    lazy[rt+1]|=lazy[root];
    
    f[rt]|=lazy[root];
    f[rt+1]|=lazy[root];
    
    lazy[root]=0;
}
void update(int root,int left,int right,int uleft,int uright,int val){
    if(uleft<=left&&right<=uright){
        f[root]|=val;
        lazy[root]|=val;
        return;
    }
    
    if(lazy[root]!=0){
        pushdown(root);
    }
    
    int mid,rt;
    mid=(left+right)>>1;
    rt=root<<1;
    
    if(uleft<=mid){
        update(rt,left,mid,uleft,uright,val);
    }
    if(uright>mid){
        update(rt+1,mid+1,right,uleft,uright,val);
    }
    
    f[root]=f[rt]&f[rt+1];
}

int query(int root,int left,int right,int qleft,int qright){
    if(qleft<=left&&right<=qright){
        return f[root];
    }
    
    if(lazy[root]!=0){
        pushdown(root);
    }
    
    int rt,mid,ans;
    ans=-1;
    rt=root<<1;
    mid=(left+right)>>1;
    
    if(qleft<=mid){
        ans&=query(rt,left,mid,qleft,qright);
    }
    if(qright>mid){
        ans&=query(rt+1,mid+1,right,qleft,qright);
    }
    return ans;

}
int main(){
    int n,m,flag;
    
    scanf("%d%d",&n,&m);
    
    for(int i=1;i<=m;i++){
        
        scanf("%d%d%d",&le[i],&ri[i],&q[i]);
        
        update(1,1,n,le[i],ri[i],q[i]);
    }
    
    flag=1;
    
    for(int i=1;i<=m;i++){
        if(query(1,1,n,le[i],ri[i])!=q[i]){
            flag=0;
            break;
        }
    }
    
    if(flag==1){
        printf("YES\n");
        for(int i=1;i<=n;i++){
            printf("%d ",query(1,1,n,i,i));
        }
    }else{
        printf("NO\n");
    }
    return 0;
}

 

标签:rt,integers,int,Interesting,线段,interesting,qi,Array,array
来源: https://www.cnblogs.com/killjoyskr/p/16492275.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有