cf311B. Cats Transport

链接

点击跳转

题解

注意出发时间可能是负数

对每只猫求出:要把这只猫带走,最早啥时候出发

所有的猫按照这个时间排序

然后就成了区间 d p dp dp

斜率优化感觉都忘得差不多了qwq,虽然 w a wa wa了无数遍不过最终还是过了

代码

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define iinf 0x3f3f3f3f
#define linf (1ll<<60)
#define eps 1e-8
#define maxn 1000010
#define maxe 1000010
#define cl(x) memset(x,0,sizeof(x))
#define rep(_,__) for(_=1;_<=(__);_++)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define de(x) cerr<<#x<<" = "<<x<<endl
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll read(ll x=0)
{
    ll c, f(1);
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-f;
    for(;isdigit(c);c=getchar())x=x*10+c-0x30;
    return f*x;
}
ll n, m, d[maxn], sb[maxn], p, dp[105][100010], b[maxn];
pll cat[maxn];
bool ok(pll p1, pll p2, pll p3)
{
    ll x1=p2.first-p1.first, y1=p2.second-p1.second, x2=p3.first-p2.first, y2=p3.second-p2.second;
    return x1*y2-x2*y1 > 0;
}
ll cost(ll l, ll r)
{
    ll ans=0, i;
    // for(i=l;i<=r;i++)
    // {
    //     ans+=b[r]+cat[i].first-cat[i].second;
    // }
    // return ans;
    return (r-l+1)*b[r]-sb[r]+sb[l-1];
}
int main()
{
    ll i, j;
    n=read(), m=read(), p=read();
    rep(i,n-1)d[i+1]=d[i]+read();
    rep(i,m)
    {
        ll h=read(), t=read();
        cat[i]=pll(d[h],t);
    }
    sort(cat+1,cat+m+1,[](pll x, pll y){return x.second-x.first < y.second-y.first;});
    rep(i,m)b[i]=cat[i].second-cat[i].first;
    rep(i,m)sb[i]=sb[i-1]+b[i];
    rep(i,m)dp[1][i]=i*b[i]-sb[i];
    dp[1][0]=0;
    for(j=2;j<=p;j++)
    {
        auto g=dp[j-1], f=dp[j];
        for(i=0;i<=m;i++)f[i]=linf;
        deque<pll> q;
        for(i=1;i<=m;i++)
        {
            pll pt(pll(i-1,g[i-1]+sb[i-1]));
            while(q.size()>1 and !ok(q.at(q.size()-2),q.at(q.size()-1),pt))
                q.pop_back();
            q.emb(pt);
            ll t=q.front().second-q.front().first*b[i];
            while(q.size()>1 and t>q[1].second-q[1].first*b[i])
            {
                t=q[1].second-q[1].first*b[i];
                q.pop_front();
            }
            f[i]=t+i*b[i]-sb[i];
        }
    }
    cout<<dp[p][m];
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
map pfn expected mapping type uncached-minus for [mem 0x7c11f000-0x7c11ffff], got write-back 这个问题怎么解决,这个会导致系统死机吗?PID: 500 TASK: ffff8800740d6dd0 CPU: 4 COMMAND: "mate-settings-d" #0 [ffff88024a6e7988] machine_kexec at ffffffff81059cdb #1 [ffff88024a6e79e8] __crash_kexec at ffffffff81105182 #2 [ffff88024a6e7ab8] crash_kexec at ffffffff81105270 #3 [ffff88024a6e7ad0] oops_end at ffffffff8168ed88 #4 [ffff88024a6e7af8] no_context at ffffffff8167e993 #5 [ffff88024a6e7b48] __bad_area_nosemaphore at ffffffff8167ea29 #6 [ffff88024a6e7b90] bad_area_nosemaphore at ffffffff8167eb93 #7 [ffff88024a6e7ba0] __do_page_fault at ffffffff81691b1e #8 [ffff88024a6e7c00] do_page_fault at ffffffff81691cc5 #9 [ffff88024a6e7c30] page_fault at ffffffff8168df88 [exception RIP: dev_set_drvdata+26] RIP: ffffffff8142c60a RSP: ffff88024a6e7ce8 RFLAGS: 00010206 RAX: 0000000900000000 RBX: ffff880258686098 RCX: 0000000180040001 RDX: ffff8801849e4000 RSI: 0000000000000000 RDI: ffff880258686098 RBP: ffff88024a6e7cf8 R8: ffff8801849e4000 R9: 0000000180040001 R10: 00000000849e6001 R11: ffffea0006127800 R12: ffff880239383398 R13: ffff880239383300 R14: ffff880061c29d08 R15: 0000000000000246 ORIG_RAX: ffffffffffffffff CS: 0010 SS: 0018 #10 [ffff88024a6e7d00] snd_usb_audio_free at ffffffffa059a587 [snd_usb_audio] #11 [ffff88024a6e7d28] snd_usb_audio_dev_free at ffffffffa059a5b2 [snd_usb_audio] #12 [ffff88024a6e7d38] __snd_device_free at ffffffffa02e2dc9 [snd] #13 [ffff88024a6e7d50] snd_device_free_all at ffffffffa02e311b [snd] #14 [ffff88024a6e7d70] release_card_device at ffffffffa02dd7de [snd] #15 [ffff88024a6e7d90] device_release at ffffffff814273f2 #16 [ffff88024a6e7db8] kobject_release at ffffffff8131a29e #17 [ffff88024a6e7de8] kobject_put at ffffffff8131a158 #18 [ffff88024a6e7e00] put_device at ffffffff81427717 #19 [ffff88024a6e7e10] snd_card_file_remove at ffffffffa02de1b4 [snd] #20 [ffff88024a6e7e40] snd_ctl_release at ffffffffa02df421 [snd] #21 [ffff88024a6e7e78] snd_disconnect_release at ffffffffa02ddafd [snd] #22 [ffff88024a6e7ea8] __fput at ffffffff811fff09 #23 [ffff88024a6e7ef0] ____fput at ffffffff812001be #24 [ffff88024a6e7f00] task_work_run at ffffffff810accc7 #25 [ffff88024a6e7f30] do_notify_resume at ffffffff8102ab22 #26 [ffff88024a6e7f50] int_signal at ffffffff8169677d gdb调试的bt,这个怎么判断是什么造成的死机
最新发布
07-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值