题目链接:https://vjudge.net/problem/964309/origin
暴力记录所有时间二维前缀和即可
#include<bits/stdc++.h>
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=2e5+100;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){
if(y==0) return x;
return gcd(y,x%y);
}
int n,q,c,x,y,z;
int t,x2,y2;
int dp[15][101][101];
int main(){
cin>>n>>q>>c;c++;
rep(i,0,n){
cin>>x>>y>>z;
rep(j,0,12){
dp[j][x][y]+=(z+j)%c;
}
}
rep(i,0,12) rep(j,1,101) rep(k,1,101){
dp[i][j][k]+=dp[i][j-1][k]+dp[i][j][k-1]-dp[i][j-1][k-1];
}
rep(i,0,q){
cin>>t>>x>>y>>x2>>y2;
t%=c;
cout<<dp[t][x2][y2]-dp[t][x-1][y2]-dp[t][x2][y-1]+dp[t][x-1][y-1]<<endl;
}
return 0;
}