標籤:memset blank sky logs log scanf print set 一個
用pre[t][i][j]存時間等價於t時座標(1, 1) 和(i, j)組成的矩形地區的星星總亮度。再注意一下一個座標處可以有多顆星星就可以了。
star sky
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 }
CF427 C star sky 二維數組首碼和