Advertisement
PikMike

Untitled

Dec 30th, 2015
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define pb push_back
  4. #define mp make_pair
  5. #define sz size
  6. #define ll long long
  7. #define ld long double
  8. #define fs first
  9. #define sc second
  10. #define forn(i, f, t) for(int i = f; i < t; i++)
  11. #define all(x) (x).begin(), (x).end()
  12. #define ins insert
  13.  
  14. const int INF = 2147483647;
  15. const int MOD = 1000000007;
  16. const ll INF64 = 9223372036854775807;
  17. const ld EPS = 1e-7;
  18.  
  19. using namespace std;
  20.  
  21.  
  22. int main(){
  23.     int h, w;
  24.     scanf("%d%d", &h, &w);
  25.     string s;
  26.     vector<vector<int> > a(h, vector<int>(w, 0)), b, c, d(h, vector<int>(w, 0)), e(w, vector<int>(h, 0));
  27.     forn(i, 0, h){
  28.         cin >> s;
  29.         forn(j, 0, w) a[i][j] = (s[j] == '.' ? 1 : 0);
  30.     }
  31.     forn(i, 0, h){
  32.         b.pb(vector<int>());
  33.         b[i].pb(0);
  34.         forn(j, 1, w)
  35.             b[i].pb(b[i][j - 1] + (a[i][j] && a[i][j - 1]));
  36.     }
  37.     forn(i, 0, w){
  38.         c.pb(vector<int>());
  39.         c[i].pb(0);
  40.         forn(j, 1, h)
  41.             c[i].pb(c[i][j - 1] + (a[j][i] && a[j - 1][i]));
  42.     }
  43.     int n;
  44.     scanf("%d", &n);
  45.     int x1, y1, x2, y2, ans;
  46.     forn(z, 0, n){
  47.         scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
  48.         ans = 0;
  49.         forn(i, x1 - 1, x2) ans += (b[i][y2 - 1] - b[i][y1 - 1]);
  50.         forn(i, y1 - 1, y2) ans += (c[i][x2 - 1] - c[i][x1 - 1]);
  51.         printf("%d\n", ans);
  52.     }
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement