C++ CP doubt / query

pls correct the time exceeded error in this c++ code.

==== question =====

Rishi is the owner of Mystery Maze. Mystery Maze is a maze of n × n which has m special room bombs.

The maze and its rooms are initially empty. Rishi will cleverly stage and fit the special room bombs one after the other in the maze.

A room in the maze is unreachable if there is at least one room-bomb fitted in the same row or in the same column with this room. Obviously enough, a room is unreachable if the room-bomb is fitted in a particular room.

You are given the rooms of the maze in which Rishi will fit the bombs.

Find the number of rooms for each room-bomb that are reachable after Rishi fits them in the Mystery-maze of rooms.

Input

The first line of the input contains two integers n and m where (1 ≤ m, n ≤ 10^5), and m can’t be greater than either of 10^5 and n^2.

Note: There has to be at least 1 bomb.

All the next m lines contain integers xixi and yiyi (1 ≤ xixi, yiyi ≤ n) — the number of the row and column where the room-bomb can be found. The bombs are fitted in the order in which they appear in the input. It is guaranteed that 2 or more bombs can not co-exist in one place.

Example

input
3 3 1 1 3 1 2 2

output
4 2 0

hello @prerak_semwal

is it any ongoing contest,
if not then pls share question share question link with me , to debug it i need to submit it over there

@aman212yadav
Yes it is ongoing 12 mins left … you won’t be able to access as your id won’t be authenciated … It says wrong on test 3 …
Ok then pls debug it after 12… when contest’s over

@prerak_semwal

the approahc that u r trying will not work becuase of m * n *n time complexity.

try to do it in O(M)
HINT -> think how many cells become unreachable after putting one bomb. its an easy problem pick some test case and analyse

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.