Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- int main(){
- cin.sync_with_stdio(false);
- cout.sync_with_stdio(false);
- ll n, d;
- char ch[501][501];
- int mapp1[501][501] {};
- int mapps1[501][501] {};
- int mapp2[501][501] {};
- int mapps2[501][501] {};
- cin >> n >> d;
- for (int i=1; i<=n; i++)
- for (int j=1; j<=d; j++)
- cin >> ch[i][j];
- for (int i=1; i<=n; i++)
- for (int j=1; j<=d; j++){
- if (i>1)
- if (ch[i][j]=='.' && ch[i-1][j]=='.' )
- mapp1[i][j]+=1;
- mapps1[i][j]=mapps1[i-1][j]+mapps1[i][j-1]-mapps1[i-1][j-1];
- mapps1[i][j]+=mapp1[i][j];
- if (j>1)
- if (ch[i][j]=='.' && ch[i][j-1]=='.' )
- mapp2[i][j]+=1;
- mapps2[i][j]=mapps2[i-1][j]+mapps2[i][j-1]-mapps2[i-1][j-1];
- mapps2[i][j]+=mapp2[i][j];
- }
- ll k=0;
- cin >> k;
- for (int i=0; i<k; i++){
- ll res=0;
- ll r1, r2, c1, c2;
- cin >> r1 >> c1 >> r2 >> c2;
- res = mapps1[r2][c2]+mapps2[r2][c2]-mapps2[r2][c1]-mapps1[r1][c2]-mapps2[r1-1][c2]-mapps1[r2][c1-1]+mapps1[r1][c1-1]+mapps2[r1-1][c1];
- cout << res << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement