{"id":"d44eb014-6213-4514-97b5-ce09b4f85a5c","name":"Toggle Bulbs","description":"You are given n bulbs, numbered from 1 to n. Initially all the bulbs are turned off.\r\nYou have to perform 2 types of operations:-\r\n\r\n1. Toggle all bulds numbered between A to B.Here toggle mean turn on bulbs to off and off bulbs to on.This is represented by 1 A B.\r\n2. Count how many bulbs numbered between A to B are on.This is represented by 2 A B.","inputFormat":"First line contains two integers n and q.\r\nFollowing q lines contains queries of format either 1 A B or 2 A B.","outputFormat":"Print count of bulbs for query type 2 A B.","constraints":"1. 1 <= n <= 10^5\r\n2. 1 <= q <= 10^5\r\n3. 1 <= A <= B <= n\r\n","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n String inps[] = read.readLine().split(\" \");\r\n int n = Integer.parseInt(inps[0]);\r\n int q = Integer.parseInt(inps[1]);\r\n\r\n // write your code here\r\n\r\n\r\n }\r\n\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"4 7\r\n2 1 4\r\n1 2 3\r\n2 1 2\r\n2 1 1\r\n1 1 4\r\n2 1 4 \r\n2 4 4\r\n","sampleOutput":"0\r\n1\r\n0\r\n2\r\n1\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"9b3d7d76-b2ca-458f-80a8-4b37d548024a","name":"Segment Tree For Experts","slug":"segment-tree-for-experts-953","type":0},{"id":"9167f274-6395-4fa1-b521-a700d2d14ff1","name":"Toggle Bulbs","slug":"toggle-bulbs","type":1}],"next":{"id":"5eceac13-61e9-4d38-960d-7b16abd79154","name":"Prime Divide","type":1,"slug":"prime-divide"},"prev":{"id":"5eccc617-64f0-4ca6-8282-6acb4e1c5160","name":"2d Segment Tree","type":1,"slug":"2d-segment-tree"}}}

Toggle Bulbs

You are given n bulbs, numbered from 1 to n. Initially all the bulbs are turned off. You have to perform 2 types of operations:- 1. Toggle all bulds numbered between A to B.Here toggle mean turn on bulbs to off and off bulbs to on.This is represented by 1 A B. 2. Count how many bulbs numbered between A to B are on.This is represented by 2 A B.

{"id":"d44eb014-6213-4514-97b5-ce09b4f85a5c","name":"Toggle Bulbs","description":"You are given n bulbs, numbered from 1 to n. Initially all the bulbs are turned off.\r\nYou have to perform 2 types of operations:-\r\n\r\n1. Toggle all bulds numbered between A to B.Here toggle mean turn on bulbs to off and off bulbs to on.This is represented by 1 A B.\r\n2. Count how many bulbs numbered between A to B are on.This is represented by 2 A B.","inputFormat":"First line contains two integers n and q.\r\nFollowing q lines contains queries of format either 1 A B or 2 A B.","outputFormat":"Print count of bulbs for query type 2 A B.","constraints":"1. 1 <= n <= 10^5\r\n2. 1 <= q <= 10^5\r\n3. 1 <= A <= B <= n\r\n","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n String inps[] = read.readLine().split(\" \");\r\n int n = Integer.parseInt(inps[0]);\r\n int q = Integer.parseInt(inps[1]);\r\n\r\n // write your code here\r\n\r\n\r\n }\r\n\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"4 7\r\n2 1 4\r\n1 2 3\r\n2 1 2\r\n2 1 1\r\n1 1 4\r\n2 1 4 \r\n2 4 4\r\n","sampleOutput":"0\r\n1\r\n0\r\n2\r\n1\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"9b3d7d76-b2ca-458f-80a8-4b37d548024a","name":"Segment Tree For Experts","slug":"segment-tree-for-experts-953","type":0},{"id":"9167f274-6395-4fa1-b521-a700d2d14ff1","name":"Toggle Bulbs","slug":"toggle-bulbs","type":1}],"next":{"id":"5eceac13-61e9-4d38-960d-7b16abd79154","name":"Prime Divide","type":1,"slug":"prime-divide"},"prev":{"id":"5eccc617-64f0-4ca6-8282-6acb4e1c5160","name":"2d Segment Tree","type":1,"slug":"2d-segment-tree"}}}
plane

Editor


Loading...

Toggle Bulbs

medium

You are given n bulbs, numbered from 1 to n. Initially all the bulbs are turned off. You have to perform 2 types of operations:- 1. Toggle all bulds numbered between A to B.Here toggle mean turn on bulbs to off and off bulbs to on.This is represented by 1 A B. 2. Count how many bulbs numbered between A to B are on.This is represented by 2 A B.

Constraints

1. 1 <= n <= 10^5 2. 1 <= q <= 10^5 3. 1 <= A <= B <= n

Format

Input

First line contains two integers n and q. Following q lines contains queries of format either 1 A B or 2 A B.

Output

Print count of bulbs for query type 2 A B.

Example

Sample Input

4 7 2 1 4 1 2 3 2 1 2 2 1 1 1 1 4 2 1 4 2 4 4

Sample Output

0 1 0 2 1

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode