QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#471563#8572. Passing Gameucup-team2307#AC ✓1061ms106036kbC++204.4kb2024-07-10 22:12:302024-07-10 22:12:31

Judging History

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

  • [2024-07-10 22:12:31]
  • 评测
  • 测评结果:AC
  • 用时:1061ms
  • 内存:106036kb
  • [2024-07-10 22:12:30]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define pb push_back

typedef long long ll;
#define int ll

using namespace std;

const int N = 3e5+100;
const int K = 66;

vector<pair<int, ll> > g[2*N];
vector<pair<int, ll> > g1[2*N][2];

pair<int, int> x[N];
int x0[N];
int n, k;

int index(int x, int r)
{
    return x*2+r;
}

void add_edge(int x1, int r1, int x2, int r2)
{
//    g[index(x1, r1)].pb({index(x2, r2), 2ll * x[x1].se * abs(x[x1].fi - x[x2].fi) + (r1 != r2)});
    g1[x1][ (x[x1].fi < x[x2].fi) ? 0 : 1].pb({x2, x[x1].se * abs(x[x1].fi - x[x2].fi)});
}

void add_edge(int x1, int x2)
{
    int r2 = (x[x1].fi > x[x2].fi);
    for (int r1=0; r1<2; r1++)
        add_edge(x1, r1, x2, r2);
}

ll DIST[2*N];

void jump(int tp)
{
//    for (int i=0; i<n; i++)
//        cout<<DIST[i]<<" ";
//    cout<<"\n";
    if (tp == 0)
    {
        for (int i=0; i<n; i++)
            for (auto [j, l] : g1[i][tp])
                DIST[j] = min(DIST[j], DIST[i] + l);
    }
    else
    {
        for (int i=n-1; i>=0; i--)
            for (auto [j, l] : g1[i][tp])
                DIST[j] = min(DIST[j], DIST[i] + l);
    }
//    cout<<" => \n";
//    for (int i=0; i<n; i++)
//        cout<<DIST[i]<<" ";
//    cout<<"\n";
}

int SOLVE(int a, int b, int k)
{
    for (int i=0; i<n; i++)
        DIST[i] = 1e18;
    DIST[a] = 0;
    for (int i=0; i<k; i++)
        jump(i%2);
    int ans = DIST[b];
    for (int i=0; i<n; i++)
        DIST[i] = 1e18;
    DIST[a] = 0;
    for (int i=0; i<k; i++)
        jump(1-i%2);
    return min<int>(ans, DIST[b]);
}

ll dijkstra(int a, int b, int k)
{
    static ll cur[2*N],nxt[2*N];
    const ll INF=1e18;
    for(int i=0;i<=a;i++)
        cur[i]=nxt[i]=INF;
    cur[a]=0;
    for(int level=0;level<k;level++) {
        priority_queue<pair<ll, int>> pq;
        for(int i=0;i<=a;i++)
            cur[i]=min(cur[i],nxt[i]),
            pq.emplace(-cur[i], i),
            nxt[i]=INF;
        while (!pq.empty()) {
            auto [d, v] = pq.top();
            pq.pop();
            d = -d;
            if (d != cur[v])
                continue;
            for (auto [to, w]: g[v])
                if(w%2)
                    nxt[to]=min(nxt[to],d+w/2);
                else if (cur[to] > d + w/2)
                    cur[to] = d + w/2,
                    pq.emplace(-cur[to], to);
        }
//        for(int i=0;i<=a;i++)
//            cout<<level<<" "<<i<<" -> "<<cur[i]<<"\n";
    }
    return min(cur[2*b],cur[2*b+1]);
}

int T;
mt19937 rng(time(0));
void solve()
{
//    n = 300000/T;
//    k = 3e5;
    cin>>n>>k;
    k = min(k+1, K);
    for (int i=0; i<=2*n; i++)
        g[i].clear();
    for (int i=0; i<=n; i++)
        g1[i][0].clear(), g1[i][1].clear();
    vector<pair<int, int> > v;
    for (int i=0; i<n; i++)
        cin>>x[i].fi;
    for (int i=0; i<n; i++)
        cin>>x[i].se;
//    for (int i=0; i<n; i++)
//    {
//        x[i].fi = i;
//        x[i].se = rng()%int(1e9)+1;
//    }

    for (int i=0; i<n; i++)
        x0[i]=x[i].fi;
    sort(x, x+n);
    int a=-1, b=-1;
    for (int i=0; i<n; i++)
        if (x[i].fi == x0[0])
            a = i;
        else if (x[i].fi == x0[n-1])
            b = i;
    for (int i=0; i<n; i++)
        v.pb({x[i].se, i});

    sort(v.begin(), v.end());
    set<pair<int, int> > xs;
    for (auto [s, i] : v)
    {
//        if (i!=a)
        {
            auto it = xs.lower_bound({x[i].fi, 0});
            if (it != xs.end())
                if (it->se != b)
                {
//                    cout<<"F "<<i<<" "<<it->se<<"\n";
                    add_edge(i,  it->se);
                }
            if (it != xs.begin())
                if (prev(it)->se != b)
                {
//                    cout<<"B "<<i<<" "<<prev(it)->se<<"\n";
                    add_edge(i, prev(it)->se);
                }
        }
        xs.insert({x[i].fi, i});
    }
//    for (int i=0; i<n; i++)
//        if (i != a) add_edge(a, i);
    for (int i=0; i<n; i++)
        if (i != b) add_edge(i, b);
//    g[2*n].pb({index(a, 0), 0});
//    g[2*n].pb({index(a, 1), 0});

    cout<<SOLVE(a, b, k)<<"\n";
//    cout<<dijkstra(2*n, b, k)<<"\n";
}

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));

    cin>>T;
    for (int _=0; _<T; _++)
        solve();

}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 7768kb

input:

2
4 2
3 2 1 6
3 1 1 3
2 0
1 2
1 2

output:

7
1

result:

ok 2 number(s): "7 1"

Test #2:

score: 0
Accepted
time: 1061ms
memory: 106036kb

input:

1
300000 204334
809492393 304618667 173130445 377106790 364888630 949045125 622060683 557772818 216607577 848817467 862855568 507840723 120816645 639713488 741781998 682531787 685261161 601686403 355792373 162819930 710057718 234560726 998604853 678957602 485413982 855985802 109303681 979706626 4822...

output:

31313390701066

result:

ok 1 number(s): "31313390701066"

Test #3:

score: 0
Accepted
time: 562ms
memory: 44228kb

input:

3
100000 65460
217141764 710454586 789075415 24849107 685675008 839804815 638763480 327755609 43827967 390187172 301370841 622696676 598237196 232099091 211987715 416876077 572665966 73382836 520033984 808399404 752832432 341795744 434460344 535426588 136624537 997406768 297342165 558882675 26863877...

output:

70635841128944
47230361360721
59110547802683

result:

ok 3 number(s): "70635841128944 47230361360721 59110547802683"

Test #4:

score: 0
Accepted
time: 986ms
memory: 105464kb

input:

1
300000 101975
207258305 525434317 528778163 645316642 562113679 143398489 9114413 669854123 106324041 841914487 21419012 308025536 689200225 263298218 39377353 860366080 24610184 43404209 529054797 902238799 422737070 484129934 967667618 953541323 338625285 115085955 363490839 998893783 877857789 ...

output:

40311829457542

result:

ok 1 number(s): "40311829457542"

Test #5:

score: 0
Accepted
time: 3ms
memory: 7796kb

input:

18
17 0
500000000 499999997 500000010 499999965 500000118 499999609 500001291 499995739 500014064 499953589 500153157 499494579 501667889 494495965 518163316 440061055 697798520
197798520 59938945 18163316 5504035 1667889 505421 153157 46411 14064 4261 1291 391 118 35 10 3 1
17 1
500000000 499999997...

output:

15506866876
14901483521
14901483521
14596599454
14596599454
14327495899
14327495899
14069829018
14069829018
13814295534
13814295534
13559037370
13559037370
13303815695
13303815695
13061698660
13061698660
13061698660

result:

ok 18 numbers

Test #6:

score: 0
Accepted
time: 965ms
memory: 103940kb

input:

1
300000 108311
562733523 631963246 813519221 169288073 117366252 527887631 958029417 190367625 583075950 97173270 896048212 131308006 37400006 90012864 923307076 279518077 383193505 134227338 223315078 230865002 126513901 226753074 767298214 632275980 328061909 158106292 275417458 205909246 6796599...

output:

22530954433990

result:

ok 1 number(s): "22530954433990"

Test #7:

score: 0
Accepted
time: 163ms
memory: 7800kb

input:

6000
50 9
134170081 235040736 405102476 567954026 351391400 872095141 116079799 935104039 779623552 857355273 642352783 394389351 10847154 403727586 104520573 266338849 213345479 719882827 836874283 973992590 698097800 821674140 408510849 363267881 10753022 371526254 123631785 246871721 505280626 29...

output:

30096348366675791
46069208396039888
43208901362730729
70517421587512986
11224815513692355
71475323642044669
1805862419831112
135052117577413332
26429620406592108
30539122715657614
7984965510320702
45549957862209120
42689412604990122
11269234889588471
80025912449049377
62081070915081025
4881768842034...

result:

ok 6000 numbers

Test #8:

score: 0
Accepted
time: 565ms
memory: 42016kb

input:

3
100000 29147
500000000 597145750 552984982 372885743 640231243 733918327 800174654 803027973 174812114 914218248 958491647 953654602 654712814 719285245 331288273 879947652 879757804 768921697 826703535 228697076 180453233 681236422 977876007 50434656 229471634 830980737 12014073 250160020 4486414...

output:

13061698660
13061698660
13061698660

result:

ok 3 number(s): "13061698660 13061698660 13061698660"

Test #9:

score: 0
Accepted
time: 99ms
memory: 7732kb

input:

30000
10 10
802030518 640274071 71550121 799843967 796619138 223219513 312183499 673542337 879397647 631413076
598196518 983359971 96204862 446173607 402690754 668171337 905549873 566661387 434495917 150918417
10 10
224422012 525305826 404334728 998133227 59632864 62611196 296576565 812713672 614679...

output:

69273774453668369
15440670445128286
192723941525693508
75675642974614068
36131012282542320
85171320762046356
27782956555892610
12331410768391077
241652836554719225
121097012285620735
382589380847694270
12204787868953675
98646491955517787
1209132821823955
27110849050473250
137126106329510200
13480620...

result:

ok 30000 numbers

Test #10:

score: 0
Accepted
time: 211ms
memory: 7876kb

input:

1000
300 17
500000000 547680479 781514046 768736762 934177391 660698970 809576345 537077801 400529937 552145378 49225712 834259550 51888621 391560261 738261701 593590260 941618125 274782375 90195859 126157143 355402134 726699436 444190441 440061055 788686954 990218202 257424993 544553505 853414019 9...

output:

13061698660
13061698660
14069829018
14596599454
13061698660
13061698660
14901483521
13061698660
13061698660
13061698660
13061698660
14069829018
13061698660
13061698660
13061698660
13061698660
15506866876
13061698660
13061698660
13814295534
14596599454
13303815695
14901483521
13061698660
13061698660
...

result:

ok 1000 numbers

Test #11:

score: 0
Accepted
time: 317ms
memory: 8124kb

input:

300
1000 542
657869894 302751325 821704902 911667041 556158495 811890152 474105790 363136546 201743030 341427747 10486332 162407523 544009771 915779647 988646785 755731062 331696864 259116972 66705678 553069290 70812533 281275932 273721508 355438226 887037644 725648767 659562563 410301053 783671813 ...

output:

1092574991858418
761786727410942
3837016071362107
4542837085930755
1215985900981157
2188923692733333
4724138820804551
3324015510566471
2123768018381713
2664228765301178
4591721575190483
4991118275259893
7874488069466712
4072341567396137
998993874951943
1397368267257796
2024987292950682
1402861394900...

result:

ok 300 numbers

Test #12:

score: 0
Accepted
time: 271ms
memory: 8084kb

input:

1200
250 98
682351638 2457996 288493156 128440451 375428233 891376236 17918276 143663203 560377768 514150164 700942749 574491970 506401375 254841922 745178877 456835709 62543579 179900914 263948337 646651057 32290953 664841057 559233349 634390971 335337494 369694988 197557638 400610487 227953519 629...

output:

23329812933206870
11277348901796038
12460508031437621
4895620700942690
738669449014040
6869250331331536
14681765643935973
5909108244560941
8421544152021567
13989985278118862
3639891463249160
8674001937254098
8255466194121077
1446947895929841
26707292420650755
17639851523757433
6242204086605175
11329...

result:

ok 1200 numbers

Test #13:

score: 0
Accepted
time: 238ms
memory: 8092kb

input:

300
1000 963
500000000 632915000 478910239 468205019 9987953 883339014 647780152 655126145 886106275 184298894 457965768 661511802 205781642 799243104 880841413 517330574 936864266 27921304 287252316 172487672 258054117 961443776 549407378 348055591 499999965 199391494 642934159 204368698 896164152 ...

output:

13061698660
14069829018
13061698660
14901483521
13061698660
13061698660
13303815695
13061698660
13061698660
13061698660
13061698660
13061698660
13061698660
13061698660
13061698660
13061698660
14596599454
13303815695
13061698660
13061698660
14327495899
13061698660
13061698660
13061698660
14596599454
...

result:

ok 300 numbers

Test #14:

score: 0
Accepted
time: 454ms
memory: 15816kb

input:

12
25000 4157
299336960 546808795 459692983 341866176 220959265 984680630 584146182 306737776 774447523 349601875 352671784 513138426 836883003 440483252 976958324 593873668 864213983 324458784 796561533 966591603 729088963 586303004 970759705 749529197 686341724 836687212 849079388 102598485 973778...

output:

284195910875626
274870514836051
404258435833079
135833080069129
176065859803454
133679933287499
369257036588126
220782753354879
212328718914556
450834372738126
197127000261514
105626494759545

result:

ok 12 numbers

Test #15:

score: 0
Accepted
time: 366ms
memory: 9740kb

input:

60
5000 1699
756662829 164615679 176745065 930641599 992714840 890646201 828015603 245741385 937343509 804090603 265947390 767999938 20283091 135162900 724431387 59623628 922934339 613174775 91621915 821163847 576884311 744574611 129855504 546339925 888037696 291592234 88692553 740078934 604296047 9...

output:

1388747109016135
796585908548315
1292842362023432
1019969421104496
699679635678647
284970927437972
1976026267696309
1262333683751669
476479031653348
836032814722947
401067691094076
224470179417906
812877199901981
1577911241094002
409665098471103
1335490113314524
688097777617304
597433042398934
10793...

result:

ok 60 numbers

Test #16:

score: 0
Accepted
time: 986ms
memory: 103800kb

input:

1
300000 79048
500000000 72303450 725956278 499829564 769524290 887183343 104695544 500558244 976713897 178100565 346465068 438866193 47040800 998435764 833218621 833033990 284438519 526206362 989981879 970886760 73797241 676341166 573983229 922343350 509988168 439937579 19085346 575750193 311019854...

output:

13061698660

result:

ok 1 number(s): "13061698660"

Test #17:

score: 0
Accepted
time: 427ms
memory: 104644kb

input:

1
300000 2
500000000 986689313 526988696 742766790 886595836 687905439 41623509 489823328 956671241 445393626 311276990 738982299 809517071 426531977 503452845 773412198 578933597 469709362 697592748 973076959 311235585 161052090 760002550 831554209 688007794 457851620 198717375 753343317 49564457 7...

output:

14901483521

result:

ok 1 number(s): "14901483521"

Test #18:

score: 0
Accepted
time: 982ms
memory: 105672kb

input:

1
300000 17895
500000000 961738248 799804319 862125039 29383909 88522421 206249306 205254278 326598156 712641955 461957852 280478849 699192392 10039427 253283343 742404721 629158607 876458637 210361887 315760729 524741657 237413472 924215264 607715874 385443844 457796693 882601269 454562263 28028030...

output:

13061698660

result:

ok 1 number(s): "13061698660"

Test #19:

score: 0
Accepted
time: 517ms
memory: 104832kb

input:

1
300000 10
500000000 616829345 738394523 653934048 46980218 822233301 704878277 425893750 793326584 314412433 119413358 893207432 392314189 886191961 773036754 716141312 651831880 378682454 142441780 861010208 140408545 821733429 756055372 762602717 66579867 260154480 709785435 723760183 667143439 ...

output:

13814295534

result:

ok 1 number(s): "13814295534"

Test #20:

score: 0
Accepted
time: 996ms
memory: 105180kb

input:

1
300000 162598
500000000 178424286 321857556 392783865 938614528 700858738 880246121 30385725 540666710 934016590 540732817 312471486 672034801 725649082 609741540 237602792 838632938 467171051 355767291 94570869 36304257 751174881 377429057 222564767 455767609 799398247 607276965 841670683 8203258...

output:

13061698660

result:

ok 1 number(s): "13061698660"

Test #21:

score: 0
Accepted
time: 462ms
memory: 104968kb

input:

1
300000 3
500000000 10640626 26244594 885618738 664684363 927460604 21605214 141448118 254610947 722072932 749730723 381408442 617124215 660295243 265990282 949209956 870823956 890190598 345267809 604438056 233614156 179167636 646003555 57529751 371559531 669193525 518674390 823682615 687712382 808...

output:

14596599454

result:

ok 1 number(s): "14596599454"

Test #22:

score: 0
Accepted
time: 267ms
memory: 9428kb

input:

60
5000 784
500000000 181933656 247700033 127137924 488746354 696015683 240485749 283778545 824036313 914909253 606068043 424412515 445204997 474299591 99548917 252196353 792967047 957143976 973486259 68189163 296428949 521704790 687088714 585678966 710330302 393693418 67215218 238595352 58967541 40...

output:

13061698660
13559037370
14901483521
13061698660
13814295534
15506866876
13559037370
13559037370
13559037370
13061698660
13061698660
13061698660
13061698660
13061698660
14596599454
13061698660
14596599454
13061698660
13061698660
13061698660
13061698660
13061698660
13061698660
14327495899
13061698660
...

result:

ok 60 numbers

Test #23:

score: 0
Accepted
time: 1000ms
memory: 102016kb

input:

1
300000 112925
500000000 187720638 774041899 719124389 144433388 722401729 514163966 358695852 613043018 211475688 785946211 346266738 885638445 520855439 83336659 482573610 909962503 70509919 170194067 87226103 644860310 982300924 929716289 601580680 989819441 432098173 936284417 882766775 8075610...

output:

12940360625

result:

ok 1 number(s): "12940360625"

Test #24:

score: 0
Accepted
time: 370ms
memory: 15656kb

input:

12
25000 20692
500000000 132857017 385523215 701066726 666661361 179540297 242239729 2197758 416327322 907621491 282200769 397832072 157059359 196291390 257407253 333935727 710782843 308141598 611903784 773877005 500001291 235246551 566392891 131837214 229389993 687718767 452527218 435117876 7896945...

output:

13061698660
13061698660
13061698660
13061698660
13061698660
13061698660
13061698660
13061698660
13559037370
13559037370
14596599454
13061698660

result:

ok 12 numbers

Test #25:

score: 0
Accepted
time: 457ms
memory: 105368kb

input:

1
300000 8
500000000 326439190 791622036 104665080 329000514 468690410 637698668 136597156 109652773 316454352 546873850 474979574 901965339 380355588 124495260 592541006 835608163 892994257 184061276 74037627 398052013 304885056 370370537 529146672 419570552 996293468 482282900 931347113 436336231 ...

output:

14069829018

result:

ok 1 number(s): "14069829018"

Test #26:

score: 0
Accepted
time: 381ms
memory: 105744kb

input:

1
300000 0
500000000 238939486 304374455 423669374 29850387 438300513 111174976 329099666 874056474 588817943 421125375 506161650 223516602 213027370 93945112 455298822 417963043 769012969 799258806 709005309 79578465 815399909 939019510 616037013 308568881 537790300 119192633 871465935 352029430 40...

output:

15506866876

result:

ok 1 number(s): "15506866876"

Test #27:

score: 0
Accepted
time: 469ms
memory: 104204kb

input:

1
300000 8
500000000 961512480 541527048 81341659 448136384 344171271 159634569 75744344 944062332 74181957 328827482 239656051 229157158 759548731 123296963 504290696 338403912 35032736 85336690 365820634 950731848 862862483 408781872 200982012 334906331 824315049 261157081 412945433 364182738 9395...

output:

14069829018

result:

ok 1 number(s): "14069829018"

Test #28:

score: 0
Accepted
time: 979ms
memory: 104516kb

input:

1
300000 127477
500000000 924603745 709414871 289466706 323340589 241488399 890485618 975344668 720001574 536087490 437923628 22861967 266855378 971340750 162468536 150815332 951025602 690120654 555801138 803553804 49036941 959174045 303264032 297460064 413061866 964223878 105359201 116733261 478018...

output:

13061698660

result:

ok 1 number(s): "13061698660"

Test #29:

score: 0
Accepted
time: 987ms
memory: 104528kb

input:

1
300000 7711
500000000 748435576 478482708 132592520 144810784 179561097 534551204 216378223 550689198 602762045 672262297 963816921 641701358 643658260 837556308 197842642 513366325 778171216 318005265 66736234 581114229 674030621 956781094 438434388 985504937 875113774 24034696 920968426 27468111...

output:

13061698660

result:

ok 1 number(s): "13061698660"

Test #30:

score: 0
Accepted
time: 998ms
memory: 104328kb

input:

1
300000 196959
500000000 803909108 287035995 504828814 502231638 398508717 129657414 275047043 10674111 998776022 470168059 574012819 135318042 637203040 592738673 376455038 104938668 524920759 198815750 183979799 493025480 108537792 527769385 907720916 134661241 27000849 49127777 547472548 9312769...

output:

13061698660

result:

ok 1 number(s): "13061698660"

Test #31:

score: 0
Accepted
time: 975ms
memory: 102096kb

input:

1
300000 60984
500000000 422362911 114135400 592480923 746334952 456767366 271308069 223807842 893538164 178332416 669320868 448048330 360818676 245670700 413899870 612763740 619621624 41470340 263166441 43785120 748504916 298549369 848364437 207051521 889775639 938698993 347177517 576889437 7384056...

output:

13061698660

result:

ok 1 number(s): "13061698660"

Test #32:

score: 0
Accepted
time: 431ms
memory: 105756kb

input:

1
300000 4
500000000 660166004 713903083 813679046 625552963 93302943 675044519 897009216 806482499 523988918 77645889 407549130 211912486 653340703 796334042 366635826 519181228 865605695 363006757 714920677 892233195 308118610 214573620 94767292 739715338 600232897 783047358 341011849 777450639 76...

output:

14596599454

result:

ok 1 number(s): "14596599454"

Test #33:

score: 0
Accepted
time: 523ms
memory: 105344kb

input:

1
300000 13
500000000 83707701 186780969 326025057 502607635 598749883 766935984 146637842 473143286 696680611 341825420 927633891 263175759 689933039 259521054 793063933 894532511 574312702 536759906 217418205 172344593 323427755 392477347 297320666 37532029 352872806 463150694 190001405 887909498 ...

output:

13303815695

result:

ok 1 number(s): "13303815695"

Extra Test:

score: 0
Extra Test Passed