zoukankan      html  css  js  c++  java
  • [ZJOI2010] 基站选址

    TheLostWeak 讲解得十分清楚,就不造轮子了

    #include <bits/stdc++.h>
    #define ll long long 
    #define ls (x<<1)
    #define rs (x<<1|1)
    using namespace std;
    
    const int N=2e4+10;
    const int inf=0x3f3f3f3f;
    
    int n,K;
    int d[N],c[N],s[N],w[N],f[N];
    vector<pair<int,int>> L[N];
    
    int val[N<<2],tag[N<<2];
    void psh(int x) {
    	if(!tag[x]) return;
    	val[ls]+=tag[x],tag[ls]+=tag[x];
    	val[rs]+=tag[x],tag[rs]+=tag[x];
    	tag[x]=0;
    }
    void build(int x,int l,int r) {
    	tag[x]=0;
    	if(l==r) {val[x]=f[l]; return;}
    	int mid=(l+r)>>1;
    	build(ls,l,mid); 
    	build(rs,mid+1,r);
    	val[x]=min(val[ls],val[rs]);
    }
    int query(int x,int l,int r,int L,int R) {
    	if(L<=l&&r<=R) return val[x];
    	int mid=(l+r)>>1,ret=inf; psh(x);
    	if(L<=mid) ret=query(ls,l,mid,L,R);
    	if(mid<R) ret=min(ret,query(rs,mid+1,r,L,R));
    	return ret;
    }
    void modify(int x,int l,int r,int L,int R,int w) {
    	if(L>R) return;
    	if(L<=l&&r<=R) {val[x]+=w; tag[x]+=w; return;}
    	int mid=(l+r)>>1; psh(x);
    	if(L<=mid) modify(ls,l,mid,L,R,w);
    	if(mid<R) modify(rs,mid+1,r,L,R,w);
    	val[x]=min(val[ls],val[rs]);
    }
    
    int main() {
    	scanf("%d%d",&n,&K); 
    	for(int i=2; i<=n; ++i) scanf("%d",d+i);
    	for(int i=1; i<=n; ++i) scanf("%d",c+i);
    	for(int i=1; i<=n; ++i) scanf("%d",s+i);
    	for(int i=1; i<=n; ++i) scanf("%d",w+i);
    	n++; K++; d[n]=inf; w[n]=inf; 
    	for(int i=1; i<=n; ++i) {
    		int l=lower_bound(d+1,d+n+1,d[i]-s[i])-d;
    		int r=upper_bound(d+1,d+n+1,d[i]+s[i])-d-1;
    		L[r].push_back({l,w[i]});
    	}
    	for(int i=1,sum=0; i<=n; ++i) {
    		f[i]=sum+c[i];
    		for(auto p:L[i]) sum+=p.second;
    	}
    	for(int T=2; T<=K; ++T) {
    		build(1,1,n); memset(f,inf,sizeof f);
    		for(int i=T; i<=n; ++i) {
    			for(auto p:L[i-1]) modify(1,1,n,T-1,p.first-1,p.second);
    			f[i]=query(1,1,n,1,i)+c[i];
    		}
    	}
    	printf("%d
    ",f[n]);
    	return 0;
    }
    
  • 相关阅读:
    HDU 1013 Digital Roots
    HDU 1290 献给杭电五十周年校庆的礼物
    几何分割问题
    HDU 1222 Wolf and Rabbit
    HDU 1997 汉诺塔VII
    HDU 1443 Joseph
    HTML的标题样式
    HDU 1568 Fibonacci
    Hope
    HDU 1071 The area
  • 原文地址:https://www.cnblogs.com/nosta/p/11032258.html
Copyright © 2011-2022 走看看