100*100规模上第一象限坐标系上有1e5规模的点,每个点随时间在同一个值域内(最大10)周期递增,但初始值不同,给出一个矩阵和时间询问此时范围内点的值的和。
预处理初始时刻不同权值下的二维前缀和,对于每个询问再次遍历所有权值,累计和就好了。
/** @Date : 2017-08-12 10:28:03 * @FileName: C.cpp * @Platform: Windows * @Author : Lweleth ([email protected]) * @Link : https://github.com/ * @Version : $Id$ */ #include <bits/stdc++.h> #define LL long long #define PII pair<int ,int> #define MP(x, y) make_pair((x),(y)) #define fi first #define se second #define PB(x) push_back((x)) #define MMG(x) memset((x), -1,sizeof(x)) #define MMF(x) memset((x),0,sizeof(x)) #define MMI(x) memset((x), INF, sizeof(x)) using namespace std; const int INF = 0x3f3f3f3f; const int N = 1e5+20; const double eps = 1e-8; int n, q, c; LL f[11][110][110]; int main() { while(cin >> n >> q >> c) { MMF(f); for(int i = 0; i < n; i++) { int x, y, s; scanf("%d%d%d", &x, &y, &s); f[s][x][y]++; } for(int k = 0; k <= c; k++/*, cout << endl*/) for(int i = 1; i <= 100; i++) { for(int j = 1; j <= 100; j++) { f[k][i][j] += f[k][i][j - 1] + f[k][i - 1][j] - f[k][i - 1][j - 1]; //cout << f[k][i][j] << " "; } //cout << endl; } while(q--) { LL t, x1, y1, x2, y2; scanf("%lld%lld%lld%lld%lld", &t, &x1, &y1, &x2, &y2); LL ans = 0; LL tmp = 0; for(int i = 0; i <= 10; i++) { tmp = (f[i][x2][y2] - f[i][x2][y1 - 1] - f[i][x1 - 1][y2] + f[i][x1 - 1][y1 - 1]); ans += ((i + t) % (c + 1)) * tmp; } printf("%lld\n", ans); } } return 0; }
时间: 2024-10-14 20:07:07