luogu#P9031. [COCI 2022/2023 #1] Iksevi

[COCI 2022/2023 #1] Iksevi

Background

After writing code for ten years, Vinko decided to change careers and become a potter. On his first day at the new job, he was given a difficult task.

Problem Description

Vinko needs to cover the floor of a concert hall using square tiles. He will not align the tile edges parallel to the walls; instead, he chooses to align the diagonals of the tiles parallel to the walls.

Vinko has not yet decided the tile size, but he knows that all tiles must be the same size, and the diagonal length must be a positive even integer.

The first tile Vinko places will have a corner touching the left wall and the back wall. After that, each tile he places shares at least one full edge with at least one tile that has already been placed. He will repeat this process until the entire 107×10710^7 \times 10^7 square millimeter floor is covered.

Besides being a programmer and a potter, Vinko is also an excellent musician. Because of that, he knows there are nn points on the floor that are crucial for the hall’s acoustics. If a tile corner lies on one of these nn points, the acoustics of the hall will improve significantly.

As shown in the figure, the left diagram is a tiling with diagonal length 44. Under this tiling, the point (2,4)(2,4) lies on a tile corner, so it satisfies the condition and greatly improves the acoustics, but the points (4,3)(4,3) and (5,1)(5,1) do not. The right diagram is a tiling with diagonal length 22. In this tiling, the point (4,3)(4,3) lies on the corners of four tiles, while (2,4)(2,4) and (5,1)(5,1) do not.

Help Vinko determine, for each of the nn points, how many tile sizes can make the ii-th point lie on a tile corner after the floor is fully covered.

Input Format

The first line contains an integer nn, the number of acoustically important points.

The next nn lines each contain two integers xi,yix_i,y_i, representing the distances from the ii-th acoustically important point to the left wall and the back wall.

Output Format

Output nn lines, each containing one integer.

Line ii should contain the number of tile sizes that can make the ii-th acoustically important point lie on a tile corner.

3
1 4
0 0
0 9
1
0
3
3
5 1
4 3
2 4
0
1
1

Hint

Subtask Score Constraints
11 1515 1n104,0xi,yi1001\leq n \leq 10^4,0\leq x_i,y_i \leq 100
22 5555 1n104,0xi,yi1071\leq n \leq 10^4,0\leq x_i,y_i \leq 10^7
33 4040 1n106,0xi,yi1071\leq n \leq 10^6,0\leq x_i,y_i \leq 10^7

This problem is worth 110110 points in total.

Translated by ChatGPT 5