Finding Treasure
시간 제한1초메모리 제한2048 MB
양 끝 칸에 보물이 고정된 1차원 격자에서 칸을 켜고 끌 때마다, 각 칸에서 왼쪽과 오른쪽 가장 가까운 보물까지의 거리 곱을 모두 더한 값을 구한다.
문제
Morgan is designing a treasury for a treasure hunt event. The treasury can be represented as one dimensional grid with cells, numbered from to . Each cell can be empty or contain a treasure. At first, cell and cell contain a treasure, while the other cells are currently empty.
While experimenting with the treasury design, Morgan does updates, numbered from to , to his treasury. In update , he wants to change cell . If cell is empty, he will put a treasure on cell . If cell contains a treasure, he will remove the treasure from cell and the cell becomes empty. It is guaranteed that for all , which implies cell and cell always contain a treasure.
After each change, Morgan wonders how difficult his treasure hunt is. He defines the difficulty level of standing on cell as the multiplication of two values:
- the distance from to the closest treasure on cell , and
- the distance from to the closest treasure on cell .
The distance between two cells can be calculated as the absolute difference between the cell numbers. Then, the total difficulty level of his treasure hunt is defined as the sum of difficulty level of standing on cell for all .
Help Morgan to determine the total difficulty level of his treasure hunt after each update.
입력
Input begins with two integers (; ) representing the size of the treasury room and the number of updates, respectively. Each of the next lines contains an integer () representing the cell that Morgan wants to change in update .
출력
After each update that Morgan makes, output an integer in a single line representing the total difficulty level of his treasure hunts at that time.