Codeforces Round #275 (Div. 1)B(线段树+位运算)

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 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 ≤ 1051 ≤ 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 ≤ n0 ≤ 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 1
1 3 3
output
YES
3 3 3
input
3 2
1 3 3
1 3 2
output
NO

题意:给出很多个区间,使得每个区间的值相与为qi,要求构造出n个数使得每个区间都满足

思路:比如第i个区间,如果里面所有的数相与要为qi,那么将这些数写成二进制以后qi为1的位要全为1,剩下的位至少有一个要为0

            那么我可以初始化n个数为0,先把所有位必须为1的构造出来,对于m个区间可以用线段树完成,只做懒操作,区间的值相或(先不向上更新)

            然后再从1到n扫一遍线段树,把每个位置的数都更新到位,然后再次对于m个区间,现在只做向上更新(区间的值相与),然后只要所有区间的值都等于qi就能够成功构

            造出来

#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
#include 
      
      
       
       
#include 
       
       
         #include 
        
          using namespace std; #define lson l,m,o<<1 #define rson m+1,r,o<<1|1 const int MAXN = 100005; const int INF = ~0U>>1; int is[MAXN<<2]; int laz[MAXN<<2]; void build() { memset(is,0,sizeof(is)); memset(laz,0,sizeof(laz)); } void pushdown(int o) { if(laz[o]){ laz[o<<1]|=laz[o]; laz[o<<1|1]|=laz[o]; is[o<<1]|=laz[o]; is[o<<1|1]|=laz[o]; laz[o]=0; } } void update(int l,int r,int o,int L,int R,int q) { if(L<=l&&r<=R){ is[o]|=q; laz[o]|=q; return; } int m=l+r>>1; pushdown(o); if(L<=m)update(lson,L,R,q); if(m 
         
           >1; pushdown(o); repair(lson); repair(rson); pushup(o); } int query(int l,int r,int o,int L,int R) { if(L<=l&&r<=R){ return is[o]; } int m=l+r>>1; int res=INF; if(L<=m)res=res&query(lson,L,R); if(m 
          
            >1; pushdown(o); print(lson); print(rson); } int l[MAXN],r[MAXN],q[MAXN]; int main() { int n,m; scanf("%d%d",&n,&m); build(); for(int i=0;i 
            
           
          
         
       
      
      
     
     
    
    
   
   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值