QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#868391#9569. SubwayExusiai1RE 33ms431208kbC++203.5kb2025-01-24 16:43:542025-01-24 16:43:55

Judging History

你现在查看的是最新测评结果

  • [2025-01-24 16:43:55]
  • 评测
  • 测评结果:RE
  • 用时:33ms
  • 内存:431208kb
  • [2025-01-24 16:43:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef pair<ll,ll>pll;
const ll INF=1e18;
const ll MO9=998244353;
const ll MO1=1e9+7;
const ll MO=MO9;
const int N=5e5+5;
ll n,m,k;

namespace lcsegtree{
    const int V=1e6;
    struct Line{
        ll k,b;
        Line():k(0),b(INF){}
        Line(ll K,ll B){
            k=K,b=B;
        }
        ll val(ll x){return k*x+b;}
    };
    int cmp(Line A,Line B,ll x){
        if(A.val(x)==B.val(x))return 0;
        else if(A.val(x)<B.val(x))return 1;
        else return -1;
    }
    struct node{
        Line L;
        int l=0,r=0;
    }tree[N*32];
    int tot=0;
    int root[N];
    void upd(Line L,int&k,int l=1,int r=V){
        if(!k)k=++tot;
        auto&s=tree[k].L;
        int mid=l+r>>1;
        // int cpmid=cmp(L,s,mid);
        if(cmp(L,s,mid))swap(s,L);
        if(cmp(L,s,l))upd(L,tree[k].l,l,mid);
        if(cmp(L,s,r))upd(L,tree[k].r,mid+1,r);
    }
    void update(int u,Line L){
        if(!root[u])root[u]=++tot;
        upd(L,root[u]);
    }
    ll que(ll x,int&k,int l=1,int r=V){
        if(!k)return INF;
        if(l==r)return tree[k].L.val(x);
        int mid=l+r>>1;
        if(x<=mid)return min(tree[k].L.val(x),que(x,tree[k].l,l,mid));
        else return min(tree[k].L.val(x),que(x,tree[k].r,mid+1,r));
    }
    ll query(int u,ll x){
        return que(x,root[u]);
    }
}
using lcsegtree::update;
using lcsegtree::query;

ll a[N];
ll b[N];
struct node{
    ll v,id,w;
    friend bool operator<(const node&a,const node&b){
        return a.w>b.w;
    }
};
map<int,node>mp[N];
map<int,ll>dp[N];
vector<int>vec[N];
ll ans[N];
void solve(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        ans[i]=INF;
    }
    for(int i=1;i<=k;i++)cin>>a[i];
    for(int i=1;i<=k;i++)cin>>b[i];
    for(int i=1;i<=k;i++){
        int p;
        cin>>p;
        int la=0;
        for(int j=1;j<=p;j++){
            ll x,w;
            if(j>1)cin>>w;
            cin>>x;
            vec[x].push_back(i);
            if(j>1){
                mp[i][la]={x,i,w};
            }
            la=x;
        }
    }
    priority_queue<node>pq;
    for(int i=1;i<=n;i++){
        sort(vec[i].begin(),vec[i].end(),[=](int x,int y){
            return a[x]>a[y];
        });
    }
    for(int i=1;i<=k;i++){
        if(mp[i].count(1))pq.push({1,i,0});
    }
    while(!pq.empty()){
        auto t=pq.top();
        pq.pop();
        ll u=t.v,id=t.id,w=t.w;
        // cout<<u<<' '<<id<<' '<<w<<' '<<1<<'\n';
        ans[u]=min(ans[u],w);
        //不换乘
        if(!(dp[u].count(id)&&dp[u][id]<w)){
            dp[u][id]=w;
            if(mp[id].count(u)){
                auto ne=mp[id][u];
                // cout<<ne.v<<' '<<ne.id<<' '<<ne.w+w<<'\n';
                pq.push({ne.v,ne.id,ne.w+w});
            }
            update(u,{b[id],w});
        }
        //换乘
        while(!vec[u].empty()){
            auto t=vec[u].back();
            if(t==id)
            vec[u].pop_back();
            auto res=query(u,a[t]);
            // cout<<u<<' '<<t<<' '<<res<<'\n';
            pq.push({u,t,res});
            break;
        }
    }
    for(int i=2;i<=n;i++){
        cout<<ans[i]<<' ';
    }
    cout<<'\n';

}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int ttt=1;
    // cin>>ttt;
    while(ttt--)
    solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 28ms
memory: 425808kb

input:

6 3
1 5 1
5 5 1
3 1 2 2 3 3
3 5 1 2 1 4
3 3 4 5 4 6

output:

2 5 21 14 18 

result:

ok 5 number(s): "2 5 21 14 18"

Test #2:

score: 0
Accepted
time: 28ms
memory: 426580kb

input:

6 3
1 5 1
5 5 1
5 1 2 2 100 3 100 6 1 4
5 1 100 2 4 3 100 5 1 4
2 3 1 5

output:

2 31 43 37 136 

result:

ok 5 number(s): "2 31 43 37 136"

Test #3:

score: 0
Accepted
time: 29ms
memory: 430256kb

input:

5 9
278281 70119 511791 834898 25300 63487 609134 236836 394497
835557 287345 579404 879128 636344 306393 569430 152565 47119
2 3 823004250 4
2 1 25427550 3
2 1 15849621 3
2 1 701911826 5
3 5 679672631 3 907176714 2
2 1 817370554 2
2 3 697987914 2
2 4 873900795 2
2 1 814305954 5

output:

817370554 15849621 80811085745 701911826 

result:

ok 4 number(s): "817370554 15849621 80811085745 701911826"

Test #4:

score: 0
Accepted
time: 33ms
memory: 431208kb

input:

5 10
436148 103565 528276 212202 680282 92724 609031 560815 80390 406327
546832 581372 731920 348686 791433 98906 112247 118131 361076 724950
4 1 213029090 4 415633732 5 581145231 3
2 4 306227294 2
2 1 713116112 4
2 3 99672714 5
2 3 975143846 1
5 4 249118026 5 689334413 1 597093740 2 553624319 3
3 4...

output:

597093740 765908995 213029090 628662822 

result:

ok 4 number(s): "597093740 765908995 213029090 628662822"

Test #5:

score: 0
Accepted
time: 32ms
memory: 426832kb

input:

3 5
696710 837216 390019 431068 960618
589388 829806 692481 154511 282620
2 1 711629163 3
2 1 781784306 3
2 1 686636041 3
2 3 794790206 2
2 1 844212542 2

output:

844212542 686636041 

result:

ok 2 number(s): "844212542 686636041"

Test #6:

score: 0
Accepted
time: 25ms
memory: 430448kb

input:

3 8
344877 101098 328614 735002 476606 635558 573861 261083
964379 333960 25186 276560 258996 683650 765559 582374
2 3 838262394 1
2 2 863940316 3
2 2 476918371 3
3 3 320092619 1 400754003 2
3 3 150885055 2 90507792 1
2 3 190275693 2
2 2 600234969 3
2 2 679446528 3

output:

400754003 29224357199 

result:

ok 2 number(s): "400754003 29224357199"

Test #7:

score: 0
Accepted
time: 24ms
memory: 430480kb

input:

50 52
895514 29433 851800 887860 340384 95967 506578 666268 850660 602220 717255 242039 34055 752012 248567 170469 505996 823344 143369 390858 112988 892365 15368 617804 351619 557340 788960 990487 283825 272924 24678 130649 341049 980236 558990 254726 682005 963825 953074 603477 706464 340694 23541...

output:

632126151 479346918 492618840 3695787776 22624579200 174047740 416387993526 21429733469 15831777447 203893499 522142321620 977566721 279122223 30345963113 804573598 73397618725 6389037892 224856032596 416404080694 75356833904 69909552850 4504114918 13173874327 1104455938 275720760247 136977429637 22...

result:

ok 49 numbers

Test #8:

score: -100
Runtime Error

input:

50 186
909405 536090 349598 989013 812836 176449 79855 101754 179492 328610 751840 298905 429840 327083 222463 770826 222448 679356 524717 759894 186015 464746 390432 205629 893518 619709 777762 985329 612480 308146 507216 337177 463052 10105 150939 411855 75743 831031 391242 914978 198839 259846 36...

output:


result: