Bzoj 2597 Building Rebuilding Tiles

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.