QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#50439 | #4835. Mode | YaoBIG# | TL | 1087ms | 8124kb | C++ | 3.2kb | 2022-09-26 03:38:57 | 2022-09-26 03:38:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e9 + 7;
const int TRESHOLD = 450;
// returns number of elements strictly smaller than v in vec
template<class T>
int bins(const vector<T>& vec, T v) {
int low = 0;
int high = vec.size();
while(low != high) {
int mid = (low + high) >> 1;
if (vec[mid] < v) low = mid + 1;
else high = mid;
}
return low;
}
void offer(int v, int off, pair<int, vector<int>>& res) {
if (off == res.first) res.second.push_back(v);
else if (off > res.first) {
res.first = off;
res.second = {v};
}
}
void solve() {
int n;
cin >> n;
vector<int> as(n);
for (int& a : as) cin >> a;
vector<int> cmp = as;
sort(cmp.begin(), cmp.end());
cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());
for (int i = 0; i < n; ++i) as[i] = bins(cmp, as[i]);
int k = cmp.size();
vector<int> tot(k, 0), suff_max(n + 1, 0);
for (int i = n-1; i >= 0; --i) {
++tot[as[i]];
suff_max[i] = max(suff_max[i + 1], tot[as[i]]);
}
int h = 0;
for (int v : tot) h = max(h, v);
vector<int> pre(n), lst(k, -1);
for (int i = 0; i < n; ++i) {
pre[i] = lst[as[i]];
lst[as[i]] = i;
}
pair<int, vector<int>> res;
res.first = 0;
if (h >= TRESHOLD) {
// O(n^2 / h)
for (int v = 0; v < k; ++v) {
if (tot[v] < h/2) continue;
vector<int> cou(n + 1, 0);
for (int i = 0; i < n; ++i) cou[i + 1] = (cou[i] + (as[i] == v));
for (int v2 = 0; v2 < k; ++v2) {
if (v2 == v) continue;
vector<int> apps = {lst[v2]};
for (int j = pre[lst[v2]]; j >= 0; j = pre[j]) apps.push_back(j);
reverse(apps.begin(), apps.end());
// Have v2 on the inside
int bst = -INF;
for (int j = (int)apps.size() - 1; j >= 0; --j) {
bst = max(bst, j + 1 - cou[apps[j]]);
offer(v, tot[v] + bst - j + cou[apps[j]], res);
// cerr << v << ' ' << v2 << ' ' << j << ' ' << apps[j] << ": " << tot[v] << ' ' << bst << ' ' << j << ' ' << cou[apps[j]] << '\n';
}
// Have v2 on the outside
bst = -INF;
for (int j = (int)apps.size() - 1; j >= 0; --j) {
bst = max(bst, cou[apps[j]] - j);
offer(v2, tot[v2] + bst + j + 1 - cou[apps[j]], res);
// Simple offers
offer(v2, tot[v] + j+1 - cou[apps[j]], res);
offer(v2, cou[apps[j]] + tot[v2] - j, res);
}
}
}
} else {
// O(nh)
vector<int> counts = {n};
for (int i = 0; i < n; ++i) {
for (int a = 1, b = 0, j = pre[i]; a < counts.size(); ++a) {
while(counts[a] <= j) {
++b;
j = pre[j];
}
offer(as[i], tot[as[i]] + a - b, res);
}
int cur = 0;
for (int j = i, cou = 1; j >= 0; j = pre[j], ++cou, ++cur) {
if (counts.size() <= cou) counts.emplace_back(j);
else counts[cou] = max(counts[cou], j);
}
offer(as[i], cur + suff_max[i + 1], res);
}
}
cout << res.first << '\n';
sort(res.second.begin(), res.second.end());
res.second.erase(unique(res.second.begin(), res.second.end()), res.second.end());
for (int v : res.second) cout << cmp[v] << ' '; cout << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
for (int ti = 0; ti < t; ++ti) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3572kb
input:
4 5 1 2 3 2 1 5 1 1 3 1 1 6 2 4 2 4 8 8 5 1 2 3 4 5
output:
4 1 5 1 4 2 4 8 2 1 2 3 4 5
result:
ok 14 numbers
Test #2:
score: 0
Accepted
time: 3ms
memory: 3776kb
input:
10 300 336470888 634074578 642802746 167959139 642802746 481199252 481199252 481199252 167959139 634074578 634074578 336470888 336470888 481199252 642802746 481199252 481199252 167959139 642802746 634074578 167959139 336470888 634074578 642802746 167959139 481199252 167959139 167959139 167959139 481...
output:
80 481199252 634074578 46 153774342 39 846318354 30 937534594 27 698063951 27 419330425 20 603780410 706588687 801036056 20 541308492 19 352404708 16 187061768 428773075
result:
ok 24 numbers
Test #3:
score: 0
Accepted
time: 3ms
memory: 3752kb
input:
10 300 641009859 804928248 804928248 804928248 804928248 641009859 476927808 641009859 641009859 641009859 75475634 804928248 804928248 641009859 804928248 54748096 75475634 75475634 54748096 75475634 54748096 54748096 476927808 476927808 75475634 476927808 641009859 75475634 476927808 476927808 754...
output:
84 75475634 47 173884819 253838924 593535580 37 119584259 29 66715052 671541499 706982083 25 683509776 23 145885283 637691905 26 968506132 18 277852473 891198181 954696748 18 967045702 19 493331319
result:
ok 27 numbers
Test #4:
score: 0
Accepted
time: 3ms
memory: 3644kb
input:
10 300 923264237 524125987 524125987 524125987 923264237 751244358 374288891 923264237 923264237 923264237 535590429 524125987 374288891 751244358 524125987 923264237 751244358 751244358 923264237 751244358 535590429 535590429 751244358 923264237 751244358 524125987 751244358 923264237 524125987 923...
output:
85 524125987 50 475906689 38 802613215 28 824887911 28 506836893 754648411 23 708438632 731263599 20 210467639 284624362 746100908 806519500 980100704 21 797383894 21 156438550 977566828 17 111777754
result:
ok 27 numbers
Test #5:
score: 0
Accepted
time: 3ms
memory: 3596kb
input:
10 300 702209411 496813081 561219907 702209411 702209411 561219907 730593611 496813081 702209411 561219907 673102149 702209411 496813081 702209411 673102149 496813081 730593611 496813081 673102149 702209411 673102149 673102149 496813081 496813081 702209411 673102149 561219907 702209411 561219907 561...
output:
81 496813081 53 675266630 38 767363622 32 404396525 27 118275344 195136790 21 422498140 522949042 869477976 887728896 998214353 22 611458649 20 298642883 618165181 853396846 18 510545542 18 41119063 42804963 383659701
result:
ok 29 numbers
Test #6:
score: 0
Accepted
time: 99ms
memory: 8000kb
input:
6 200000 564718673 564718673 291882089 291882089 412106895 291882089 291882089 412106895 564718673 564718673 412106895 412106895 412106895 564718673 291882089 564718673 412106895 291882089 564718673 291882089 564718673 291882089 291882089 564718673 291882089 412106895 564718673 291882089 564718673 5...
output:
72021 564718673 40464 764450551 14267 485362070 14627 904735088 4168 647351267 2097 876938652
result:
ok 12 numbers
Test #7:
score: 0
Accepted
time: 96ms
memory: 7936kb
input:
6 200000 757703054 544067926 5887448 544067926 757703054 757703054 544067926 757703054 544067926 544067926 643910770 544067926 5887448 544067926 757703054 544067926 5887448 544067926 5887448 643910770 5887448 757703054 544067926 544067926 544067926 544067926 544067926 544067926 757703054 757703054 5...
output:
72009 544067926 40553 532894160 14507 280401558 14661 652613244 4149 954112179 2118 387281831
result:
ok 12 numbers
Test #8:
score: 0
Accepted
time: 85ms
memory: 7976kb
input:
6 200000 941492387 378192988 783332532 378192988 378192988 72235422 378192988 378192988 378192988 783332532 783332532 783332532 378192988 378192988 783332532 378192988 783332532 72235422 378192988 449924898 378192988 783332532 941492387 449924898 72235422 72235422 72235422 378192988 378192988 378192...
output:
72125 378192988 40566 204258647 14420 679764421 14458 621315231 4176 283127255 2125 379004468
result:
ok 12 numbers
Test #9:
score: 0
Accepted
time: 79ms
memory: 8124kb
input:
6 200000 652509537 513994713 513994713 513994713 940751563 652509537 652509537 43705451 513994713 652509537 43705451 513994713 513994713 652509537 652509537 43705451 513994713 940751563 513994713 652509537 43705451 940751563 43705451 43705451 652509537 513994713 513994713 652509537 513994713 5139947...
output:
72040 652509537 40565 33034714 14364 848061415 14689 972643361 4192 106061785 2110 861238489
result:
ok 12 numbers
Test #10:
score: 0
Accepted
time: 243ms
memory: 6612kb
input:
9 50000 264178469 144383292 725622388 29492121 605488152 580675905 55883389 390555088 441004197 831609975 438791943 987615719 859267729 743196568 55883389 39388076 959436397 876153780 45621610 363531956 977960026 782710197 106874917 807199457 562810007 715666999 743196568 538628510 824046493 1893675...
output:
432 752268030 91 254698774 3 12093 60583 90748 127514 236374 353911 368891 378263 400779 470972 478812 494946 510827 581713 599252 615790 629984 637246 701304 786939 829043 829312 845188 889918 916550 959344 965105 1017725 1049787 1062654 1070749 1080286 1081671 1166002 1169723 1181573 1183208 122...
result:
ok 25213 numbers
Test #11:
score: 0
Accepted
time: 243ms
memory: 6748kb
input:
9 50000 962118480 224422012 530689910 598196518 780267148 621837875 609026662 572394174 7897785 147043779 266397628 168565069 996408310 102067050 634382639 349570916 116002772 879226371 885888570 327981393 627552028 237784764 96204862 620985129 565390129 447700005 116002772 631413076 653535984 20424...
output:
416 62611196 983359971 90 107074781 643264242 3 23227 45992 77973 82516 88807 165433 168782 196483 329750 379946 434404 476061 484239 514555 515876 595779 609792 610877 636970 751634 779432 789743 857129 895585 912839 1076739 1166389 1258455 1310282 1337130 1420860 1499159 1570380 1579613 1592225 ...
result:
ok 25218 numbers
Test #12:
score: 0
Accepted
time: 1024ms
memory: 7212kb
input:
9 200000 135784616 930376306 84361809 985295444 851292970 269236805 856798091 271181548 762217893 856798091 462749196 120755595 531571129 604211010 493908907 940486169 604211010 283516964 762217893 407741671 990711947 205335962 178685515 360234468 964851431 992963178 261895625 812267178 990711947 17...
output:
1519 6962495 106 284854399 36 72700176 625030539 998418613 20 4708984 21638247 25944554 311172186 357325474 670434401 773565295 1015 406948177 2501 99440824 107215326 375570744 387799976 55 11588682 12972610 20897063 26205844 37106836 45190049 55821994 58636324 79987571 82666901 90477975 91080...
result:
ok 45168 numbers
Test #13:
score: 0
Accepted
time: 1024ms
memory: 7216kb
input:
9 200000 725743030 30028136 108363704 132541583 233129596 19219689 856407544 987503539 172639782 153113856 729626528 341033928 156410721 482750975 678092074 494457330 258978219 146102138 709650431 274969460 59820892 664720419 990219478 322188987 901999530 675880331 943159603 423585569 272812766 1743...
output:
1538 343342034 106 317511752 539940990 725124952 35 768762226 20 6523560 60432456 114843736 126398351 156670961 283509084 371703512 426837279 436686342 468890936 473003550 504146483 554659729 835413643 1019 987463849 5001 396357249 404217765 56 10939303 11521641 13992263 17225651 24816521 2899...
result:
ok 45201 numbers
Test #14:
score: 0
Accepted
time: 1077ms
memory: 7092kb
input:
9 200000 259924440 482843646 698405858 81829609 668643035 120115078 465713378 795525066 468586155 869487013 464799976 872257813 729091232 158103417 939650978 204652647 729091232 948940622 284430414 575073865 259924440 668643035 668643035 81829609 450236911 129772276 812967691 305614847 729091232 877...
output:
1513 22499636 109 723253814 34 235430243 20 6390485 16439594 84871695 90637215 105894856 111732401 114485810 115322402 135713539 172295642 198914375 307517989 319720950 330982551 424398819 485917637 494352242 542747394 580755161 606211322 646568947 724021598 736789363 766748367 776946075 79233612...
result:
ok 45117 numbers
Test #15:
score: 0
Accepted
time: 1052ms
memory: 7508kb
input:
9 200000 888134619 66269133 509900976 163810765 143703759 163810765 854756227 146141988 888134619 183817154 978602533 5192585 715910077 5192585 567678137 774920273 470853832 368687845 368799527 203971504 240701357 644793984 183817154 774920273 653069289 180071384 978602533 408839201 183817154 171420...
output:
1511 448599941 107 926889556 35 184205986 306398259 526309676 747903041 20 42810625 100223221 107274411 111942280 124998844 131893527 149445814 154380679 169672593 177752769 186703689 238905954 285690681 360707994 381030191 388106329 389961350 485320672 533728043 537938022 557774659 583518077 593...
result:
ok 45236 numbers
Test #16:
score: 0
Accepted
time: 1011ms
memory: 7164kb
input:
9 200000 73842336 136680216 621080695 666865318 160471107 546318047 6426671 382252749 368317095 556784178 162093547 261854484 843033743 258790234 484537901 158560673 908579552 102513046 765800986 190705915 355958959 660867016 560507758 73842336 459238545 919716424 739715261 99349978 946879386 592356...
output:
1513 182330345 115 924866239 35 473421507 544286978 20 27578725 69995657 96254998 108343444 130958890 148622143 161397629 188299191 256845517 288071428 322808295 341013782 348676074 405252151 417261444 423000440 509097231 522038777 571201755 579809652 593380535 600545884 648569241 691095316 70265...
result:
ok 45125 numbers
Test #17:
score: 0
Accepted
time: 1024ms
memory: 7132kb
input:
9 200000 317786155 96515847 222493722 70967262 888446782 779886867 638247548 338875831 172030458 78054611 767171259 127409208 837418741 736004147 458027028 580568152 462603834 875136891 686756569 436879176 857115203 886678205 172030458 819971755 530735129 747661596 363495802 654860294 279397774 1274...
output:
1497 548228514 110 244545335 32 19180303 48171730 66461630 320868401 410993082 573856318 639377421 719064833 784665837 936236452 20 10204603 32434499 60092661 64234622 164436517 224151388 261203787 303689062 323180625 348100475 371038641 391283497 408543592 452957601 465602602 485938740 488269740...
result:
ok 45140 numbers
Test #18:
score: 0
Accepted
time: 1087ms
memory: 7128kb
input:
9 200000 45409652 235649445 235649445 549349991 458256339 790761728 328822538 625672915 164800546 599197383 72261464 754382508 216022244 777618263 381586476 29613623 678393925 224602191 207229582 11988400 25203298 233596921 815509812 305555972 48953130 707869688 216022244 64999512 862759972 78793927...
output:
1508 843116152 106 118864836 35 380920549 20 10282409 42159790 63145970 70091816 152051075 177868106 190621579 355548478 361587442 435572107 436289783 445885116 467186436 473242102 503654443 520957056 542819238 578606653 593074719 599679913 627545388 695163335 702826276 745014921 759849791 777728...
result:
ok 45186 numbers
Test #19:
score: 0
Accepted
time: 1012ms
memory: 7148kb
input:
9 200000 962636738 659949746 990724893 374392733 418160283 432681473 280790303 990724893 479162773 255124409 525244419 449144296 869729807 401182818 599473018 60606166 663226971 418160283 235756777 286461965 249699420 179944793 60606166 642879999 371616484 173351006 753434266 107173713 718880383 249...
output:
1502 453595703 105 278346314 386832331 37 365936735 382124501 20 24669726 105664496 356210646 531168236 603403566 644042701 686072325 790180830 955137028 996520483 1017 248599916 3335 298072584 67 19993925 20652289 33823722 86416159 86935428 95705174 96591200 106100027 145327727 149208966 1679...
result:
ok 45135 numbers
Test #20:
score: 0
Accepted
time: 1052ms
memory: 7204kb
input:
9 200000 115209394 576447346 547139308 261969202 914539062 20101580 356150426 467908848 232758068 818725993 467908848 159595153 590951729 282436814 758315712 193787527 408916833 738307717 479489724 764655030 338589400 454338516 818725993 483456905 276843270 363467715 965696474 239862203 590951729 36...
output:
1495 214911410 102 462891101 38 57040259 20 5378814 173349077 230192561 336434984 399643086 426558780 440657144 559123439 585280058 585877393 603956467 626298919 685558179 741260520 831109430 905506922 1017 755021310 2501 129390957 297826679 435587260 460940731 63 10654436 21766107 40937212 42...
result:
ok 45144 numbers
Test #21:
score: 0
Accepted
time: 1018ms
memory: 7076kb
input:
9 200000 199661234 217496893 475351765 102844764 801878032 280362149 382292455 862407789 919571086 237784464 396909705 717802881 798684788 51795969 586588704 694385934 427833657 422130608 661699500 903631686 610613187 730980950 382292455 234429745 81507010 811254995 935958538 148658854 694385934 724...
output:
1517 668774730 112 790429610 35 599135129 20 5099691 13151910 26320111 43761826 53238162 53859450 61867865 81043710 99510236 116965675 119782176 124281900 124750791 170506037 205834874 231072926 285760927 294631038 301802212 373554157 384765556 386390796 391457725 447883817 461393830 463501811 48...
result:
ok 45135 numbers
Test #22:
score: -100
Time Limit Exceeded
input:
12 200000 621837875 912591234 690846426 701317769 546816240 116002772 466097892 466097892 25203351 303640854 102467451 463278943 998133227 642911606 5764908 420188705 500165093 521027619 870739178 164353437 831452391 472379315 121227049 885888570 343766215 455613697 192568336 598196518 267884026 559...