#P4676. [BalticOI 2016 day1] Spiral
[BalticOI 2016 day1] Spiral
题目描述
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 ).
题目大意
[BalticOI 2016 Day1]螺旋
题目描述
一个矩阵的大小为 ,我们们通过下述方法填数:数字 在中心,数字 在其右,其他数字依次按照逆时针螺旋摆放。
你的任务是对于 个询问,计算出一个给定子矩阵所有数字的和对 取余的结果。比如以下 的矩阵,灰色区域的数字之和为 :
输入格式
第一行,两个整数 和 ,分别表示矩阵的大小和询问的个数。
接下来 行,每行四个整数 和 。这表示你需要计算一个对角为 和 的子矩阵的数字之和。
输出格式
对于每个询问,输出一行表示答案(对 取余)。
由 @I_love_him52 提供翻译
2 3
0 -2 1 1
-1 0 1 0
1 2 1 2
74
9
14
提示
Subtasks
In all subtasks .
Subtask 1 (12 points)
Subtask 2 (15 points)
-
-
and