Title: Given n building, the initial height of 0, each time can change the height of a building, for each change in height from the origin can be seen several buildings
Record the slope of the connection between the roof and the origin of each building. The building is visible when and only the slope of all buildings in the current polygon is less than this building.
Divide n buildings into √ (0.5*N*LOGN) blocks to maintain a monotonically ascending subsequence in each piece (note not LCS) For example, 4 1 2 3 5 So the maintenance sequence is 4 5.
Change the time of the block violence reconstruction then query follow the block to the current maximum value and then go to the next block to find the first value that is larger than the maximum value and then the answer && update maximum value
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include < algorithm> #define M 100100#define EPS 1e-10using namespace std;struct block{double elements[1010];int tot,l,r;void Rebuild (); int Get_ans (double& x);} Blocks[120];int n,m,b;double a[m];int belong[m];void Block:: Rebuild () {int i;double temp=0;tot=0;for (i=l;i<=r;i++) if (a[i]>temp+eps) temp=a[i],elements[++tot]=a[i];} int Block:: Get_ans (double& x) {int re= (tot+1)-(Upper_bound (elements+1,elements+tot+1,x+eps)-elements); if (re) x= Elements[tot];return re;} int main () {int i,j,x,y;cin>>n>>m;b= (int) sqrt (n*log (n)/log (2)/2); for (I=1; (i-1) *b+1<=n;i++) {blocks[ I].l= (i-1) *b+1;blocks[i].r=min (i*b,n);} for (i=1;i<=n;i++) belong[i]= (i-1)/b+1;for (i=1;i<=m;i++) {scanf ("%d%d", &x,&y); a[x]= (double) y/x; BLOCKS[BELONG[X]]. Rebuild ();d ouble temp=0;int ans=0;for (j=1;blocks[j].l;j++) ans+=blocks[j]. Get_ans (temp);p rintf ("%d\n", Ans); return 0;}
Bzoj 2597 Building Rebuilding Tiles