QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#868400#9569. SubwayExusiai1WA 36ms431400kbC++203.5kb2025-01-24 16:48:052025-01-24 16:48:07

Judging History

This is the latest submission verdict.

  • [2025-01-24 16:48:07]
  • Judged
  • Verdict: WA
  • Time: 36ms
  • Memory: 431400kb
  • [2025-01-24 16:48:05]
  • Submitted

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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 36ms
memory: 431140kb

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: 36ms
memory: 430476kb

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: -100
Wrong Answer
time: 28ms
memory: 431400kb

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 1000000000000000000 701911826 

result:

wrong answer 3rd numbers differ - expected: '80811085745', found: '1000000000000000000'