# bzoj 3716: [PA2014]Muzeum

## Solution

$\frac{P_x-Z_x}{P_y-Z_y}<=\frac{w}{h}$
$\frac{Z_x-P_x}{P_y-Z_y}<=\frac{w}{h}$

$h*P_x-w*P_y<=h*Z_x-w*Z_y$
$h*P_x+w*P_y>=h*Z_x+w*Z_y$
$x$ 都变为 $x*h$,$y$ 都变成 $y*w$ 坐标变为 $(x-y,x+y)$ 之后

$Z_x>=P_x\,\,\&\&\,\,Z_y<=P_y$

#include<bits/stdc++.h>
using namespace std;
template<class T>void gi(T &x){
int f;char c;
for(f=1,c=getchar();c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
for(x=0;c<='9'&&c>='0';c=getchar())x=x*10+(c&15);x*=f;
}
typedef long long ll;
const int N=4e5+10;
int n,m,W,H,v[N];ll ans=0,Y[N];
struct data{
ll x,y;int id;
inline bool operator <(const data &p)const{
if(x!=p.x)return x>p.x;
return id<p.id;
}
}p[N];
struct comp{bool operator ()(int i,int j){return Y[i]!=Y[j]?Y[i]<Y[j]:i<j;}};
set<int,comp>S;
set<int,comp>::iterator it;int top=0,st[N];
int main(){
freopen("pp.in","r",stdin);
freopen("pp.out","w",stdout);
int cnt=0;ll x,y;
cin>>n>>m>>W>>H;
for(int i=1;i<=n+m;i++){
gi(x);gi(y);gi(v[i]);
x*=H;y*=W;
p[++cnt]=(data){x-y,Y[i]=x+y,i};
}
for(int i=1;i<=n;i++)ans+=v[i];
sort(p+1,p+cnt+1);
for(int i=1;i<=cnt;i++){
if(p[i].id<=n)S.insert(p[i].id);
else{
x=p[i].id;
it=S.upper_bound(x);
if(it==S.begin())continue;
for(--it;;--it){
int t=min(v[*it],v[x]);
v[x]-=t;v[*it]-=t;ans-=t;
if(!v[*it])st[++top]=*it;
else break;
if(it==S.begin())break;
}
while(top)S.erase(st[top--]);
}
}
cout<<ans<<endl;
return 0;
}


posted @ 2018-05-03 10:51  PIPIBoss  阅读(200)  评论(0编辑  收藏  举报