QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#405046 | #7944. Max Minus Min | ucup-team992# | TL | 795ms | 261476kb | C++20 | 1.7kb | 2024-05-05 09:04:28 | 2024-05-05 09:04:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ar array
typedef int uci;
#define int long long
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define ll long long
typedef pair<int, int> pii;
typedef vector<int> vi;
void solve(){
ll N; cin >> N;
vi A(N); rep(i,0,N) cin >> A[i];
ll M = A[0], m = A[0];
rep(i,0,N) {M = max(M,A[i]); m = min(m,A[i]);}
map<ll, vi> indices;
rep(i,0,N) indices[A[i]].push_back(i);
ll ans = M-m;
ll maxr = -1;
ll l = N+1;
ll r = -1;
for(ll m2 = m; m2 <= M; m2++) {
ll ol = l, olr=r;
for(auto i: indices[m2]) {l = min(l,i); r = max(r, i);}
if(olr<0) {
rep(i,l,r+1) maxr = max(maxr, A[i]);
} else {
rep(i,l,ol) maxr = max(maxr, A[i]);
rep(i,olr+1,r+1) maxr = max(maxr, A[i]);
}
if(maxr + m2 - m + 1 > M) break;
ans = M-m2-1;
}
nextl1:
ll minr = M+1;
l = N;
r = -1;
for(ll M2 = M; M2 >= m; M2--) {
ll ol = l, olr=r;
for(auto i: indices[M2]) {l = min(l,i); r = max(r, i);}
if(olr<0) {
rep(i,l,r+1) minr = min(minr,A[i]);
} else {
rep(i,l,ol) minr = min(minr,A[i]);
rep(i,olr+1,r+1) minr = min(minr,A[i]);
}
if(minr - (M-M2+1) < m) break;
ans = min(ans, M2-m-1);
}
nextl2:
cout << ans << '\n';
}
uci main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
ll T; cin >> T;
rep(t,0,T) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3480kb
input:
4 3 42 42 42 4 1 2 2 1 5 1 100 1 100 1 6 1 2 3 4 5 6
output:
0 0 99 2
result:
ok 4 number(s): "0 0 99 2"
Test #2:
score: 0
Accepted
time: 12ms
memory: 3496kb
input:
19530 6 2 3 3 3 4 3 6 2 4 4 2 5 5 6 2 5 2 5 1 3 6 4 4 1 2 4 1 5 5 4 5 3 3 5 2 2 1 5 1 6 3 1 2 4 2 3 5 5 5 4 4 5 6 5 3 3 1 4 2 6 3 3 2 4 2 4 6 1 2 4 5 2 5 5 3 4 5 5 3 6 4 3 3 3 4 3 6 1 5 1 2 3 1 5 5 5 2 1 4 6 1 2 5 3 5 2 6 4 5 2 4 5 2 5 2 4 2 4 1 4 2 3 3 3 6 1 2 2 1 4 5 6 3 2 1 3 3 2 6 2 1 1 2 5 3 6 ...
output:
1 2 3 3 1 1 2 0 3 2 3 1 1 2 1 2 3 2 0 1 1 2 0 3 2 2 3 2 2 2 3 3 2 2 1 2 2 2 2 2 2 1 2 1 2 1 2 2 2 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 2 3 2 2 1 1 2 1 2 3 2 0 2 1 1 2 1 1 2 2 2 1 3 2 1 2 3 2 1 1 2 2 3 1 1 1 2 2 1 1 1 1 2 2 2 2 2 3 2 1 2 0 1 1 1 1 1 1 2 2 2 2 2 2 1 2 1 2 4 1 1 1 3 2 2 2 1 2 1 2 1 2 2 1 3 ...
result:
ok 19530 numbers
Test #3:
score: 0
Accepted
time: 99ms
memory: 27864kb
input:
1 199996 95228303 201285494 63848235 748936712 940169142 379639162 189291770 224201078 335564466 792345215 948056869 35198826 312793561 194588099 297198853 665606109 163797196 584404459 996890415 458867609 331820116 713293915 858136035 520976262 519894660 918315819 660535535 639896052 141007070 1151...
output:
999986012
result:
ok 1 number(s): "999986012"
Test #4:
score: 0
Accepted
time: 107ms
memory: 27404kb
input:
1 199998 527515482 831759304 786398217 142876272 541300660 926936654 117644051 72438862 579434512 298922247 726038416 333034763 721144032 811978092 585764800 216757507 702854739 157207076 124829370 951519274 884953479 246664247 437913730 867100723 186107370 511591980 673723365 46011051 452152759 270...
output:
999982414
result:
ok 1 number(s): "999982414"
Test #5:
score: 0
Accepted
time: 110ms
memory: 27712kb
input:
1 199996 664835369 535862041 172511710 536815834 363770542 769201437 45996332 625709355 118271849 100466570 798987255 630870699 908156139 60771864 242926966 399312687 905475794 730009693 916331839 370542011 733054133 853663508 722724134 623290601 852320082 809900849 350474706 862191469 468331156 761...
output:
999985829
result:
ok 1 number(s): "999985829"
Test #6:
score: 0
Accepted
time: 102ms
memory: 28424kb
input:
1 199998 728526329 166335849 895061692 562159176 891273133 980062441 974348614 473947140 67174604 607043603 282001509 560110415 316506610 973129149 531492913 655496794 444533336 597779601 44270795 789564748 917591276 755630061 302501830 969415063 854969281 108209717 953597119 604742957 484509554 621...
output:
999969572
result:
ok 1 number(s): "999969572"
Test #7:
score: 0
Accepted
time: 107ms
memory: 28616kb
input:
1 199998 865846216 165405878 912578966 251066028 787371942 822327224 271297114 322184924 311044650 408587926 986354129 857946351 798486009 926955630 525091568 543084682 647154390 170582217 835773264 577183705 470724637 952563905 660941162 315539524 521181991 406518586 335381168 10857956 500687951 11...
output:
999964695
result:
ok 1 number(s): "999964695"
Test #8:
score: 0
Accepted
time: 89ms
memory: 21532kb
input:
2 53064 626000898 221967145 345169505 82068734 702234813 12584781 696818177 437027007 675473634 401025770 489012528 838016710 229255283 146265714 58851900 50317524 118508121 443178663 688346675 26420200 243286360 900568139 507939681 714342908 406102977 701868009 826713254 705530551 980176160 4536422...
output:
999949128 999983244
result:
ok 2 number(s): "999949128 999983244"
Test #9:
score: 0
Accepted
time: 94ms
memory: 18604kb
input:
2 86135 961507416 239484419 739109067 683200252 618128524 645969771 881492450 680897053 477017958 105378389 491881172 246367180 773016348 434831661 610003299 884342359 986278030 866084911 812402121 210957343 850285621 553974762 854064143 85588326 704411846 378619350 232828254 353112728 840052815 818...
output:
999989368 999979159
result:
ok 2 number(s): "999989368 999979159"
Test #10:
score: 0
Accepted
time: 97ms
memory: 18848kb
input:
2 114819 665610152 257001693 764452408 210702842 755360600 574322052 434762943 924767099 278562281 588392644 789717109 728346580 95439048 723397608 792558479 791996121 854047938 362620087 600021077 764090705 383655953 133752457 200188604 383204817 666284226 686774472 975379743 369291125 331333250 84...
output:
999957148 999925013
result:
ok 2 number(s): "999957148 999925013"
Test #11:
score: 0
Accepted
time: 113ms
memory: 21952kb
input:
2 51745 296083961 979551675 158391969 33172724 671254311 502674333 283000727 168637145 80106605 661341483 718956825 505293270 639200113 11963554 48742585 920988247 426850554 154122555 19043814 22256775 580589798 418562861 914909286 754450236 964593095 994929594 86527451 680436815 822613686 213225598...
output:
999935991 999977026
result:
ok 2 number(s): "999935991 999977026"
Test #12:
score: 0
Accepted
time: 218ms
memory: 45104kb
input:
2 190655 295153990 365665168 478702602 929271535 513519094 431026614 131238512 412507191 881650930 439323030 721825469 618676449 961622815 5562209 231297765 828642010 294620462 282061512 438066552 206793918 482556350 998340557 966066456 420662947 557869256 671680935 829078940 696615212 682490341 652...
output:
999986925 999410177
result:
ok 2 number(s): "999986925 999410177"
Test #13:
score: 0
Accepted
time: 735ms
memory: 261476kb
input:
3 509 945103490 925258646 551206125 526700079 667773410 95427191 362812642 886786434 870232904 495179381 81906730 281227871 253895133 37646925 42217132 359205845 471862629 935227244 26261416 979759614 224254713 556220075 695518823 269277086 725271797 910519987 326988819 137416508 605439760 724706756...
output:
992734363 999989683 999826782
result:
ok 3 number(s): "992734363 999989683 999826782"
Test #14:
score: 0
Accepted
time: 107ms
memory: 18508kb
input:
4 25729 148578218 399443910 770570125 469317733 578441446 955615870 169612 119026676 783745328 338090837 820285414 826697750 460553174 534868797 912339208 373829181 515004940 372385878 645972324 522563583 864375197 101633822 580422775 216552232 275859942 529623463 963747478 462104612 760212230 83453...
output:
999888931 999891034 999960265 999881981
result:
ok 4 number(s): "999888931 999891034 999960265 999881981"
Test #15:
score: 0
Accepted
time: 249ms
memory: 53508kb
input:
5 7824 952714403 309407462 270862057 651390285 253451805 777116303 367820449 72311274 520646017 22906468 694467658 957088351 658924243 170505277 275795733 168411563 718510340 648621523 115839743 836093830 844185312 596601172 707832668 9796117 805887036 495111155 245140536 427121484 204604275 6740390...
output:
998412528 999965938 999453971 999964102 999954744
result:
ok 5 number(s): "998412528 999965938 999453971 999964102 999954744"
Test #16:
score: 0
Accepted
time: 451ms
memory: 114996kb
input:
6 7149 258310216 72406381 429371832 256320449 890499482 985210442 729473441 776830124 561964011 562237566 748590818 77946979 650009712 177762285 453221967 769667510 314834233 119181320 849281660 955333020 612779569 567709323 670103366 82150607 321442125 733209168 462626958 869644823 848320244 706702...
output:
999480642 999875981 999949063 997982749 999914475 999892960
result:
ok 6 numbers
Test #17:
score: 0
Accepted
time: 397ms
memory: 56500kb
input:
7 16819 578983413 502320670 554156386 667446173 234004214 18039387 959385303 395988845 135040182 876529775 496969717 203143074 6099910 32999662 115791971 981046945 417490189 157436781 66480727 628957967 353957051 109072249 284785251 852805803 884841312 424503504 534685369 727634172 946504457 2615944...
output:
999790819 999967769 999353168 999916205 999029434 999468671 999517643
result:
ok 7 numbers
Test #18:
score: 0
Accepted
time: 514ms
memory: 143648kb
input:
8 29021 616738706 483396102 75796643 146361498 306605334 510536702 598609899 707842799 668032243 989621382 756276437 908066463 317810067 461916433 278663435 10766349 834188123 103999508 645136364 845237487 843008426 561048823 974104064 667877236 796445467 904758625 196882683 186306199 953584113 4257...
output:
999918412 999570747 999973927 999050677 999539352 999916183 999887707 998670357
result:
ok 8 numbers
Test #19:
score: 0
Accepted
time: 748ms
memory: 168540kb
input:
9 37136 486264746 557776042 100187980 300203989 398124589 432634734 575612707 164567419 408644119 645846287 810033015 897587763 218106311 649908854 309075218 142343244 920179925 956282053 410146850 503315673 132279686 505467742 155945868 126918233 864766464 371163903 131140649 350606443 429219755 22...
output:
999799709 999929058 999948989 999811617 999786771 999526295 999805610 997448953 999646655
result:
ok 9 numbers
Test #20:
score: 0
Accepted
time: 795ms
memory: 116268kb
input:
10 5543 167330214 188915787 22596977 283315922 625320639 228617645 282545327 230150386 552702835 716228254 474861297 817414746 774990558 855963275 14435565 876904270 168862381 704047836 629575366 451396215 56903186 809266075 332272060 232038554 741712502 479043833 601664005 176505178 453922701 29541...
output:
998232492 999430106 999686964 998491202 999850116 999350387 999769603 999914606 999874299 999833527
result:
ok 10 numbers
Test #21:
score: -100
Time Limit Exceeded
input:
100 2336 727549620 741730767 408911556 945446245 572038064 685609097 128205004 829936008 281081951 754715688 816339011 33520063 908787051 515313288 551649559 542879422 387539530 197674304 87720945 641686985 185882310 676226017 871051739 957002232 2277122 142180596 415788089 732362363 798930745 37640...