Advertisement
Alexandre_lsv

Untitled

Mar 17th, 2016
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1.     #include <bits/stdc++.h>
  2.     using namespace std;
  3.     typedef long long ll;
  4.     typedef long double ld;
  5.     int main(){
  6.         cin.sync_with_stdio(false);
  7.         cout.sync_with_stdio(false);
  8.         ll n, d;
  9.         char ch[501][501];
  10.         int mapp1[501][501] {};
  11.         int mapps1[501][501] {};
  12.         int mapp2[501][501] {};
  13.         int mapps2[501][501] {};
  14.  
  15.         cin >> n >> d;
  16.         for (int i=1; i<=n; i++)
  17.             for (int j=1; j<=d; j++)
  18.                 cin >> ch[i][j];
  19.         for (int i=1; i<=n; i++)
  20.             for (int j=1; j<=d; j++){
  21.                 if (i>1)
  22.                     if (ch[i][j]=='.' && ch[i-1][j]=='.' )
  23.                             mapp1[i][j]+=1;
  24.                     mapps1[i][j]=mapps1[i-1][j]+mapps1[i][j-1]-mapps1[i-1][j-1];
  25.                     mapps1[i][j]+=mapp1[i][j];
  26.                 if (j>1)
  27.                         if (ch[i][j]=='.' && ch[i][j-1]=='.' )
  28.                             mapp2[i][j]+=1;
  29.                     mapps2[i][j]=mapps2[i-1][j]+mapps2[i][j-1]-mapps2[i-1][j-1];
  30.                     mapps2[i][j]+=mapp2[i][j];
  31.             }
  32.         ll k=0;
  33.         cin >> k;
  34.         for (int i=0; i<k; i++){
  35.             ll res=0;
  36.             ll r1, r2, c1, c2;
  37.             cin >> r1 >> c1 >> r2 >> c2;
  38.             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];
  39.             cout << res << endl;
  40.         }
  41.         return 0;
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement