Eating apples

2.2

17 votes
Algorithms, Quick Sort, Sorting
Problem

You are staying at point (1, 1) in a matrix 109×109. You can travel by following these steps:

  1. If the row where you are staying has 1 or more apples, then you can go to another end of the row and can go up.
  2. Otherwise, you can go up.

The matrix contains N apples. The ith apple is at point (xi, yi). You can eat these apples while traveling. 

For each of the apples, your task is to determine the number of apples that have been eaten before.

Input format

  • The first line contains a single integer N (1N105) denoting the number of apples.
  • The next N lines contain two integersxi, yi (1xi, yi109) denoting the coordinates of the ith apple.

Output format

Print N lines containing a single integer.

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

-

Editor Image

?