QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#768459#2990. IIIDXpropane20 190ms33440kbC++202.4kb2024-11-21 10:53:232024-11-21 10:53:24

Judging History

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

  • [2024-11-21 10:53:24]
  • 评测
  • 测评结果:20
  • 用时:190ms
  • 内存:33440kb
  • [2024-11-21 10:53:23]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
using LL = long long;

const int maxn = 5e5 + 5;
int tr[maxn];

int lowbit(int x){
    return x & -x;
}

void modify(int x, int v){
    while(x < maxn){
        tr[x] += v;
        x += lowbit(x);
    }
}

int query(int x){
    int ans = 0;
    while(x){
        ans += tr[x];
        x -= lowbit(x);
    }
    return ans;
}

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int n; string str;
    cin >> n >> str;
    pair<LL, LL> k;
    auto pos = str.find('.');
    if (pos == string::npos){
        k = {stoll(str), 1};
    }
    else{
        int cnt = str.size() - pos - 1;
        str.erase(str.begin() + pos);
        k.second = 1;
        while(cnt--) k.second *= 10;
        k.first = stoll(str);
    }
    vector<int> p(n + 1);
    vector<vector<int> > g(n + 1);
    for(int i = 1; i <= n; i++){
        p[i] = __int128_t(i) * k.second / k.first;
        g[p[i]].push_back(i);
    }
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    a.push_back(0);
    sort(a.begin(), a.end());
    auto b = a;
    b.erase(unique(b.begin(), b.end()), b.end());
    const int m = b.size();

    vector<int> sz(n + 1);

    auto dfs = [&](auto &&dfs, int u) -> void {
        sz[u] = 1;
        for(auto j : g[u]){
            dfs(dfs, j);
            sz[u] += sz[j];
        }
    };

    dfs(dfs, 0);

    for(auto x : a){
        int id = lower_bound(b.begin(), b.end(), x) - b.begin() + 1;
        modify(id, 1);
    }

    modify(1, -(n + 1));
    vector<int> ans(n + 1);
    ans[0] = 1;

    for(int i = 1; i <= n; i++){
        modify(ans[p[i]], sz[i]);

        // 找到最大的x满足s[x, m] >= sz[i]
        // s[m] - s[x - 1] >= sz[i]
        // s[x - 1] <= s[m] - sz[i]

        int target = query(m) - sz[i];

        int x = 0, sum = 0;
        for(int j = 19; j >= 0; j--){
            if (x + (1 << j) <= m and sum + tr[x + (1 << j)] <= target){
                sum += tr[x + (1 << j)];
                x += 1 << j;
            }
        }
        x += 1;
        modify(x, -sz[i]);
        ans[i] = x;
        cout << b[x - 1] << " \n"[i == n];
    }

}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3604kb

input:

4 2.0
9 5 3 4

output:

3 5 9 4

result:

wrong answer 1st lines differ - expected: '3 5 4 9', found: '3 5 9 4'

Test #2:

score: 5
Accepted
time: 0ms
memory: 3668kb

input:

8 3.000
31 15 2 54 97 65 46 61

output:

54 2 97 65 61 46 31 15

result:

ok single line: '54 2 97 65 61 46 31 15'

Test #3:

score: 5
Accepted
time: 0ms
memory: 3664kb

input:

5 1.100
26 62 58 94 67

output:

26 58 62 67 94

result:

ok single line: '26 58 62 67 94'

Test #4:

score: 5
Accepted
time: 0ms
memory: 3604kb

input:

9 9.000
15 88 55 99 29 36 7 71 45

output:

88 71 55 45 36 29 15 7 99

result:

ok single line: '88 71 55 45 36 29 15 7 99'

Test #5:

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

input:

10 2.333
38 38 85 14 35 69 58 37 89 100

output:

38 14 69 89 37 35 38 58 85 100

result:

wrong answer 1st lines differ - expected: '38 14 69 38 37 35 100 89 85 58', found: '38 14 69 89 37 35 38 58 85 100'

Test #6:

score: 5
Accepted
time: 0ms
memory: 3600kb

input:

1 3.333
86

output:

86

result:

ok single line: '86'

Test #7:

score: 0
Wrong Answer
time: 1ms
memory: 3744kb

input:

1986 2.000
281295007 369543000 811574394 77532113 282225790 49445902 624452407 655720521 807581699 787169513 916890294 893096710 811681693 619388658 720357095 599550164 469242195 692961953 904464661 886425240 407991228 2456315 260548941 617078389 361663778 691708754 559248679 162773819 18033965 3680...

output:

639939 441073320 470031473 683590 198574900 708316395 746015853 86774604 925547 335377379 198918664 470640860 610376219 862892302 894833318 135966980 87042283 45063907 1274919 403866021 335610641 268628143 199260424 545556912 470644210 675384677 610467259 746151152 825018045 932188826 963492698 1653...

result:

wrong answer 1st lines differ - expected: '639939 441073320 683590 708316...1790 26361360 25690700 25490546', found: '639939 441073320 470031473 683...8 996060556 996696577 999334500'

Test #8:

score: 0
Wrong Answer
time: 1ms
memory: 4040kb

input:

1986 2.000
410358852 771659955 609020567 78010901 891539089 58470167 996405684 709265737 118335385 72626916 465005856 224956998 977265488 196399968 657949596 345289423 798156987 903811388 234327100 847271602 47598967 528935137 80448574 155437182 342444252 114510395 598707279 351220692 466768959 9279...

output:

3993744 445094234 3993744 732258290 445094234 139648398 3993744 855547874 732258290 600918715 445094234 271839764 139648398 64416248 3993744 934871707 855547874 800778028 732258290 686238415 605633492 523492343 445094234 343453671 271839764 208061459 139648398 103524427 64416248 19169021 41269562 97...

result:

wrong answer 1st lines differ - expected: '3993744 445094234 3993744 7322...4338 19169021 19169021 18080328', found: '3993744 445094234 3993744 7322...1 397323871 397323871 410358852'

Test #9:

score: 0
Wrong Answer
time: 1ms
memory: 3716kb

input:

1989 3.000
990864107 642150955 155463337 92945547 566987168 613942275 571349910 125615127 90015994 520882482 482177513 945162640 850442966 422843075 685269653 99650208 499754581 36272980 277930567 17252979 600991186 714594241 2081442 899198830 839621423 764176107 561473786 130748352 380445610 866909...

output:

421438549 515353366 299758 136429456 339836957 817849682 616437715 726105824 461920870 44511939 883992 90790519 192727229 136598763 393568208 261628781 340413547 935769689 877779162 817878376 659272608 515758667 586633074 772429344 746154266 726885015 704509881 480545115 462329712 441181842 35843842...

result:

wrong answer 1st lines differ - expected: '421438549 299758 817849682 616...1410 38876691 38292726 36376810', found: '421438549 515353366 299758 136...5 908199271 909423095 925526546'

Test #10:

score: 0
Wrong Answer
time: 1ms
memory: 3780kb

input:

1989 3.000
25662683 386690509 471933555 615075359 22546939 34818749 626732057 792200516 471006685 653186188 901875472 244615213 390645993 633933259 38810248 983486968 675189604 675189604 784732242 38810248 792200516 567616754 626732057 684398656 271837278 238805988 872887631 431850121 903966106 3331...

output:

390645993 2590306 800327124 596587717 390645993 202887162 57952168 121678750 903966106 875018503 800327124 702205293 639000551 596587717 503601877 458609710 390645993 324606253 258692790 202887162 2590306 35708626 82782624 143116805 974719269 121678750 895877371 956943859 903966106 845067645 8857800...

result:

wrong answer 1st lines differ - expected: '390645993 2590306 800327124 59...7816 28927816 28927816 34818749', found: '390645993 2590306 800327124 59...2 133360102 133360102 561635318'

Test #11:

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

input:

1999 6.523
337250772 530507854 641691531 138621890 7527603 551560640 403442319 595955055 615491869 132117477 19858651 909420457 802364987 296972240 477926758 443054437 936505287 125010807 595483861 881929447 37359990 481564722 506388073 261568083 788166345 46836286 713348293 780896918 132914700 5070...

output:

802065619 630248249 444093505 269896370 116677159 2478080 952060523 973188111 909420457 890694885 858684963 832307168 802192185 773609401 747191883 720179497 687859238 661804343 630310546 606945203 584354638 548218023 524864103 500882116 474418984 444368672 448115565 385437667 358803886 328551819 30...

result:

wrong answer 1st lines differ - expected: '802065619 630248249 444093505 ...3 976678613 976027763 975711792', found: '802065619 630248249 444093505 ...5 959334126 958955838 958845615'

Test #12:

score: 0
Wrong Answer
time: 1ms
memory: 4016kb

input:

1999 2.123
780045250 153239311 309157213 29562070 294834889 780045250 337602783 357106666 179787248 294834889 550326722 331413909 880980880 875130647 366842538 880980880 21576086 467718250 554430349 778914550 525347896 338102165 467718250 830781157 554430349 557349626 249198018 821179692 631762899 5...

output:

249198018 566483405 21576086 366842538 812405469 566483405 188552013 21576086 503406414 366842538 845898193 812405469 730030823 566483405 309157213 188552013 153239311 61502514 21576086 527443540 503406414 434667483 366842538 875130647 845898193 821179692 830781157 778914550 730030823 582416109 5664...

result:

wrong answer 1st lines differ - expected: '249198018 21576086 503406414 2...5 338102165 366842538 366842538', found: '249198018 566483405 21576086 3...3 513918003 550326722 550326722'

Test #13:

score: 0
Wrong Answer
time: 134ms
memory: 32408kb

input:

498765 2.000
58107723 618698520 100249493 373660543 97564333 117796271 51411872 464112788 142651213 219200625 547359830 403878568 146585233 30781754 740842250 708454458 477069340 848102107 798653859 100249493 645810221 265305480 848501819 669774419 62982467 335502222 697325602 112743145 965055098 62...

output:

4209 436759152 4209 725066942 436759152 156044902 4209 861859784 725066942 581201642 436759152 294246483 156044902 58888672 348341589 929100088 861859784 797240948 725066942 648761449 581201642 506053647 436759152 95309872 280365960 208454465 142574691 4209 47650386 529951979 348341589 965315492 929...

result:

wrong answer 1st lines differ - expected: '4209 436759152 4209 725066942 ...9593 36359593 36359593 36359593', found: '4209 436759152 4209 725066942 ...3 790117243 795167442 795167442'

Test #14:

score: 0
Wrong Answer
time: 134ms
memory: 30720kb

input:

500000 3.000
9042246 202940352 43272064 800855306 743910648 807487381 43272064 615067766 857382024 76086932 972574673 647380659 577870378 567053734 76327550 310307945 444518674 429782580 613279803 342467758 150028977 577870378 78604228 844435178 709135656 207337247 500274314 432450797 733473710 5004...

output:

438962117 660193 804221164 613279803 438962117 229626704 76086932 660193 939882380 857382024 804221164 749294015 674843409 613279803 566227489 513544076 438962117 352355987 295481193 229626704 164138626 118270525 76086932 41681685 773366560 660193 978581914 959074973 939882380 907752835 889178830 85...

result:

wrong answer 1st lines differ - expected: '438962117 660193 804221164 613...7931 29237931 29237931 29237931', found: '438962117 660193 804221164 613...0 994494530 994494530 994494530'

Test #15:

score: 0
Wrong Answer
time: 190ms
memory: 31800kb

input:

500000 6.666
687629251 725725373 377584674 789067458 745891542 13609480 340943012 588686633 292431935 333790521 497513034 430914272 243282836 816494436 165675153 133056947 445790460 832770546 914901024 185219181 415577102 602213968 284480221 10427020 242834056 770096576 368977456 511413070 28294552 ...

output:

765536274 799478152 336934796 116943052 23559449 530004219 565297049 599843964 629655428 664741315 700306822 730493382 764715952 970137793 935203176 900202979 870316425 834755388 799478514 500206494 466255746 430891028 401187098 366466602 301819148 336129789 266877291 231703949 93233345 197186761 16...

result:

wrong answer 1st lines differ - expected: '765536274 565297049 336934796 ...9492 30259262 30258887 30258476', found: '765536274 799478152 336934796 ...0 829881336 829881040 829874565'

Test #16:

score: 0
Wrong Answer
time: 186ms
memory: 31632kb

input:

500000 3.526
251575195 880559884 302464608 669160226 68868182 881391252 762642602 250418843 332747975 962841429 60560019 180497268 410436706 875122869 51000516 514949651 444300442 13863163 411847306 137596125 350377403 151555710 7011427 383942355 74972874 938293131 563525997 99346734 942546998 54704...

output:

409457234 799423085 515880148 1313 149755314 453849994 372042588 943093608 863090465 799423367 719356141 654944825 573315586 515881268 291712266 228339619 2331 53080294 95518388 169768135 981974007 435538819 481733443 458343945 418032109 394995544 353789289 371942946 965908778 924929496 948185831 90...

result:

wrong answer 1st lines differ - expected: '409457234 208351230 1313 77666...5 579672337 579667670 579660889', found: '409457234 799423085 515880148 ...1 943636209 943636610 943637345'

Test #17:

score: 0
Wrong Answer
time: 131ms
memory: 30236kb

input:

500000 4.500
77285882 347720767 911705537 776587768 774249073 490272904 883923821 940241 157476532 352488958 110028472 342016631 157476532 771373777 524881498 217596011 170708299 341952542 671978059 39229697 750607498 960786354 429687148 643111371 852737293 852737293 187363480 170708299 986018262 93...

output:

548027607 132054617 483820240 376896360 904350273 775588378 656310970 548027607 407253045 940241 62247023 156582970 963730601 224892450 509884143 487061028 474625958 250980472 282956091 303363882 342016631 360820976 939619563 856378214 927199028 885781933 835685399 623146735 798135552 776600921 7547...

result:

wrong answer 1st lines differ - expected: '548027607 132054617 66848454 9...1 143207371 143207371 145023302', found: '548027607 132054617 483820240 ...6 983705726 983705726 987349422'

Test #18:

score: 0
Wrong Answer
time: 130ms
memory: 33440kb

input:

500000 1.865
886232424 31938153 95550197 232682690 537426339 175267421 816697451 848319174 61371162 930404799 23279758 352055652 870933174 863413833 61116212 559312628 937512167 944390122 162824144 379141335 381507405 940890734 367214858 944761522 508213584 152082099 619777933 79637471 535898589 501...

output:

1034843 205156641 727029701 1034843 352055652 769938700 727029701 164331439 1034843 500533327 529559842 904432253 769938700 727029701 263568690 164331439 73381014 1034843 352055652 424321797 590171508 677942645 967453172 904432253 838595837 769938700 727029701 293000045 263568690 205156641 164331439...

result:

wrong answer 1st lines differ - expected: '1034843 205156641 1034843 5486...4 207113694 207113694 207113694', found: '1034843 205156641 727029701 10...9 685250589 685250589 685250589'

Test #19:

score: 0
Wrong Answer
time: 134ms
memory: 32000kb

input:

500000 2.560
862379585 689468510 971090515 539709893 257730100 605063548 554280955 656731612 654467610 291195472 165627350 850981485 933583024 98671776 799427557 305899863 814781661 199669971 807770925 909918748 244558259 113052839 882579521 283970656 93897189 349431777 222009441 589011084 942407018...

output:

168588790 775405951 424427651 552051672 138613 898602271 775405951 202001798 697928879 344138374 596909357 470537132 133124358 51492986 138613 941043905 898602271 850981485 799427557 775405951 289741127 246033949 202001798 746382120 697928879 416126741 383656443 344138374 637362147 596909357 5667731...

result:

wrong answer 1st lines differ - expected: '168588790 138613 644365687 426...0 154587020 154587020 154587020', found: '168588790 775405951 424427651 ...5 992062905 992062905 992062905'

Test #20:

score: 0
Wrong Answer
time: 169ms
memory: 31152kb

input:

500000 2.690
550310400 164214680 463562328 688869176 87744368 782564579 923140216 324740484 239974566 511094619 827941383 145764776 158271562 820642676 687448291 173834606 322711736 577801491 495952875 800456607 583758834 133066095 519735912 41476830 317069788 423262078 606309582 907207417 312877355...

output:

474628750 5816 877193090 669024977 474628750 324229319 129210801 5816 951725058 877210811 801455282 746467687 669039556 595917457 519740834 906415337 397154894 324229319 417570821 192098431 129219221 96145583 48411697 7650 978792661 951725058 550962717 579455783 888081936 860902522 829048456 8709931...

result:

wrong answer 1st lines differ - expected: '474628750 5816 877193090 66902...2481932 2481932 2481932 2481932', found: '474628750 5816 877193090 66902...4 812631314 812681286 812672335'