zoukankan      html  css  js  c++  java
  • URAL1097. Square Country 2

    XLIII.URAL1097. Square Country 2

    考虑二分,二分后转成判定性问题,然后用扫描线+线段树处理即可。时间复杂度 \(O(n\log^2n)\)

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    int n,m,q;
    struct Land{
    	int x,yl,yr,imp;
    	Land(){}
    	Land(int X,int YL,int YR,int I){x=X,yl=YL,yr=YR,imp=I;}
    	friend bool operator<(const Land&u,const Land&v){return u.x<v.x;}
    }p[210];
    #define lson x<<1
    #define rson x<<1|1
    #define mid ((l+r)>>1)
    struct SegTree{int tag,mn;}seg[40100];
    void ADD(int x,int y){seg[x].tag+=y,seg[x].mn+=y;}
    void pushdown(int x){ADD(lson,seg[x].tag),ADD(rson,seg[x].tag),seg[x].tag=0;}
    void pushup(int x){seg[x].mn=min(seg[lson].mn,seg[rson].mn);}
    void modify(int x,int l,int r,int L,int R,int val){
    	if(l>R||r<L)return;
    	if(L<=l&&r<=R)ADD(x,val);
    	else pushdown(x),modify(lson,l,mid,L,R,val),modify(rson,mid+1,r,L,R,val),pushup(x);
    }
    bool che(int ip){
    	memset(seg,0,sizeof(seg));
    	for(int i=1,j=1;i<=n-m+1;i++){
    		for(;j<=2*q&&p[j].x<=i;j++){
    			if(abs(p[j].imp)<=ip)continue;
    			if(p[j].imp>0)modify(1,1,n-m+1,p[j].yl,p[j].yr,1);else modify(1,1,n-m+1,p[j].yl,p[j].yr,-1);
    		}
    		if(seg[1].mn==0)return true;
    	}
    	return false;
    }
    int main(){
    	scanf("%d%d%d",&n,&m,&q);
    	for(int i=1,I,L,X,Y;i<=q;i++){
    		scanf("%d%d%d%d",&I,&L,&X,&Y);
    		p[i]=Land(max(1,X-m+1),max(1,Y-m+1),min(Y+L-1,n-m+1),I);
    		p[q+i]=Land(X+L,max(1,Y-m+1),min(Y+L-1,n-m+1),-I);
    	}
    	sort(p+1,p+2*q+1);
    //	for(int i=1;i<=2*q;i++)printf("%d[%d,%d]:%d\n",p[i].x,p[i].yl,p[i].yr,p[i].imp);
    	int l=1,r=100;
    	while(l<r){
    		int md=(l+r)>>1;
    		if(che(md))r=md;
    		else l=md+1;
    	}
    	if(!che(l))puts("IMPOSSIBLE");else printf("%d\n",l);
    	return 0;
    }
    

  • 相关阅读:
    AMap公交线路查询
    AMap行政区查询服务
    使用JavaScript的Join方法
    获取layer.open弹出层的返回值
    MVC项目中WebViewPage的实战应用
    ASP.NET管道
    Android接收系统广播
    python字符串转换成数字
    mysql缓存
    两个矩阵对应位置的数据相加,并返回一个矩阵
  • 原文地址:https://www.cnblogs.com/Troverld/p/14612783.html
Copyright © 2011-2022 走看看