CF1027B.Numbers on the Chessboard
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
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.
给你一个 n×n 的棋盘。棋盘按如下方式填入 1 到 n2 的数字:
前 ⌈2n2⌉ 个数(即 1 到 ⌈2n2⌉)按从左到右、从上到下的顺序,填入所有行列坐标之和为偶数的格子中;
其余 n2−⌈2n2⌉ 个数(即 ⌈2n2⌉+1 到 n2)同样按从左到右、从上到下的顺序,填入所有行列坐标之和为奇数的格子中。
其中,⌈yx⌉ 表示将 x 除以 y 后向上取整。
例如,下图中左侧棋盘对应 n=4 的情况,右侧棋盘对应 n=5 的情况。

你将收到 q 个查询。第 i 个查询由一对坐标 (xi,yi) 描述。第 i 个查询的答案即为第 xi 行、第 yi 列(行号与列号均从 1 开始编号)格子中所填的数字。
输入格式
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.
第一行包含两个整数 n 和 q(1≤n≤109,1≤q≤105)—— 分别表示棋盘的大小和查询次数。
接下来的 q 行每行包含两个整数。第 i 行包含两个整数 xi,yi(1≤xi,yi≤n)—— 描述第 i 次查询。
输出格式
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 到 q 的每个查询,请输出该查询的答案。第 i 个查询的答案为位于第 xi 行、第 yi 列的单元格中所写的数字(其中 xi 表示行号,yi 表示列号)。行号与列号均从 1 编号至 n。查询按输入顺序编号,从 1 到 q。
输入输出样例
输入#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.
示例中查询的答案在题目描述图片中的黑板上。
输入解题思路,AI测评打分。不知道怎么写?