(Block) the reconstruction of buildings HYSBZ - 2957

The meaning of problems

Coordinate axis of length n, from every point on the building has a 1-n, acquaintance building height is 0, the height of a building each day is modified (may change), a building can be seen if and only if the connection its highest point and the far point of connection does not intersect with the other before, ask a few buildings you can see every day how much.

Thinking

In fact, this question can also be done with a tree line, but the feeling is more complicated.
Pretreatment
First we will play the entire root section blocked into N blocks, each section maintaining two values, the maximum section height of the building, the building and the number of sections can be seen, a building block that can be seen height must be incremental, so the pre-treatment time, only need to record the next block of buildings with a maximum height of buildings within the increment on the line, as can be seen how relatively highly, we can compare the slope of the building, if the slope is large, it must be seen.
Highly modified
this should be the difficulty of solving the problem, how highly modified, in fact, think about it too hard. Since only a single point of modification, and do not know the specific circumstances of the original is modified within the block, so be modified within the entire block where we can directly point to the re-count the maximum height, and buildings can be seen.
Queries
Because statistics can be seen all the buildings, so there is no case of incomplete blocks, each block for the number of buildings that can be seen, must be greater than the maximum height of a block, so the dichotomy found in the block building block is larger than a number of positions that can be seen can be obtained within a block of buildings

Code

#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
 using namespace std;
 const int maxn=1e5+20;
 int a[maxn],n,m,bl;
 double b[maxn];
 vector<double> v[400];
 void update(int x,int y)
 {
 	b [x] = 1.0 * y / x;
 	int pos=a[x];
 	v[pos].clear();
 	double kmax=0;
 	for(int i=bl*(pos-1)+1;i<=min(bl*pos,n);i++){
 		if(b[i]>kmax)
 			v[pos].push_back(b[i]),kmax=b[i];
	 }
 }
 void query()
 {
 	double kmax=0;
 	int years = 0;
 	for(int i=1;i<=a[n];i++){
 		ans+=(v[i].end()-upper_bound(v[i].begin(),v[i].end(),kmax));
 		if(!v[i].empty())
 			kmax=max(kmax,v[i][v[i].size()-1]);
	 }
	printf("%d\n",ans);
 }
 int main ()
 {
 	while(scanf("%d%d",&n,&m)!=EOF){
 	for(int i=0;i<400;i++)
 		v[i].clear();
 	bl=sqrt(n);
 	for(int i=1;i<=n;i++)
 		a[i]=(i-1)/bl+1;
 	for(int i=0;i<m;i++){
 		int x,y;
 		scanf("%d%d",&x,&y);
 		update(x,y);
 		query();
	  }
	}
	return 0;
  } 

  

Guess you like

Origin www.cnblogs.com/overrate-wsj/p/12168918.html