Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

Not able be solve during test

Revision en1, by naman_334, 2022-07-31 09:27:41

There is long barn with N stalls located along a straight line from 1 to N. Each stall can contain only one cow.

A any moment you may buy or sell a cow. When you buy a cow, you want them to locate the cow in a stall such that the distance between the new cow and other cows to as max as possible.

The place of a cow is chose in the following way.

First you will choose the longest segment of empty stalls among available stalls in the barn. If there are several segments with maximum number of empty stalls, then you will choose the closest one to the right.

After that the cow is placed on the stall located in the middle of this segment, If the segment has even number of stalls, then among two median stalls we choose the closest one to the right.

When a cow is sold, its location will be empty and you can reuse it again, At some time, you may want to know how many cows are placed on the range from L->R inclusive.

You are given Q query where each consist of two values L and R

  1. If R==-1 and the number of occurrences of L is even then you bought the cow number L and have to place it in the barn. The answer to this type of query is zero.
  2. If R==-1 and the number of occurrences of L is odd then you sold the cow number L and you have to make its stall empty. The answer to this type of query is zero.
  3. If R!=-1 The answer to this query is the total number of cows placed in the ange from L to R inclusive.

Initially all the stalls are empty

constraints:

1<= N <= 10^9

1<= Q <= 10^5

1<= L,R <= 10^9

also R can be -1

sample test case 1: N=7 Q=3

L R => Query result

1 -1 => 0

2 5 => 1

4 4 => 1

In this case cow is located in stall no. 4

sample test case 2: N=7 Q=4

L R => Query result

1 -1 => 0

2 5 => 1

1 -1 => 0

4 4 => 0

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English naman_334 2022-07-31 09:27:41 1877 Initial revision (published)