QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#48946#2990. IIIDXyukino_yukinoshita100 ✓259ms22128kbC++1.9kb2022-09-17 20:03:072022-09-17 20:03:08

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-17 20:03:08]
  • 评测
  • 测评结果:100
  • 用时:259ms
  • 内存:22128kb
  • [2022-09-17 20:03:07]
  • 提交

answer

#include <bits/stdc++.h>
#define mid (l + r >> 1)
#define FOR(i,j,k) for(int i=j; i<=k; ++i)
#define ROF(i,j,k) for(int i=j; i>=k; --i)
inline int read (void) {
  int x = 0, f = 1, ch = getchar();
  while(!isdigit(ch)) { if(ch == '-') f = -f; ch = getchar(); }
  while(isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); }
  return x * f;
}
const int maxn = 500005;
const int maxm = 1048577;
int t[maxm], tg[maxm];
inline void pushdown (int k) {
  if(tg[k]) {
    t[k<<1] += tg[k]; tg[k<<1] += tg[k];
    t[k<<1|1] += tg[k]; tg[k<<1|1] += tg[k];
    tg[k] = 0;
  }
}
void build (int l, int r, int k=1) {
  t[k] = l;
  if(l == r) return ;
  build (l, mid, k<<1);
  build (mid+1, r, k<<1|1);
  t[k] = std::min(t[k<<1], t[k<<1|1]);
}
void modify (int l, int r, int ql, int qr, int c, int k=1) {
  if(ql <= l && r <= qr) {
    t[k] += c; tg[k] += c;
    return ;
  }
  pushdown (k);
  if(ql <= mid) modify (l, mid, ql, qr, c, k<<1);
  if(mid < qr) modify (mid+1, r, ql, qr, c, k<<1|1);
  t[k] = std::min(t[k<<1], t[k<<1|1]);
}
int query (int l, int r, int q, int k=1) {
  if(l == r) return l + (t[k] < q);
  pushdown (k);
  if(t[k<<1|1] >= q) return query (l, mid, q, k<<1);
  else return query (mid+1, r, q, k<<1|1);
}
int a[maxn], cnt[maxn], fa[maxn], sz[maxn], ans[maxn];
bool vis[maxn];
int main (void) {
  int n = read(); double k;
  scanf("%lf", &k);
  FOR(i,1,n) a[i] = read();
  std::sort(a+1, a+n+1, std::greater <int> ());
  build (1, n);
  ROF(i,n,1) {
    cnt[i] = a[i] == a[i+1] ? cnt[i+1] + 1 : 0;
    sz[fa[i] = i / k] += ++ sz[i];
  }
  FOR(i,1,n) {
    if(fa[i] && !vis[fa[i]]) {
      modify (1, n, ans[fa[i]], n, sz[fa[i]] - 1);
      vis[fa[i]] = 1;
    }
    int now = query (1, n, sz[i]);
    now += cnt[now]; ans[i] = now -= cnt[now] ++;
    modify (1, n, now, n, -sz[i]);
  }
  FOR(i,1,n) printf("%d%c", a[ans[i]], i==n?10:32);
  return 0;
}

详细

Test #1:

score: 5
Accepted
time: 2ms
memory: 3864kb

input:

4 2.0
9 5 3 4

output:

3 5 4 9

result:

ok single line: '3 5 4 9'

Test #2:

score: 5
Accepted
time: 3ms
memory: 3860kb

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: 3ms
memory: 3792kb

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: 2ms
memory: 3812kb

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: 5
Accepted
time: 3ms
memory: 3780kb

input:

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

output:

38 14 69 38 37 35 100 89 85 58

result:

ok single line: '38 14 69 38 37 35 100 89 85 58'

Test #6:

score: 5
Accepted
time: 2ms
memory: 3804kb

input:

1 3.333
86

output:

86

result:

ok single line: '86'

Test #7:

score: 5
Accepted
time: 3ms
memory: 3844kb

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 683590 708316395 441672058 166351785 925547 862892302 709316564 583477729 441868524 304276671 167370432 65798344 1274919 932188826 863223754 787169513 709665832 644893225 583701801 510849769 442737741 376021494 306218560 233848779 167390192 110893711 65955027 27020521 1569058 964613...

result:

ok single line: '639939 441073320 683590 708316...1790 26361360 25690700 25490546'

Test #8:

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

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 3993744 973...

result:

ok single line: '3993744 445094234 3993744 7322...4338 19169021 19169021 18080328'

Test #9:

score: 5
Accepted
time: 3ms
memory: 4004kb

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 299758 817849682 616437715 421496480 213078780 61666646 883992 935769689 877779162 817878376 750525833 686056832 616931290 544691671 481753420 421960808 360786781 301716682 214199296 156816580 109658944 62407808 31382773 15645640 1046339 974966217 956109531 935995699 921231544 898704621 87...

result:

ok single line: '421438549 299758 817849682 616...1410 38876691 38292726 36376810'

Test #10:

score: 5
Accepted
time: 2ms
memory: 3860kb

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 2590306 903966106 875018503 800327124 702205293 639000551 596587717 503601877 458609710 390645993 324606253 258692790 202887162 133360102 100961312 57952168 25662683 19145504 2590306 974719269 956943859 903966106 895877371 885780070 ...

result:

ok single line: '390645993 2590306 800327124 59...7816 28927816 28927816 34818749'

Test #11:

score: 5
Accepted
time: 3ms
memory: 3852kb

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 929762282 909420457 890694885 858684963 832307168 802192185 773609401 747191883 720179497 687859238 661804343 630310546 606945203 584354638 548218023 524864103 500882116 474418984 444368672 418000567 385437667 358803886 328551819 30...

result:

ok single line: '802065619 630248249 444093505 ...3 976678613 976027763 975711792'

Test #12:

score: 5
Accepted
time: 3ms
memory: 3808kb

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 21576086 503406414 249198018 127031097 21576086 778914550 503406414 337602783 249198018 179787248 127031097 61502514 21576086 845898193 778914550 582416109 550326722 503406414 366842538 337602783 309157213 249198018 241473222 179787248 153239311 127031097 116504570 61502514 37966549 215760...

result:

ok single line: '249198018 21576086 503406414 2...5 338102165 366842538 366842538'

Test #13:

score: 5
Accepted
time: 257ms
memory: 21960kb

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 4209 929100088 861859784 797240948 725066942 648761449 581201642 506053647 436759152 361733411 294246483 227023143 156044902 105085197 58888672 24915566 4209 965315492 92910008...

result:

ok single line: '4209 436759152 4209 725066942 ...9593 36359593 36359593 36359593'

Test #14:

score: 5
Accepted
time: 228ms
memory: 21744kb

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 9042246 660193 978581914 959074973 939882380 907752835 889178830 8573...

result:

ok single line: '438962117 660193 804221164 613...7931 29237931 29237931 29237931'

Test #15:

score: 5
Accepted
time: 238ms
memory: 21792kb

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 565297049 336934796 116943052 23559449 632 965763311 936045270 900319246 865004548 834864097 800235393 765537888 735642855 700307185 665500072 635730191 600588700 565301231 535327828 501110249 466355188 436161190 401317136 367242218 336935220 301900879 267011400 236799193 202374796 1670215...

result:

ok single line: '765536274 565297049 336934796 ...9492 30259262 30258887 30258476'

Test #16:

score: 5
Accepted
time: 244ms
memory: 21848kb

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 208351230 1313 776663980 553518319 491351697 409458633 352177539 271598711 208353227 134970017 92402890 38012987 2331 920462262 856854977 776668714 712765583 630753928 571425864 553519674 530490468 514404200 491353061 473705158 450296815 432253839 409460066 393507812 369849525 352178322 32...

result:

ok single line: '409457234 208351230 1313 77666...5 579672337 579667670 579660889'

Test #17:

score: 5
Accepted
time: 209ms
memory: 21904kb

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 66848454 940241 904350273 775588378 656310970 548027607 483820240 379323252 274383576 159663404 132054617 113576773 99377069 81189684 66848454 48714043 32173999 19112375 9534209 940241 986018262 958351099 935025602 904350273 879140891 850813540 826703995 794778449 775588378 74716...

result:

ok single line: '548027607 132054617 66848454 9...1 143207371 143207371 145023302'

Test #18:

score: 5
Accepted
time: 244ms
memory: 22128kb

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 1034843 548695587 205156641 28872639 1034843 811089301 548695587 366967314 205156641 106681661 28872639 1034843 930404799 811439971 685250589 548695587 445590092 366967314 248795417 205156641 162824144 106681661 70674584 28872639 1034843 946836461 930404799 854259756 811439971 7408...

result:

ok single line: '1034843 205156641 1034843 5486...4 207113694 207113694 207113694'

Test #19:

score: 5
Accepted
time: 239ms
memory: 21828kb

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 138613 644365687 426668964 168588790 74960070 138613 869263078 785749805 644365687 566773110 426668964 357537890 237226679 168588790 109983988 74960070 51771854 20429073 138613 954276379 921711375 869263078 828689367 785749805 742783381 707371913 644365687 607478191 566773110 539709893 490...

result:

ok single line: '168588790 138613 644365687 426...0 154587020 154587020 154587020'

Test #20:

score: 5
Accepted
time: 259ms
memory: 21996kb

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 474628750 397154894 324229319 268893514 192098431 129219221 96145583 48411697 7650 978792661 951725058 923669147 896121665 877210811 850402596 818374581 8014552...

result:

ok single line: '474628750 5816 877193090 66902...2481932 2481932 2481932 2481932'