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
#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;
}
Comments
Post a Comment