482B - Interesting Array - CodeForces Solution


constructive algorithms data structures trees *1800

Please click on ads to support us..

C++ Code:

#include <stdio.h>
#include <string.h>
const int N=100100;
int n,m,l[N],r[N],q[N],c[N],s[N],a[N],f;
int go(int b){
  memset(c,0,sizeof(c));
  for(int i=0;i<m;++i)if(q[i]&b)++c[l[i]],--c[r[i]+1];
  for(int i=1;i<=n;++i)c[i]+=c[i-1],s[i]=s[i-1]+(c[i]<1),a[i]|=c[i]?b:0;
  for(int i=0;i<m;++i)if(!(q[i]&b)&&s[r[i]]-s[l[i]-1]<1)return 1;
  return 0;
}
int main(){
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;++i)scanf("%d %d %d",&l[i],&r[i],&q[i]);
  for(int b=0;!f&&b<30;++b)f|=go(1<<b);
  if(f)puts("NO");else{
    puts("YES");
    for(int i=1;i<=n;++i)printf("%d ",a[i]);
  }
}


Comments

Submit
0 Comments
More Questions

991B - Getting an A
246A - Buggy Sorting
884A - Book Reading
1180A - Alex and a Rhombus
445A - DZY Loves Chessboard
1372A - Omkar and Completion
159D - Palindrome pairs
981B - Businessmen Problems
1668A - Direction Change
1667B - Optimal Partition
1668B - Social Distance
88B - Keyboard
580B - Kefa and Company
960A - Check the string
1220A - Cards
897A - Scarborough Fair
1433B - Yet Another Bookshelf
1283B - Candies Division
1451B - Non-Substring Subsequence
1408B - Arrays Sum
1430A - Number of Apartments
1475A - Odd Divisor
1454B - Unique Bid Auction
978C - Letters
501B - Misha and Changing Handles
1496A - Split it
1666L - Labyrinth
1294B - Collecting Packages
1642B - Power Walking
1424M - Ancient Language