#P4939. Counting Cuckoo Agents

    ID: 18180 Type: Default 1000ms 256MiB

Counting Cuckoo Agents

Counting Cuckoo Agents

You are given a schedule for N days and M commands. Each command is one of the following two types:

  1. 0 a b: This means that from day a to day b (inclusive) an agent will perform a "cuckoo" operation.
  2. 1 a: For this command, you are asked to output how many agents, according to the information so far, will cuckoo on day a.

Initially, no agent is scheduled to cuckoo. Process the commands in the given order and output the correct answer for every query command. In other words, after performing all previous updates, for each command of the form 1 a, output the number of updates affecting day a.

Note: The range update and point query can be formulated using a difference array or a Fenwick Tree. One way to view an update command is to add 1 to the interval [a, b]. Formally, if we denote an array A where initially A[i] = 0 for 1 \le i \le N, then the update command adds 1 to each A[i] for a \le i \le b. Each query is to output the value of A[a].

The command operations can be mathematically expressed using the following formula: $$\text{For an update } (0,a,b):\quad A[i] \mathrel{+}= \begin{cases} 1, & \text{if } a \le i \le b \\ 0, & \text{otherwise} \end{cases}$$

inputFormat

The first line contains two integers N and M, where N is the number of days and M is the number of commands.

Each of the next M lines contains a command. A command is in one of the following two forms:

  • 0 a b — update: add a cuckoo count to each day in the interval from a to b (inclusive).
  • 1 a — query: output the number of agents scheduled to cuckoo on day a.

Input values are separated by spaces.

outputFormat

For each query command (1 a), output a single integer representing the number of agents that will cuckoo on day a. Each answer should be printed on a new line.

sample

5 5
0 1 3
1 2
0 2 5
1 3
1 5
1

2 1

</p>