CF1027B.Numbers on the Chessboard

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a chessboard of size n×nn \times n . It is filled with numbers from 11 to n2n^2 in the following way: the first n22\lceil \frac{n^2}{2} \rceil numbers from 11 to n22\lceil \frac{n^2}{2} \rceil are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n2n22n^2 - \lceil \frac{n^2}{2} \rceil numbers from n22+1\lceil \frac{n^2}{2} \rceil + 1 to n2n^2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation xy\lceil\frac{x}{y}\rceil means division xx by yy rounded up.

For example, the left board on the following picture is the chessboard which is given for n=4n=4 and the right board is the chessboard which is given for n=5n=5 .

You are given qq queries. The ii -th query is described as a pair xi,yix_i, y_i . The answer to the ii -th query is the number written in the cell xi,yix_i, y_i ( xix_i is the row, yiy_i is the column). Rows and columns are numbered from 11 to nn .

输入格式

The first line contains two integers nn and qq ( 1n1091 \le n \le 10^9 , 1q1051 \le q \le 10^5 ) — the size of the board and the number of queries.

The next qq lines contain two integers each. The ii -th line contains two integers xi,yix_i, y_i ( 1xi,yin1 \le x_i, y_i \le n ) — description of the ii -th query.

输出格式

For each query from 11 to qq print the answer to this query. The answer to the ii -th query is the number written in the cell xi,yix_i, y_i ( xix_i is the row, yiy_i is the column). Rows and columns are numbered from 11 to nn . Queries are numbered from 11 to qq 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.

首页