AND operation

2.9

11 votes
Arrays, Basic Programming, Bit Manipulation, Bit manipulation, Java, Medium, Python
Problem

You are given an array A of length N. You are also given Q tasks.

Each task is of the following type:

L R V: Apply the bitwise-and operator with V for all AiwhereLiR

You need to print the array after performing all the tasks.

Input format

  • First line: Two integers, N (denoting the length of array) and Q (denoting the number of tasks)
  • Second line: N space-separated elements of the array
  • Each of the following Q lines contains a task in the described format

Output format

Print the final array after performing all the Q tasks.

Constraints

1N105

1Q2105

1Ai,V109

1LRN

 

Sample Input
5 2
7 7 7 7 7
1 3 4
1 5 6
Sample Output
4 4 4 6 6
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

After first task, the array will be {4,4,4,7,7}.

After second task, the array will be {4,4,4,6,6}.

Editor Image

?