CF1027B.Numbers on the Chessboard
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a chessboard of size n×n . It is filled with numbers from 1 to n2 in the following way: the first ⌈2n2⌉ numbers from 1 to ⌈2n2⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n2−⌈2n2⌉ numbers from ⌈2n2⌉+1 to n2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈yx⌉ means division x by y rounded up.
For example, the left board on the following picture is the chessboard which is given for n=4 and the right board is the chessboard which is given for n=5 .
You are given q queries. The i -th query is described as a pair xi,yi . The answer to the i -th query is the number written in the cell xi,yi ( xi is the row, yi is the column). Rows and columns are numbered from 1 to n .
输入格式
The first line contains two integers n and q ( 1≤n≤109 , 1≤q≤105 ) — the size of the board and the number of queries.
The next q lines contain two integers each. The i -th line contains two integers xi,yi ( 1≤xi,yi≤n ) — description of the i -th query.
输出格式
For each query from 1 to q print the answer to this query. The answer to the i -th query is the number written in the cell xi,yi ( xi is the row, yi is the column). Rows and columns are numbered from 1 to n . Queries are numbered from 1 to q in order of the input.
输入输出样例
输入#1
4 5 1 1 4 4 4 3 3 2 2 4
输出#1
1 8 16 13 4
输入#2
5 4 2 1 4 2 3 3 3 4
输出#2
16 9 7 20
说明/提示
Answers to the queries from examples are on the board in the picture from the problem statement.