Programming training _ summation formula

Problem Description:

QQ small square before will not use excel in the sum formula, and now he would, so he was eager to teach you. 
For a formula excel in the sub-matrix format is summed sum (A: B), where A represents the coordinates of the upper left corner of the sub-matrix, B represents the coordinates of the lower right corner of the sub-matrix.

  

Just tell you to listen is definitely not enough, in order to express themselves, QQ small parties now want to test you. 
Now QQ small square will give you a square matrix of n × n, two diagonal positions and it will fill the entire square matrix 1 (illustrated in Figure 17), fill the remaining positions of all 0. And he gave a square matrix of rows and columns from 0 to n-1 marked with a number. 
Is as shown in FIG. 4 × 4 square matrix is filled and row numbers:

  

Now, to test whether you really mastered the matrix of summation formulas excel, QQ small parties will be asked q times, each time asking a sub-matrices and. 
Input format 
input of the first line contains two integers n, q (1≤n≤10 ^ 18,1≤q≤10 ^ 5), respectively, the number and size of the matrix represents interrogation. 
The next q rows, each row comprising four integers a, b, c, d ( 0≤a≤c <n, 0≤b≤d <n), represents a sub-matrix. Wherein the sub-matrix is left corner (a, b), the bottom right coordinates (c, d). 
Output format 
output contains the line q represents an answer for each query output an integer. 

Sample 
INPUT 
. 4 2 
0. 1. 3. 1 
0 0. 3. 3 
Output 
. 3 
. 8

Topic solved:

AC Code:

Questions for:

Guess you like

Origin www.cnblogs.com/Robin5/p/11295533.html