51nod1781 Pinball

Description

Pinball的游戏界面由m+2行、n列组成。第一行在顶端。一个球会从第一行的某一列出发,开始垂直下落,界面上有一些漏斗,一共有m个漏斗分别放在第2~m+1行,第i个漏斗的作用是把经过第i+1行且列数在Ai~Bi之间的球,将其移到下一行的第Ci列。 使用第i个漏斗需要支付Di的价钱,你需要保留一些漏斗使得球无论从第一行的哪一列开始放,都只可能到达第m+2行的唯一 一列,求花费的最少代价。

Input

第一行两个数,m和n。m<=100000,2<=n<=1000000000
接下来m行,第i+1行描述第i个漏斗的属性,Ai,Bi,Ci,Di (1<=Ai<=Ci<=Bi<=n, 1<=Di<=1000000000)。

Output

若不存在一种方案能满足条件则输出-1,否则输出最小花费

Input示例

5 6
3 5 4 8
1 4 3 5
4 6 5 7
5 6 5 3
3 5 4 12

Output示例

20

Solution

我们发现 第一列和第n列 有且仅有一个重复使用的漏斗 就是最后一个
因为如果1和n都已经在一起了,就没有必要再用别的漏斗了
我们定义l[i]为第一列最后使用第i个漏斗的答案
r[i]同理
l[i]=min(a[i].l,a[i].r)+d[i]
最小值用线段树维护
ans=(l[i]+r[i]-d[i])

code

#include <cstdio>
#include <cstring>
#include <algorithm>
#define L rt<<1
#define R rt<<1|1 
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int N=100005;
typedef long long ll;
ll a[N],b[N],c[N],d[N],q[3*N],k;
ll n,m,h1,h2,i,ans,tr[N*12],l[N],r[N];
ll read(){
    ll sum=0;
    char c=getchar();
    while (c<'0'||c>'9') c=getchar();
    while (c>='0'&&c<='9') {
        sum=sum*10+c-'0';
        c=getchar();}
    return sum;
}
inline void build(ll rt,ll l,ll r){
    tr[rt]=1e17;
    if (l==r) return;
    ll mid=(l+r)>>1;
    build(L,l,mid);
    build(R,mid+1,r);
}
inline void update(ll rt,ll l,ll r,ll x,ll z){
    if (l==r){
        tr[rt]=min(tr[rt],z);
        return;}
    ll mid=(l+r)>>1;
    if (x<=mid) update(L,l,mid,x,z);
      else update(R,mid+1,r,x,z);
    tr[rt]=min(tr[L],tr[R]);
}
inline ll query(ll rt,ll l,ll r,ll x,ll y){
    if (l>=x&&y>=r) return tr[rt];
    ll mid=(l+r)>>1;
    ll ans=1e17;
    if (x<=mid) ans=min(ans,query(L,l,mid,x,y));
    if (y>mid)  ans=min(ans,query(R,mid+1,r,x,y));
    return ans;
}
int main(){
//  freopen("1.in","r",stdin);
//  freopen("1.out","w",stdout);
    m=read(); n=read();
    fo(i,1,m){
        a[i]=read(),b[i]=read(),c[i]=read(),d[i]=read();
        q[++q[0]]=a[i],q[++q[0]]=b[i]; q[++q[0]]=c[i];}
    q[++q[0]]=1,q[++q[0]]=n;
    sort(q+1,q+q[0]+1);
    q[0]=unique(q+1,q+q[0]+1)-q-1;
    fo(i,1,m) {
        a[i]=lower_bound(q+1,q+q[0]+1,a[i])-q;
        b[i]=lower_bound(q+1,q+q[0]+1,b[i])-q;
        c[i]=lower_bound(q+1,q+q[0]+1,c[i])-q;
    }
    h1=1; h2=lower_bound(q+1,q+q[0]+1,n)-q;
    build(1,1,h2);
    update(1,1,h2,h1,0);
    fo(i,1,m){
        k=query(1,1,h2,a[i],b[i]);
        l[i]=k+d[i];
        update(1,1,h2,c[i],l[i]);
    }
    build(1,1,h2);
    update(1,1,h2,h2,0);
    fo(i,1,m){
        k=query(1,1,h2,a[i],b[i]);
        r[i]=k+d[i];
        update(1,1,h2,c[i],r[i]);
    }
    ans=1e17;
    fo(i,1,m) ans=min(ans,l[i]+r[i]-d[i]);
    if (ans>=1e17) printf("-1\n"); else printf("%lld\n",ans);
}
封装系统减肥用,新手使用 慎慎慎 [AutoRunDir] DirName1 = www.FreeSkyCD.cn DirName2 = KEYFree2008 ;定义所有硬盘/U盘“驱动器:\AutoRun.inf\www.FreeSkyCD.cn\KEYFree2008.”目录 [StringData] GUITitle = 系统清理&减肥程序 by-选择自由 ;定义窗口标题内容 Default1 = 1,2,3,4,5,6,7,8,9,10,11,12,13,16,19,20,21,22,23,24,26,45,51 ;定义默认选定项目 Default2 = 1,2,3,4,5,6,7,8,9,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,39,40,41,42,43,44,45,46,47,49,50,51 ;定义封装推荐选定项目 系统清理: 1 = 回收站目录,X,Recycl* 2 = 系统还原目录,X,System Vol* 3 = 系统临时文件,C:\Windows\Temp\,* 4 = 用户临时文件,C:\Documents and Settings\Administrator\Local Settings\Temp\,* 5 = 网页临时文件,C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files\,*,0,1 6 = 系统垃圾文件,C:\Windows\/C:\Windows\System32\,*.tmp/*._mp/*.log/*.gid/*.old/*.chk/*.bak,1,1 7 = 最近文档记录,C:\Documents and Settings\Administrator\Recent\,*,1,1 8 = 网络邻居记录,C:\Documents and Settings\Administrator\NetHood\,* 9 = 网页历史记录,C:\Documents and Settings\Administrator\Local Settings\History\,* 10 = IE地址栏记录,HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs,*,0,1 11 = 程序运记录,HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU,*,0,1 12 = 系统搜索记录,HKEY_CURRENT_USER\Software\Microsoft\Search Assistant\ACMru,*,0,1 13 = REG最后访问位置,HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit,*,0,1 14 = 收藏夹目录,C:\Documents and Settings\Administrator\Favorites\,* 15 = Cookies数据,C:\Documents and Settings\Administrator\Cookies\,*,0,1 16 = Auto病毒相关,X,AutoRun.inf,0,1 17 = 系统休眠文件,X,HiberFil.sys 18 = 虚拟内存文件,X,PageFile.sys 19 = 程序预读文件,C:\Windows\Prefetch\,*,0,1 20 = 磁盘修复备份,X,Found.* 21 = 安装程序备份1,C:\Windows\Installer\,*.msi/*.msp/$*$ 22 = 安装程序备份2,C:\Program Files\InstallShield Installation Information\,*,0,1 23 = 补丁下载目录,C:\Windows\SoftwareDistribution\Download\,*,0,1 24 = 补丁备份目录,C:\Windows\,$*$/KB*,0,1 25 = 补丁生成驱动备份,C:\Windows\Driver Cache\I386\,Nt*.exe 26 = 未完成的打印任务,C:\Documents and Settings\Administrator\PrintHood\,* 系统减肥: 27 = 韩文输入法,C:\Windows\Ime\Imkr6_1\/C:\Windows\Ime\Imkr6_1\Applets\,Dicts/Help/*.dll/*.exe/*.ini 28 = 日文输入法,C:\Windows\Ime\Imjp8_1\/C:\Windows\Ime\Imjp8_1\Applets\,Dicts/Help/*.dll/*.exe/*.ini 29 = 繁体输入法,C:\Windows\Ime\Chtime\Applets\,* 30 = 注音输入法,C:\Windows\System32\Ime\Tintlgnt\,* 31 = 仓颉码输入法,C:\Windows\System32\Ime\Cintlgnt\,* 32 = 三维弹球游戏,C:\Program Files\Windows NT\Pinball\/C:\Documents and Settings\All Users\「开始」菜单\程序\游戏\,*.dat/*.mid/*.exe/*.wav/*.bmp/*.inf/桌上弹球*,0,1 33 = 微软在线游戏,C:\Program Files\MSN Gaming Zone\Windows\/C:\Documents and Settings\All Users\「开始」菜单\程序\游戏\,*.dll/*.exe/Internet* 34 = 微软代理助手,C:\Windows\msagent\,chars/Ag*.*/*.dll 35 = 系统搜索助手,C:\Windows\Srchasst\,chars/*.dll/*.lex 36 = 系统激活程序,C:\Windows\System32\Oobe\,*,0,1 37 = Messenger程序,C:\Program Files\Messenger\/C:\Documents and Settings\All Users\「开始」菜单\程序\,*.dll/*.gif/*.exe/*.wav/*.chm/Windows Messenger.lnk 38 = NetMeeting 程序,C:\Program Files\NetMeeting\,* 39 = Movie Maker程序,C:\Program Files\Movie Maker\/C:\Documents and Settings\All Users\「开始」菜单\程序\,Mui/Shared/*.exe/*.dll/Windows Movie Maker.lnk 40 = 韩文字体,C:\Windows\Fonts\,Batang.ttc 41 = 日文字体,C:\Windows\Fonts\,Msmincho.ttc 42 = 帮助相关文件,C:\Windows\Help\/C:\Windows\Pchealth\,*,0,1 43 = 图标缓存文件,C:\Documents and Settings\Administrator\Local Settings\Application Data\,IconCache.db 44 = 桌面壁纸文件,C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\,Wallpaper1.bmp 45 = WMP 更新备份,C:\Windows\RegisteredPackages\,*,0,1 46 = 硬件驱动备份,C:\Windows\System32\ReinstallBackups\,* 47 = 重要文件备份,C:\Windows\System32\Dllcache\,*,0,1 48 = 注册表相关备份,C:\Windows\Repair\,*,0,1 49 = 驱动预编译文件,C:\Windows\Inf\,*.pnf,0,1 50 = 最后一次正确配置,C:\Windows\,LastGoo* 51 = 恶意软件清理工具,C:\Windows\System32\,Mrt.exe 52 =
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值