LITE - Light Switching


Farmer John tries to keep the cows sharp by letting them play with intellectual toys. One of the larger toys is the lights in the barn.  Each of the N (2 ≤ N ≤ 100,000) cow stalls conveniently numbered 1..N has a colorful light above it.

At the beginning of the evening, all the lights are off. The cows control the lights with a set of N pushbutton switches that toggle the lights; pushing switch i changes the state of light i from off to on or from on to off.

The cows read and execute a list of M (1 ≤ M ≤ 100,000) operations expressed as one of two integers (0 ≤ operation ≤ 1).

The first kind of operation (denoted by a 0 command) includes two subsequent integers Si and Ei (1 ≤ Si ≤ Ei ≤ N) that indicate a starting switch and ending switch. They execute the operation by pushing each pushbutton from Si through Ei inclusive exactly once.

The second kind of operation (denoted by a 1 command) asks the cows to count how many lights are on in the range given by two integers Si and Ei (1 ≤ Si ≤ Ei ≤ N) which specify the inclusive range in which the cows should count the number of lights that are on.

Help FJ ensure the cows are getting the correct answer by processing the list and producing the proper counts.

Input

Line 1: Two space-separated integers: N and M
Lines 2 to M+1: Each line represents an operation with three space-separated integers: operation, Si, and Ei

Output

Lines 1: number of queries: For each output query, print the count as an integer by itself on a single line.

Example

Input:
4 5
0 1 2
0 2 4
1 2 3
0 2 4
1 1 4

Output:
1
2

hide comments
Rishab Banerjee: 2014-10-25 10:18:38

exactly same as flipcoin only difference is that flipcoin has 0 based indexing and here its 1 based costed me 5 WA

Umair Khan: 2014-10-22 07:39:59

Anyone going wrong at 10th test case, update the lazy node everywhere in the update method (I hope you get it).

Corner case is when you are going to mark a lazy node again to be lazy.

caesar: 2014-10-07 23:29:00

getting wrong answer on Test case 10. Any suggestion
<snip>
Used Segment tree along with lazy propagation

Last edit: 2023-04-06 23:00:44
maniAC: 2014-07-08 21:18:54

Finally got AC after few TLE, just optimize the program using inline, TL should be 2.0 second :(.

Archit Jain: 2014-07-01 10:40:28

nice question
lazy optimization....

Atul Vaibhav: 2014-04-16 16:25:08

i just copy-pasted my FLIPCOIN solution and got WA! but then read the problem details again "carefully" and got AC!
Learned to read problems carefully atleast once before submitting! ;)

csprajeeth: 2014-04-05 20:25:11

Same here..AC on FLIPCOINS and WA here

Adamos Ttofari: 2014-02-02 18:15:26

I solved the Flipping Coins in CodeChef
Why I get WA here?

ABHISHEK004: 2014-01-01 21:57:43

phew...!!
after lots of tle finally acc.. :)
learnt new thing about lazy propogation

Praneeth Reddy: 2013-12-04 17:13:55

TLE for 10th test case???
where is the mistake???
ca anybody explain?


Added by:Iqram Mahmud
Date:2010-09-03
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: OBJC VB.NET
Resource:USACO November 08