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];
- //map<pair<int, int>, int> mapp, mapps;
- 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;
- //mapp[i][j]+=mapp[i-1][j];
- //}
- if (j>1)
- if (ch[i][j]=='.' && ch[i][j-1]=='.' )
- mapp2[i][j]+=1;
- //mapp[i][j]+=mapp[i][j-1];
- //}
- }
- for (int i=1; i<=n; i++)
- for (int j=1; j<=d; j++){
- for (int l=1; l<=i; l++){
- for (int k=1; k<=j; k++){
- mapps1[i][j]+=mapp1[l][k];
- mapps2[i][j]+=mapp2[l][k];
- }
- }
- }
- ll k=0;
- cin >> k;
- /*cout << endl;
- for (int i=1; i<=n; i++)
- {
- for (int j=1; j<=d; j++)
- cout << mapp1[i][j] << ' ';
- cout << endl;
- }
- cout << endl;
- for (int i=1; i<=n; i++)
- {
- for (int j=1; j<=d; j++)
- cout << mapps1[i][j] << ' ';
- cout << endl;
- }
- cout << endl;
- for (int i=1; i<=n; i++)
- {
- for (int j=1; j<=d; j++)
- cout << mapp2[i][j] << ' ';
- cout << endl;
- }
- cout << endl;
- for (int i=1; i<=n; i++)
- {
- for (int j=1; j<=d; j++)
- cout << mapps2[i][j] << ' ';
- cout << endl;
- }*/
- 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 << mapps1[r2][c2] << ' ' << mapps1[r1][c2] << ' ' << mapps1[r2][c1-1] << ' ' << mapps1[r1][c1-1] << endl;
- //cout << mapps2[r2][c2] << ' ' << mapps2[r1-1][c2] << ' ' << mapps2[r2][c1] << ' ' << mapps2[r1-1][c1] << endl;
- /*for (int j=c1; j<=c2; j++)
- res-=mapp2[r1][j];
- for (int j=r1; j<=r2; j++)
- res-=mapp1[j][c1];
- */
- //res-=mapp[r1][c1];
- /*for (int j=r1; j<=r2; j++)
- res-=mapp[j][c1-1]*(r2-r1+1);
- for (int l=c1; l<=c2; l++)
- res-=mapp[r1-1][l]*(r2-r1+1);
- */
- /*for (int j=r1+1; j<=r2; j++){
- for (int l=c1+1; l<=c2; l++){
- res+=mapp[j][l];
- res+=mapps[j][l];
- }
- }
- for (int j=r1+1; j<=r2; j++)
- res+=mapp[j][c1];
- for (int l=c1+1; l<=c2; l++)
- res+=mapps[r1][l];*/
- cout << res << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement