logo AlgoBeat OnlineJudge
登录 注册

#203664. [BalticOI 2016] Spiral (day1)

内存限制:250 MiB 时间限制:1500 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

A grid of size has been constructed as follows. Number has been placed in the center square, number has been placed to the right of it, and the following numbers have been placed along the spiral counterclockwise.

Your task is to calculate answers for queries where the sum of numbers in an rectangular region in the grid is requested (modulo ). For example, in the following grid and the sum of numbers in the gray region is :

输入格式

The first input line contains two integers and : the size of the grid and the number of queries.

After this, there are lines, each containing four integers and (). This means that you should calculate the sum of numbers in a rectangular region with corners and .

输出格式

You should output the answer for each query (modulo ).

样例

样例输入 1

2 3
0 -2 1 1
-1 0 1 0
1 2 1 2

样例输出 1

74
9
14

数据范围与提示

Subtasks

In all subtasks .

Subtask 1 (12 points)

Subtask 2 (15 points)

  • and

Subtask 3 (17 points)

Subtask 4 (31 points)

Subtask 5 (25 points)