Card Query

0

0 votes
Medium
Problem

Problem Statement:
 

There are n playing cards kept face down on a table, they are all numbered from 0 to n-1. You are required to perform two types of operations on them.

Operation #1: To flip the cards between two given indices (both inclusive)

Operation #2: To count how many cards are facing up between two given indices (both inclusive)


Input :

Line 1 contains two space separated integers

n q

q : number of queries

Each of next q lines contains a query for either of the two operations:

0 a b : for operation #1
1 a b : for operation #2

Output :

q lines of output for all the queries of Operation #2 containing the required answer to the corresponding queries.

Constraints :
1 <= N <= 100000
1 <= Q <= 100000
0 <= A <= B <= N - 1


Sample Input :
4 7
1 0 3
0 1 2
1 0 1
1 0 0
0 0 3
1 0 3
1 3 3

Sample Output :
0
1
0
2
1

 

Time Limit: 0.5
Memory Limit: 256
Source Limit:
Explanation

For query 1 0 3 : None of the card in the range is facing upwards
Output : 0

For query 1 0 1 : ony1 card at index 1 is facing upwards 
Output : 1

For query 1 0 0 : the card at index 0 is facing downwards implies no card facing upwards
Output : 0

For query 1 0 3 : 2 cards (at index 0 and 3) are facing upwards
Output : 2

For query 1 3 3 : card  at index 3 in facing upwards
Output : 1

Editor Image

?