-
Notifications
You must be signed in to change notification settings - Fork 3
/
1573.cpp
29 lines (29 loc) · 916 Bytes
/
1573.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <bits/stdc++.h>
using namespace std;
const int maxn = 205;
int arr[maxn][maxn], dp[maxn][maxn][25], n, q;
int main(){
//freopen("../input.txt", "r", stdin);
//freopen("../output.txt", "w", stdout);
cin>>n;
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>arr[i][j];
memset(dp, 0, sizeof(dp));
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){
for(int k=0;k<25;k++) dp[i][j][k] = dp[i][j-1][k];
dp[i][j][arr[i][j]]++;
}
cin>>q;
for(int _=0;_<q;_++){
int i, j, k; cin>>i>>j>>k;
int ans = 0;
for(int x=1;x<25;x++) if(k % x == 0){
for(int a=max(0,i-k);a<=min(n,i+k);a++) {
int d = k - abs(a - i);
int br = min(n,j+d), bl = max(0,j-d-1);
ans += dp[a][br][x] - dp[a][bl][x];
}
}
cout<<ans<<endl;
}
return 0;
}