Score : 400 points
问题陈述
给定一个正整数 N,以及对于每一组整数三元组 (x,y,z) 的整数 Ax,y,z,满足 1≤x,y,z≤N。
你将按照顺序处理以下格式的 Q 个查询。
对于第 i 个查询 (1≤i≤Q),你将得到一组整数 (Lxi,Rxi,Lyi,Ryi,Lzi,Rzi),满足 1≤Lxi≤Rxi≤N,1≤Lyi≤Ryi≤N,以及 1≤Lzi≤Rzi≤N。计算:
$\displaystyle{\sum_{x=Lx_i}^{Rx_i} \sum_{y=Ly_i}^{Ry_i} \sum_{z=Lz_i}^{Rz_i} A_{x,y,z}}$。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given a positive integer N, and an integer Ax,y,z for each triple of integers (x,y,z) such that 1≤x,y,z≤N.
You will be given Q queries in the following format, which must be processed in order.
For the i-th query (1≤i≤Q), you are given a tuple of integers (Lxi,Rxi,Lyi,Ryi,Lzi,Rzi) such that 1≤Lxi≤Rxi≤N, 1≤Lyi≤Ryi≤N, and 1≤Lzi≤Rzi≤N. Find:
$\displaystyle{\sum_{x=Lx_i}^{Rx_i} \sum_{y=Ly_i}^{Ry_i} \sum_{z=Lz_i}^{Rz_i} A_{x,y,z}}$.
Constraints
- 1≤N≤100
- 1≤Q≤2×105
- 0≤Ax,y,z≤999 (1≤x,y,z≤N)
- 1≤Lxi≤Rxi≤N (1≤i≤Q)
- 1≤Lyi≤Ryi≤N (1≤i≤Q)
- 1≤Lzi≤Rzi≤N (1≤i≤Q)
- All input values are integers.
The input is given from Standard Input in the following format:
N
A1,1,1 A1,1,2 … A1,1,N
A1,2,1 A1,2,2 … A1,2,N
⋮
A1,N,1 A1,N,2 … A1,N,N
A2,1,1 A2,1,2 … A2,1,N
A2,2,1 A2,2,2 … A2,2,N
⋮
A2,N,1 A2,N,2 … A2,N,N
⋮
AN,1,1 AN,1,2 … AN,1,N
AN,2,1 AN,2,2 … AN,2,N
⋮
AN,N,1 AN,N,2 … AN,N,N
Q
Lx1 Rx1 Ly1 Ry1 Lz1 Rz1
Lx2 Rx2 Ly2 Ry2 Lz2 Rz2
⋮
LxQ RxQ LyQ RyQ LzQ RzQ
Output
Print Q lines. The i-th line should contain the answer to the i-th query.
2
1 2
3 4
5 6
7 8
2
1 2 2 2 1 1
2 2 1 2 1 2
Sample Output 1
10
26
For the 1st query, the sought value is A1,2,1+A2,2,1=3+7=10. Thus, print 10.
For the 2nd query, the sought value is $A_{2,1,1} + A_{2,1,2} + A_{2,2,1} + A_{2,2,2} = 5 + 6 + 7 + 8 = 26$. Thus, print 26.
3
733 857 714
956 208 257
123 719 648
840 881 245
245 112 746
306 942 694
58 870 849
13 208 789
687 906 783
8
3 3 3 3 1 1
1 3 2 3 3 3
2 2 2 3 1 1
1 3 1 1 1 1
2 3 2 3 2 3
1 2 1 1 1 2
3 3 2 2 1 3
1 2 2 3 2 3
Sample Output 2
687
3917
551
1631
5180
3311
1010
4326