QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#786125#6660. 택시 여행int_R0 420ms119220kbC++142.9kb2024-11-26 20:23:272024-11-26 20:23:28

Judging History

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

  • [2024-11-26 20:23:28]
  • 评测
  • 测评结果:0
  • 用时:420ms
  • 内存:119220kb
  • [2024-11-26 20:23:27]
  • 提交

answer

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef pair<int,int> Pair;
typedef pair<ll,ll> Pairl;

const int MAXN=1e5+10;
const ll INF=4e18;

int n,b[MAXN],fa[MAXN],pos[MAXN];
ll a[MAXN];
vector <Pair> v[MAXN];
unordered_map <int,unordered_map<int,int>> dis;

namespace tree
{
    int MIN,R,S,siz[MAXN];
    bool vis[MAXN];
    void dfs(int x,int fa=0)
    {
        int MAX=0;siz[x]=1;
        for(auto now:v[x])
        {
            int y=now.first;
            if(y==fa||vis[y]) continue;
            dfs(y,x),siz[x]+=siz[y];
            MAX=max(MAX,siz[y]);
        }
        MAX=max(MAX,S-siz[x]);
        if(MAX<MIN) MIN=MAX,R=x;
    }
    void calc(int x,int fa=0,ll D=0)
    {
        dis[R][x]=D;
        for(auto now:v[x])
        {
            int y=now.first;
            if(y==fa||vis[y]) continue;
            calc(y,x,D+now.second);
        }
    }
    void work(int x)
    {
        vis[x]=true;calc(x);
        for(auto now:v[x])
        {
            int y=now.first;
            if(vis[y]) continue;
            MIN=MAXN,S=siz[y],dfs(y);
            fa[R]=x,dfs(R),work(R);
        }
    }
    void init()
        {MIN=MAXN,S=n,dfs(1),dfs(R),work(R);}
}

inline bool cmp(int x,int y)
    {return b[x]>b[y];}


struct node
{
    vector <Pairl> f;
    inline ll F(Pairl f,int x)
        {return f.first*x+f.second;}
    inline ll qry(ll x)
    {
        if(f.empty()) return INF;
        int l=0,r=f.size()-1;
        while(l<r)
        {
            int mid=(l+r)>>1;
            ll suma=F(f[mid],x);
            ll sumb=F(f[mid+1],x);
            (suma>sumb)?l=mid+1:r=mid;
        }
        return F(f[l],x);
    }
    inline void upd(ll k,ll B)
    {
        if(!f.empty()&&f.back().second>=B)
            f.pop_back();
        if(f.empty()||f.back().first!=B)
            f.emplace_back(k,B);
    }
}t[MAXN];

inline ll qry(int x)
{
    ll D=INF;
    for(int p=x;p;p=fa[p])
        D=min(D,t[p].qry(dis[p][x]));
    return D;
}

inline void upd(int x,ll D)
{
    for(int p=x;p;p=fa[p])
        t[p].upd(b[x],D+a[x]+1ll*b[x]*dis[p][x]);
}

vecll travel(vecll A,vecint B,vecint U,vecint V,vecint W)
{
    n=A.size();
    for(int i=0;i<n;++i)
        a[i+1]=A[i],b[i+1]=B[i];
    for(int i=0;i<n-1;++i)
        v[U[i]+1].emplace_back(V[i]+1,W[i]),
        v[V[i]+1].emplace_back(U[i]+1,W[i]);
    tree::init();
    for(int i=1;i<=n;++i) pos[i]=i;
    sort(pos+1,pos+n+1,cmp);
    upd(1,0);
    for(int i=1;i<=n;++i)
    {
        if(b[pos[i]]>=b[1]) continue;
        cout<<"P:"<<pos[i]<<'\n';
        upd(pos[i],qry(pos[i]));
    }
    vecll C;
    for(int i=2;i<=n;++i)
        C.push_back(qry(i));
    return C;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 2ms
memory: 9524kb

input:

2
684124582850 713748627948
74361 256955
0 1 661088

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
733283747618
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 3 lines

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 10348kb

input:

3
251115773325 363097865287 358609487841
826785 213106 914768
0 1 851938
2 0 231697

output:

Unauthorized output

result:

wrong answer 1st lines differ - expected: 'secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I', found: 'Unauthorized output'

Subtask #2:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 420ms
memory: 119220kb

input:

100000
746699125678 374834842799 250803643493 620187038832 454433387570 406226564003 897157438699 99473514061 734784419618 503968957100 363935477037 277126009840 52078020050 990757079812 847235285349 950784717285 271017141367 861087225700 996035427219 520682200664 282013988419 415183977876 882007771...

output:

Unauthorized output

result:

wrong answer 1st lines differ - expected: 'secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I', found: 'Unauthorized output'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Wrong Answer

Test #69:

score: 0
Wrong Answer
time: 172ms
memory: 56776kb

input:

100000
15175010 23519365 21177669 27079342 9089 16784452 29693960 23124925 17048604 10179491 12828214 24992902 8483134 2928073 23807522 7332137 17421520 28460746 1607282 13224363 11900728 11794692 11495061 4687109 23460275 7657982 27417256 16978162 7326803 23083826 24942987 16610314 12147303 2828271...

output:

Unauthorized output

result:

wrong answer 1st lines differ - expected: 'secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I', found: 'Unauthorized output'

Subtask #5:

score: 0
Wrong Answer

Test #94:

score: 0
Wrong Answer
time: 227ms
memory: 60504kb

input:

99281
551670361798 568902251563 418071776626 697635341894 641578820039 117221079324 812766431051 425410617978 663769685693 282144284527 799662290178 749088952784 586626406385 122473825417 459510657357 871705247919 443707710712 735612808044 237919555727 829939639783 122127143240 616906466299 24431898...

output:

Unauthorized output

result:

wrong answer 1st lines differ - expected: 'secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I', found: 'Unauthorized output'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%