Nemmo Nemmo 2020
Time limit3sMemory limit1024 MB
The board holds rows of nemmo forming a nonincreasing staircase; for each query (x, y), count the nemmo removed by a laser firing up column x and right along row y.
- Level
Medium7 of 10
- Topics
- Binary search, Prefix sum, Implementation, Math
- Solved
- No attempts yet
Problem
Mysterious creatures called "nemmo" have started living on an old Tetris board. The board is cells wide and floors tall, and each nemmo occupies one cell on one floor. For convenience, let denote the cell in the -th column from the left and the -th floor from the bottom.
Floor contains nemmo. Since nemmo like to stay close together, they live side by side in cells , and because they are affected by gravity, for every .

Nemmo living on the Tetris board. Here , , , and .
Leff, who wants to play Tetris, plans to clear the nemmo away with a laser. Installing a laser at makes all nemmo disappear that live in the -th column from the left on floor or above, along with all nemmo on floor to the right of . No other nemmo disappears right away.

A laser installed at . A total of 4 nemmo are hit by the laser and disappear.
There are positions where a laser can be installed. For each position, tell Leff how many nemmo would be removed if a laser were installed there. Since this is only planning an installation rather than actually installing lasers, the plans do not affect one another.
Input
The first line contains two integers and separated by a space. is the height of the board, and is the number of positions where a laser can be installed.
The second line contains integers separated by spaces. This means that floor contains nemmo.
Each of the next lines gives a position where a laser can be installed. The -th line contains two integers and separated by a space, meaning a laser can be installed at .
Output
Print the answers over lines. The -th line should contain the number of nemmo removed by installing a laser at .
Constraints
- ()
- , ()