HZOI20190813 B, any one of (duty)

Face questions: go to a magical page: https://www.cnblogs.com/Juve/articles/11352426.html

I heard that beat O (nmq) 70

It is clear that bloggers only 50 minutes

Test sites: the prefix and the integrated application

Scalar operators: for FIG ring does not contain the number of blocks = communicating Points - the number of sides, the two-dimensional prefix and pretreatment, O (1) to find the number of points and sides within a rectangular region.

A good 70 minutes to write the algorithm: for each group seeking the number of inquiries are violent communication block complexity is O (NMQ), people think that can be a problem through the first seven test points in the examination room, a moderate level of most players. the best strategy is to use this algorithm for 70 minutes to allow time for thinking of the third question.

3,4,5,6 other practice test points: the use of standard and count the same lines, but do not need a prefix and a two-dimensional, as it is easier to solve.

8,9 The purpose of the test points is constant is too large to take care of the players and to open a small array of players.

This problem is actually a problem AtCoder Grand Contest C 015, there may be some players did because the original question and quickly get a high score in this question, but do not expect much

The official title of the solution Liu_runda

In fact, you will find a sample hand to play with, a number of China Unicom rectangular blocks equal to the number of black spots all inside the rectangle minus the number of edges connecting points between all black

Maintenance and three prefixes, respectively, the number of black points exist, the number of sides on a line, the number of edges on the column so can be O (1) Query

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#define re register
#define MAXN 2005
using namespace std;
int n,m,q,mapa[MAXN][MAXN];
int sum[MAXN][MAXN],sumh[MAXN][MAXN],suml[MAXN][MAXN];
int dx[2]={-1,0},dy[2]={0,-1},h[MAXN][MAXN],l[MAXN][MAXN];
char ch[MAXN];
signed main(){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=n;i++){
		scanf("%s",ch+1);
		for(int j=1;j<=m;j++){
			mapa[i][j]=ch[j]-'0';
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+mapa[i][j];// prefix and the total number of black dots 
	for (int I =. 1; I <= n-; I ++) {
	}
		}
		for (int. 1 = J; J <= m; J ++) {
			if(mapa[i][j]==0) continue;
			for(int k=0;k<=1;k++){
				int p=i+dx[k],q=j+dy[k];
				if(mapa[p][q]==0) continue;
				if(k==0) h[p][q]++;
				else l[p][q]++;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			sumh[i][j]=sumh[i-1][j]+sumh[i][j-1]-sumh[i-1][j-1]+h[i][j];
			suml[i][j]=suml[i-1][j]+suml[i][j-1]-suml[i-1][j-1]+l[i][j];//内部边数的前缀和(行与列)
		}
	}
	for(int i=1,sx,sy,ex,ey;i<=q;i++){
		scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
		int res1=sum[ex][ey]-sum[sx-1][ey]-sum[ex][sy-1]+sum[sx-1][sy-1];
		int res2 = suml [from] [ey-1] -suml [X-1] [ey-1] -suml [from] [sy-1] + suml [X-1] [sy-1]; 
		res3 sumh int = [on-1] [key] -sumh [X-1] [key] -sumh [on-1] [sy-1] + sumh [X-1] [sy-1]; 
		int ans = res1-res2-res3; 
		printf ( "% d \ n", ans); 
	} 
	Return 0; 
}

 

Guess you like

Origin www.cnblogs.com/Juve/p/11352508.html