The topic probably says to a n*m lattice, lattice '. ' Indicates that you can put something, ask the rectangular area (x1,y1) multiple times-(X2,Y2) There are several schemes to put a 1*2 domino.
Consider, respectively, horizontal vertical, preprocessing the two-dimensional prefix and, that is, Sum[x][y] (x, y) of the number of horizontal or vertical put, and then for each query is split into a few prefixes and a bit of a reprimand.
Attention to detail. The dominoes are 1*2.
1#include <cstdio>2#include <cstring>3 using namespacestd;4 Charmap[555][555];5 inthsum[555][555],vsum[555][555];6 intMain () {7 intn,m;8scanf"%d%d",&n,&m);9 for(intI=1; i<=n; ++i) {Ten for(intj=1; j<=m; ++j) { Onescanf"%c",&map[i][j]); A } - } - the for(intI=1; i<=n; ++i) { - for(intj=2; j<=m; ++j) { - intT= (map[i][j]=='.'&& map[i][j-1]=='.'); - if(i==0){ +hsum[i][j]=hsum[i][j-1]+T; -}Else{ +hsum[i][j]=hsum[i][j-1]+hsum[i-1][j]-hsum[i-1][j-1]+T; A } at } - } - for(intI=2; i<=n; ++i) { - for(intj=1; j<=m; ++j) { - intT= (map[i][j]=='.'&& map[i-1][j]=='.'); - if(j==0){ invsum[i][j]=vsum[i-1][j]+T; -}Else{ tovsum[i][j]=vsum[i][j-1]+vsum[i-1][j]-vsum[i-1][j-1]+T; + } - } the } * $ intQ,x1,y1,x2,y2;Panax Notoginsengscanf"%d",&q); - while(q--){ thescanf"%d%d%d%d",&x1,&y1,&x2,&y2); + intRes=hsum[x2][y2]-hsum[x2][y1]-hsum[x1-1][y2]+hsum[x1-1][y1]; ARes+=vsum[x2][y2]-vsum[x2][y1-1]-vsum[x1][y2]+vsum[x1][y1-1]; theprintf"%d\n", res); + } - return 0; $}
Codeforces 611C New Year and Domino (two-dimensional prefix and)