Asraf has N lights, arranged in a line, with him. A[i] denotes the initial state of ‘i’th light.
He wants to toggle some lights, but he can only toggle the lights in ranges. Toggling a light means changing the state of the light. That is, if the light was ON then after toggling it becomes OFF.
He does this ‘range toggling’ Q times. In the ‘i’th range toggling, he toggles the lights all the lights between Li and Ri lights (Li and Ri inclusive).
You need to find the final states of all the N lights after these Q toggles.
A[i] = 1 means the light is ON and A[i] = 0 means the light is OFF
Input:
First line N and Q.
Next line contains N integers showing the initial state of the bulbs.
Next Q line contains the queries where 'i'th line contains Li and Ri.
Output:
Output N integers showing the final state of the bulbs.
#include <stdio.h> int main() { int lights[100001],n,q,i,a,b; scanf("%d %d",&n,&q); for(i=0;i<n;i++) {scanf("%d",&lights[i]);} while(q-->0) {scanf("%d %d",&a,&b); for(i=a-1;i<b;i++) lights[i]=!lights[i]; } for(i=0;i<n;i++){ printf("%d ",lights[i]);} return 0; }
INPUT_1:
7 2
1 1 0 1 0 0 0
5 7
1 3
OUTPUT:
0 0 1 1 1 1 1
INPUT_2:
10 4
0 1 0 0 0 1 1 0 0 1
3 6
2 5
7 10
4 8
OUTPUT:
0 0 0 1 1 1 1 0 1 0
INPUT_3:
5 2
0 0 1 1 1
1 3
3 5
OUTPUT:
1 1 1 0 0
ILLUSTRATION OUTPUT
Morae Q!
- Conversion of days into year, weeks and days.
- Find if the number is a perfect number or not.
- Compute conversion of Binary to Octal.
- Return the sum of digits in a number.
- Find if a word exists or not in a sentence.
- Convert Numbers into Words.
- Read a word if it consists only of the letters known.
- Check if the string is a dynamic string or not.
- Convert all Uppercase letters to Lowercase and vice-versa.
- Change the string such that there are no matching adjacent characters.
- Find the number of sub-strings which start and end both in 1.
- Find the start and end index of unsorted sub-array.
- Find the maximum number of pairs that can be formed.
- Figure out the number of bubbly words present.
- Check if a string is lapindrome or not even with a middle character.
- Seating layout in a triangular shaped class according to the number of rows.
- Find and Sort a sub-array which makes whole array sorted.
- Seating layout according to the number of rows.
- Find the final states of the bulbs.
- Check if reversing sub array makes the array sorted.