Friends
Time limit2sMemory limit1024 MB
Friends occupy squares on a line; a jump moves one friend to an empty square, and after each move a query asks for the sum over all friends of the length of their contiguous block.
- Level
Medium7 of 10
- Topics
- Intervals, Implementation, Sorting, Math
- Solved
- No attempts yet
Problem
friends are playing a game. The game is played on a row of squares, numbered from to , where squares and are adjacent to each other. At most one friend stands on each square at any given time. In each step of the game, one friend jumps from its current square to a new (non-occupied) square.
At any moment of the game, the score of a friend is the length of the longest contiguous segment of friends it is part of. This means that if a friend stands on some position , and there are friends on positions , the score of the friend is .
The total score of the game is the sum of scores for all friends. At various times during the game, the friends wonder what their current total score is.
Input
The judge reads input in the following format:
- line :
N L Q - line :
P[0] P[1] .. P[N - 1] - lines to : each line represents either a jump or a score question. If the line is
0 A B, a jump from to is to be made, and if the line is1a scoring question is to be made.
Output
For each scoring question, the judge writes a line with the return value of score().