用pre[t][i][j]存时间等价于t时坐标(1, 1) 和(i, j)组成的矩形区域的星星总亮度。再注意一下一个坐标处可以有多颗星星就可以了。
1 // http://codeforces.com/contest/835/problem/C 2 #include <cstdio> 3 #include <cstring> 4 const int M = 12, N = 102; 5 int pre[M][N][N]; 6 int main() 7 { 8 int n, q, c; 9 while(~scanf("%d%d%d", &n, &q, &c)) { 10 memset(pre, 0, sizeof pre); 11 c++; 12 int x, y, s; 13 while(n--) { 14 scanf("%d%d%d", &x, &y, &s); 15 for (int i = 0; i < c; ++i) 16 pre[i][x][y] += (s + i) % c; //不易注意的地方,同一个坐标可能有多颗小星星 17 } 18 for (int t = 0; t < c; ++t) //时间t,求下二维前缀和 19 for (int i = 1; i <= 100; ++i) 20 for (int j = 1; j <= 100; ++j) 21 pre[t][i][j] += pre[t][i-1][j] + pre[t][i][j-1] - pre[t][i-1][j-1]; 22 int t, x1, y1, x2, y2; 23 while(q--) { 24 scanf("%d%d%d%d%d", &t, &x1, &y1, &x2, &y2); 25 t %= c; 26 int sum = pre[t][x2][y2] - pre[t][x1-1][y2] - pre[t][x2][y1-1] + pre[t][x1-1][y1-1]; 27 printf("%d\n", sum); 28 } 29 } 30 31 return 0; 32 }
时间: 2024-11-05 00:23:30