水平较水,想了老久,都结束了,才发现数据这么小,打个表预处理下不就好了。然后才想到,表怎么打?真是傻了
去看了看别人怎么打的。。。
光照强度每c+1轮循环一次,c<=10,共循环c+1轮,把每轮的都打出来,然后O(1)查询。。。
#include <bits/stdc++.h>
using namespace std;
struct star
{
int x,y,s;
};
const int MAXN = 1e5+10;
int table[15][110][110];
star stars[MAXN];
int n,q,c;
int main()
{
ios::sync_with_stdio(false);
cin >> n >> q >> c;
for(int i = 0; i < n; ++i)
cin >> stars[i].x >> stars[i].y >> stars[i].s;
for(int t = 0; t <= c; ++t)
{
for(int i = 0; i < n; ++i)
table[t][stars[i].x][stars[i].y] += stars[i].s;
for(int i = 1; i < 110; ++i)
for(int j = 1; j < 110; ++j)
table[t][i][j] += table[t][i][j-1];
for(int i = 1; i < 110; ++i)
for(int j = 1; j < 110; ++j)
table[t][j][i] += table[t][j-1][i];
for(int i = 0; i < n; ++i) stars[i].s = (stars[i].s+1)%(c+1);
}
int t,x1,y1,x2,y2;
while(q--)
{
cin >> t >> x1 >> y1 >> x2 >> y2;
t %= (c+1);
int res = table[t][x2][y2]-table[t][x1-1][y2]
-table[t][x2][y1-1]+table[t][x1-1][y1-1];
cout << res << endl;
}
return 0;
}