Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define mp make_pair
- #define sz size
- #define ll long long
- #define ld long double
- #define fs first
- #define sc second
- #define forn(i, f, t) for(int i = f; i < t; i++)
- #define all(x) (x).begin(), (x).end()
- #define ins insert
- const int INF = 2147483647;
- const int MOD = 1000000007;
- const ll INF64 = 9223372036854775807;
- const ld EPS = 1e-7;
- using namespace std;
- int main(){
- int h, w;
- scanf("%d%d", &h, &w);
- string s;
- vector<vector<int> > a(h, vector<int>(w, 0)), b, c, d(h, vector<int>(w, 0)), e(w, vector<int>(h, 0));
- forn(i, 0, h){
- cin >> s;
- forn(j, 0, w) a[i][j] = (s[j] == '.' ? 1 : 0);
- }
- forn(i, 0, h){
- b.pb(vector<int>());
- b[i].pb(0);
- forn(j, 1, w)
- b[i].pb(b[i][j - 1] + (a[i][j] && a[i][j - 1]));
- }
- forn(i, 0, w){
- c.pb(vector<int>());
- c[i].pb(0);
- forn(j, 1, h)
- c[i].pb(c[i][j - 1] + (a[j][i] && a[j - 1][i]));
- }
- int n;
- scanf("%d", &n);
- int x1, y1, x2, y2, ans;
- forn(z, 0, n){
- scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
- ans = 0;
- forn(i, x1 - 1, x2) ans += (b[i][y2 - 1] - b[i][y1 - 1]);
- forn(i, y1 - 1, y2) ans += (c[i][x2 - 1] - c[i][x1 - 1]);
- printf("%d\n", ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement