Alice and friends
Practice
5 (1 votes)
Data structures
Hard
Segment tree
Data structures
Problem
9% Success 61 Attempts 50 Points 4s Time Limit 512MB Memory 1024 KB Max Code

Alice and her friends are playing a game. There is a big rectangle field with n rows and m columns initially with empty cells. Every turn Alice puts a small cube in one of the empty cells. After this friends need to find a empty cell so that they can see the maximum number of empty cells from it. Empty cell A can be seen from empty cell B if they are in the same row or in the same column and there are no cubes between them. Help Alice to check the answers her friends made. After each step find the maximum number of cells which can be seen from one free cell on the field.

\(INPUT\)

The first line of the input contains three integers n, m and q \((1 \leq n, m \leq 50 000, 1 \leq q \leq min(n \cdot m - 1, 100 000))\) - number of rows, number of columns and number of game steps.

Then following q lines contain description of the turns. The i-th of these lines contains two integers \(r_i\) and \(c_i\) - row number and column number of cell where Alice put a cube in this turn. It is guaranteed that this cell is free before this turn.

\(OUTPUT\)

Output q lines. The i-th of these lines should contain single integer - the maximum number of cells that can be seen from some free cell on field after i-th step.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
3 votes
Tags:
Advanced Data StructuresData StructuresString AlgorithmsLazy Propagation in Interval/Segment TreesHashing algorithm
Points:50
7 votes
Tags:
Advanced Data StructuresData StructuresXORHashing algorithmLazy Propagation in Interval/Segment TreesNumber theory
Points:50
Tags:
Hard
Editorial

Login to unlock the editorial