QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#864819 | #894. Longest Loose Segment | lc20110802 | AC ✓ | 739ms | 45696kb | C++14 | 971b | 2025-01-21 09:13:50 | 2025-01-21 09:13:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, m, a[N], l[N], b[N], ls[N], rs[N], stk[N], top, ans;
void dfs(int u){
if(ls[u]) dfs(ls[u]);
if(rs[u]) dfs(rs[u]);
l[u] = l[ls[u]] + 1 + l[rs[u]];
b[u] = max(a[u], max(b[ls[u]], b[rs[u]]));
ans = max(ans, min(b[u] + a[u] - 1, l[u]));
return ;
}
void solve(){
top = 0;
for(int i = 1; i <= n; i++){
ls[i] = rs[i] = 0;
int k = top;
while(k > 0 && a[stk[k]] > a[i]) k--;
if(k) rs[stk[k]] = i;
if(k < top) ls[i] = stk[k + 1];
stk[++k] = i;
top = k;
}
ans = 0; b[0] = -1e9;
dfs(stk[1]);
cout << ans << "\n";
return ;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i];
solve();
for(int i = 1; i <= m; i++){
int k; cin >> k;
for(int i = 1; i <= k; i++){
int x, y; cin >> x >> y;
swap(a[x], a[y]);
}
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 12004kb
input:
5 2 1 2 -2 3 4 1 2 3 1 1 2
output:
2 3 4
result:
ok 3 tokens
Test #2:
score: 0
Accepted
time: 687ms
memory: 43092kb
input:
998546 30 998544 998544 998543 998539 998538 998537 998536 998534 998533 998531 998529 998527 998522 998521 998520 998520 998516 998514 998512 998509 998501 998501 998500 998499 998498 998496 998494 998493 998491 998491 998490 998489 998489 998488 998488 998486 998483 998480 998479 998478 998475 998...
output:
212114 16718 12587 9069 8111 7079 7403 7403 5937 5941 5846 5758 6492 5465 5465 5565 5565 5408 5408 5668 5668 5408 6263 6350 6350 5325 4608 4612 4612 4430 4612
result:
ok 31 tokens
Test #3:
score: 0
Accepted
time: 677ms
memory: 37724kb
input:
996793 30 -4 -9 -9 -12 -12 -16 -18 -19 -21 -23 -25 -26 -27 -32 -35 -36 -39 -40 -41 -43 -44 -44 -46 -50 -50 -51 -51 -53 -54 -55 -56 -59 -60 -71 -75 -78 -78 -81 -89 -89 -92 -97 -97 -97 -98 -99 -99 -100 -100 -103 -107 -108 -110 -114 -116 -120 -122 -122 -124 -126 -127 -127 -128 -132 -132 -133 -133 -136 ...
output:
177950 14325 9045 8903 7633 6308 6484 5729 5516 5300 4952 5400 5400 5400 5400 4181 4480 4480 5073 5073 5073 5073 5073 5073 5073 3972 3890 3890 3662 3803 3816
result:
ok 31 tokens
Test #4:
score: 0
Accepted
time: 724ms
memory: 23720kb
input:
996724 30 794282 213907 521445 -364970 -472174 -59279 -474730 572237 755430 273436 -973360 -699601 63661 509831 -290107 -721257 418628 -47045 361250 955842 442167 382489 -707666 723191 706612 -1385 -971455 150071 -959926 281857 513993 349025 -794149 617933 837312 331332 -443900 638587 -696289 620807...
output:
4195 4118 4118 3784 3784 3694 3747 3736 3698 3698 3337 3637 3637 4036 4036 4036 4036 4036 3906 3906 3542 3456 3677 3635 3806 3806 3877 3677 3424 3424 3424
result:
ok 31 tokens
Test #5:
score: 0
Accepted
time: 697ms
memory: 38384kb
input:
993293 30 -2 -9 -15 -17 -18 -19 -20 -20 -21 -22 -23 -23 -25 -26 -29 -31 -33 -37 -38 -40 -42 -43 -47 -48 -48 -50 -50 -54 -54 -55 -61 -62 -64 -65 -70 -70 -72 -72 -73 -74 -74 -74 -76 -77 -79 -79 -81 -83 -85 -97 -99 -101 -102 -103 -104 -105 -106 -106 -108 -112 -113 -115 -117 -120 -124 -129 -134 -134 -13...
output:
545662 14551 9093 7680 7249 6255 5919 6520 6122 6122 6122 5234 4988 4988 4638 4638 4544 4002 3744 3744 3744 3744 4041 4113 4113 4041 3527 3277 3516 3516 3414
result:
ok 31 tokens
Test #6:
score: 0
Accepted
time: 729ms
memory: 24168kb
input:
995079 30 -127626 -806293 760853 221329 639458 26296 -625348 -911169 -484179 -241236 -23083 802181 264523 -913110 597508 -302652 560493 787109 323658 680835 -962692 509475 412378 472202 261783 51513 -264587 -468212 -517463 -526110 174495 -64296 226462 -224507 566922 128999 369163 215486 -405591 4575...
output:
3774 4267 4267 3805 3981 3981 3981 3981 4023 4357 4201 4201 3433 3445 3380 3725 3725 3725 3936 3662 3662 3662 3576 3576 3434 3791 3791 3805 3628 3970 3970
result:
ok 31 tokens
Test #7:
score: 0
Accepted
time: 706ms
memory: 34932kb
input:
996709 30 996706 996705 996705 996704 996702 996700 996700 996696 996695 996694 996694 996692 996685 996674 996674 996671 996668 996666 996664 996663 996661 996661 996660 996658 996653 996644 996640 996639 996638 996634 996632 996631 996630 996628 996628 996626 996624 996623 996623 996622 996621 996...
output:
467704 12585 13169 8147 8574 7568 6832 6294 5157 5424 5424 4803 4564 4542 5227 5227 4558 4493 4786 4413 5271 5271 5271 4237 4603 4563 4563 4699 4699 4745 4662
result:
ok 31 tokens
Test #8:
score: 0
Accepted
time: 719ms
memory: 34280kb
input:
997991 30 -1 -3 -6 -13 -16 -16 -18 -24 -32 -33 -33 -36 -39 -40 -42 -44 -46 -48 -49 -49 -49 -49 -49 -53 -55 -55 -57 -58 -59 -59 -62 -64 -65 -66 -66 -71 -72 -82 -83 -86 -88 -93 -93 -98 -101 -102 -102 -103 -103 -105 -106 -109 -113 -117 -117 -122 -123 -123 -127 -134 -137 -137 -137 -140 -141 -142 -143 -1...
output:
450217 14978 11567 10297 10112 8575 7665 7665 7665 6209 6001 6001 4891 5278 5278 5379 5379 5379 4911 4911 4911 5298 5298 4694 4694 4922 5298 5998 4922 4122 4408
result:
ok 31 tokens
Test #9:
score: 0
Accepted
time: 687ms
memory: 45696kb
input:
999983 30 999980 999979 999978 999978 999976 999974 999970 999970 999968 999968 999966 999962 999961 999961 999957 999957 999955 999952 999947 999943 999943 999943 999941 999941 999939 999939 999937 999937 999936 999935 999935 999933 999929 999927 999927 999926 999926 999923 999923 999921 999920 999...
output:
27630 16359 9244 7724 6188 6188 5435 5714 4439 6165 5156 5156 4446 4272 3784 3585 3923 3923 3923 3987 3987 3915 3901 3901 4228 3901 4238 4238 4238 3878 3878
result:
ok 31 tokens
Test #10:
score: 0
Accepted
time: 724ms
memory: 24280kb
input:
995145 30 -313553 -12505 -925641 186813 16986 924367 805937 184685 532759 387963 -636328 278575 139662 47778 -58494 767510 -799947 282981 260090 370725 294568 -235883 51199 -458398 -393789 -832017 34746 -583575 21917 -241471 -739760 -757370 -269685 -432890 468251 452683 -9740 87799 928942 382241 -94...
output:
3919 4015 3691 3805 3805 3805 3805 3805 3805 3805 3805 4054 4639 4639 4639 4639 4639 4639 4639 4748 5041 5041 5041 5041 5041 4716 4716 4001 4001 3838 4001
result:
ok 31 tokens
Test #11:
score: 0
Accepted
time: 728ms
memory: 24528kb
input:
992678 30 -922071 737416 -842098 839476 616946 -472918 69713 -327751 -327440 8371 -275705 -144781 34229 292897 -810362 86680 -334562 -248801 -918984 -626253 -974872 -596186 -922039 144517 -662063 621170 707835 236920 183995 405198 -268980 710121 621160 -471861 941483 -410726 -618358 -139910 -202452 ...
output:
3756 3756 3877 3756 3468 3501 3501 4095 3836 3836 3959 3959 3959 3868 3868 3868 3815 3793 3793 3814 3952 3642 3642 3458 3458 3514 3527 3514 3514 3314 3666
result:
ok 31 tokens
Test #12:
score: 0
Accepted
time: 672ms
memory: 41148kb
input:
998615 30 2 4 5 10 11 16 17 19 22 23 26 28 29 30 33 35 37 41 41 43 44 46 46 47 48 48 51 54 54 55 56 56 57 60 61 64 64 65 65 66 69 71 73 73 76 77 77 78 80 83 85 87 87 89 94 96 97 97 98 99 104 107 111 113 115 116 118 122 123 123 124 124 126 127 129 130 132 135 136 136 136 137 138 140 140 142 145 147 1...
output:
469834 16083 9564 10235 9393 9060 8037 7081 6187 6351 6351 6365 5387 5150 5415 5415 5229 5082 4662 4662 4662 4662 4662 4662 4434 4434 4336 3936 3889 3889 3795
result:
ok 31 tokens
Test #13:
score: 0
Accepted
time: 683ms
memory: 38688kb
input:
999043 30 999041 999039 999035 999034 999032 999030 999030 999030 999028 999026 999026 999025 999023 999021 999020 999019 999018 999016 999016 999009 999008 999007 999007 999002 998996 998995 998993 998990 998985 998982 998981 998981 998980 998979 998972 998963 998959 998957 998951 998948 998947 998...
output:
520950 14266 9541 7578 7206 5974 6094 5542 5782 5121 5121 4703 4839 4631 4374 4345 4089 4823 4823 4823 4823 4823 4869 4631 4631 4039 4422 4422 4422 4370 4511
result:
ok 31 tokens
Test #14:
score: 0
Accepted
time: 707ms
memory: 43120kb
input:
994645 30 994644 994642 994641 994641 994641 994639 994638 994637 994633 994630 994629 994629 994628 994628 994627 994624 994618 994618 994615 994612 994612 994608 994605 994604 994604 994602 994598 994596 994596 994595 994590 994588 994582 994581 994581 994578 994577 994575 994574 994574 994573 994...
output:
99074 21425 10970 8967 8934 7835 5922 5922 5922 5675 5578 5578 6040 4903 4344 4344 4344 4245 4498 4537 4478 4537 4537 4734 4724 4122 4714 4714 4890 4575 4153
result:
ok 31 tokens
Test #15:
score: 0
Accepted
time: 699ms
memory: 37428kb
input:
998728 30 -5 -8 -11 -11 -15 -15 -16 -17 -18 -22 -23 -24 -25 -26 -26 -26 -30 -32 -32 -32 -38 -38 -40 -41 -43 -44 -46 -49 -49 -49 -50 -52 -54 -58 -58 -59 -62 -62 -62 -63 -63 -64 -64 -67 -71 -75 -75 -77 -78 -87 -88 -92 -93 -96 -97 -97 -98 -98 -99 -100 -101 -101 -102 -103 -106 -106 -106 -107 -109 -111 -...
output:
154225 12801 10365 9255 8130 7227 7209 6032 6032 5386 5421 5376 5338 5139 5935 4575 4130 4085 4085 4347 4347 4198 3859 4346 4122 4122 4110 4377 4377 4203 4203
result:
ok 31 tokens
Test #16:
score: 0
Accepted
time: 692ms
memory: 43732kb
input:
997109 30 -997109 -997105 -997102 -997102 -997100 -997097 -997092 -997092 -997091 -997091 -997086 -997081 -997080 -997078 -997076 -997076 -997076 -997075 -997075 -997074 -997073 -997070 -997070 -997068 -997063 -997053 -997047 -997044 -997043 -997034 -997032 -997031 -997028 -997027 -997024 -997022 -9...
output:
247567 17203 11748 10515 9128 8224 7805 7805 6613 6591 6480 5947 5947 5904 5358 5358 5358 4898 4890 4890 4890 4890 5028 4890 5060 4425 4425 4433 4433 4433 4433
result:
ok 31 tokens
Test #17:
score: 0
Accepted
time: 702ms
memory: 38216kb
input:
994095 30 -6 -6 -8 -11 -12 -16 -16 -17 -18 -19 -21 -22 -27 -28 -31 -33 -35 -37 -42 -46 -46 -46 -48 -49 -50 -52 -56 -57 -63 -65 -67 -67 -68 -78 -79 -79 -80 -80 -82 -82 -88 -93 -95 -96 -100 -106 -106 -106 -106 -107 -111 -112 -113 -114 -117 -118 -119 -128 -129 -130 -131 -133 -135 -136 -147 -148 -150 -1...
output:
622499 14963 9009 7185 6152 5893 5544 5745 5444 5774 5240 5035 5035 5419 5419 5346 5346 5346 5346 4868 4500 4500 4500 3860 3860 4148 4671 4671 4656 4656 4550
result:
ok 31 tokens
Test #18:
score: 0
Accepted
time: 727ms
memory: 23652kb
input:
997223 30 795263 696265 31767 -439658 78179 626005 -500427 303299 771706 31603 756660 857860 948680 950213 446314 749471 596800 241560 839125 -967945 -43187 689054 -565336 156908 356896 843223 -283125 652592 -485247 625086 -408744 547622 283220 402232 251047 860217 136945 696712 -352711 146564 -3205...
output:
4090 4090 3665 3665 3823 3661 3619 3619 3619 3628 3619 4078 4129 4129 3997 4422 3793 3655 3655 3655 3722 3722 3655 4280 4280 4280 4280 4280 3748 3748 3566
result:
ok 31 tokens
Test #19:
score: 0
Accepted
time: 670ms
memory: 44328kb
input:
998083 30 3 3 5 9 10 11 12 17 18 18 24 28 29 30 33 33 35 38 38 43 44 44 47 52 52 54 54 55 57 59 59 59 61 62 62 62 63 65 66 66 66 69 70 71 72 73 75 77 77 79 79 80 80 81 86 88 90 91 92 93 94 94 96 100 102 104 104 106 106 109 112 112 113 114 116 118 122 123 123 126 126 129 130 130 132 134 135 135 135 1...
output:
646440 17281 12354 9193 9193 9008 7022 7058 6780 6698 7518 7518 7518 7518 7518 6678 6678 6313 6231 6151 5329 5338 4742 4347 4347 5292 5589 5589 5589 4900 4347
result:
ok 31 tokens
Test #20:
score: 0
Accepted
time: 676ms
memory: 38020kb
input:
994402 30 -1 -1 -6 -15 -17 -18 -20 -24 -25 -25 -26 -28 -29 -29 -30 -34 -38 -38 -43 -43 -43 -47 -47 -50 -52 -58 -60 -60 -62 -68 -68 -71 -74 -75 -77 -78 -79 -80 -81 -81 -85 -89 -89 -90 -91 -91 -99 -102 -104 -108 -114 -118 -120 -123 -124 -126 -128 -128 -129 -129 -129 -133 -134 -134 -136 -141 -148 -150 ...
output:
408192 14182 8665 8074 7546 6201 6002 6559 5594 5114 5114 5114 4555 4342 4342 4202 3784 3784 3784 4106 4405 4658 4112 4112 4112 3616 3657 4022 3657 3657 3818
result:
ok 31 tokens
Test #21:
score: 0
Accepted
time: 670ms
memory: 44636kb
input:
990077 30 1 2 2 4 7 8 8 14 15 16 16 19 20 22 25 29 33 37 37 41 42 43 43 48 50 53 54 57 58 60 63 66 69 71 71 74 78 78 79 88 88 91 94 97 99 102 102 106 107 113 113 122 127 130 136 136 139 140 141 141 143 146 147 150 154 155 158 162 163 164 164 165 166 169 169 172 177 178 180 180 181 185 187 187 193 19...
output:
503511 12866 12765 8066 8135 7593 7264 6398 6398 6257 5841 5335 5491 5577 4872 4652 4840 4652 4790 4840 4790 4790 4790 4520 4783 4783 4691 4792 4515 4515 4515
result:
ok 31 tokens
Test #22:
score: 0
Accepted
time: 730ms
memory: 23852kb
input:
998459 30 -402459 -700252 -559126 -239589 208150 44921 928337 -154107 -697689 88667 -484569 178563 331795 -135197 -351549 -601709 120383 497156 -183729 -647420 -213304 784994 842436 445932 -942721 -810839 975843 -920094 -490042 -909881 -897787 249158 98469 -130692 648148 -679770 95396 -239658 307821...
output:
3867 3867 3867 3867 3867 3656 3656 3925 3867 5356 3971 3971 3679 3667 3667 4108 4108 3590 3850 3761 3761 3974 3914 3625 3588 3588 3914 4039 3622 3622 3580
result:
ok 31 tokens
Test #23:
score: 0
Accepted
time: 721ms
memory: 23120kb
input:
992426 30 -634693 158188 -625064 558625 -644808 -972266 -616926 -929044 223892 -906359 565712 579148 -270789 590540 -438972 -255330 -945302 850684 122527 -535591 627036 -587178 676475 -756509 -479692 538212 790533 -725404 784041 722937 791185 -855348 451961 -480401 -239902 465172 -596236 790910 -106...
output:
3873 3873 3873 3698 3921 4014 3608 3608 3608 3608 3972 4121 4121 3591 3591 3591 3414 3786 3786 4020 3758 3758 3758 3758 3490 3534 3534 3326 3326 4194 4194
result:
ok 31 tokens
Test #24:
score: 0
Accepted
time: 680ms
memory: 36896kb
input:
990012 30 1 8 9 10 13 13 14 14 16 16 18 19 20 23 28 36 41 41 45 45 46 48 49 49 52 56 57 57 61 61 63 67 69 72 77 78 80 83 84 89 89 89 89 89 89 90 95 96 102 102 102 103 106 110 111 116 118 122 123 126 126 131 131 139 140 140 140 143 144 145 148 149 149 150 150 153 153 155 160 170 170 171 177 177 178 1...
output:
34499 14840 9509 8448 7743 7629 7187 6028 5847 5076 5060 5060 5955 5237 5027 4850 4778 4850 4850 4145 5072 4445 4445 3637 4254 4411 4411 4411 4675 3713 3713
result:
ok 31 tokens
Test #25:
score: 0
Accepted
time: 685ms
memory: 43400kb
input:
997112 30 2 4 6 9 9 9 10 14 18 19 24 28 30 32 32 34 37 37 44 60 64 66 67 71 71 73 75 76 77 78 79 80 82 82 84 84 84 94 95 97 99 105 106 108 111 111 113 117 117 118 122 123 123 125 125 127 128 129 131 132 132 133 133 134 135 136 138 140 143 145 145 149 149 150 152 156 160 163 165 166 169 170 173 183 1...
output:
488921 13266 11227 8100 8273 6980 6531 6604 6300 5630 5376 5297 5339 4998 5076 5120 5120 4911 4679 4452 4550 4550 4183 4136 4136 4136 4136 4163 4388 4163 3793
result:
ok 31 tokens
Test #26:
score: 0
Accepted
time: 739ms
memory: 24536kb
input:
992971 30 344603 -184013 -629959 841287 -497456 -347548 121465 466140 -410226 -951298 981942 844122 745787 -32336 -539878 -266192 -724997 -306229 129893 -498243 408760 -888518 -420037 -566841 -579899 -19137 -528442 -747290 -550811 262795 -327557 697973 -352510 164095 -123293 -467118 558697 916073 -9...
output:
3883 4111 3830 3620 3539 3749 3827 3827 3676 3676 3520 3520 3542 3520 3682 3520 4107 4107 3539 3598 3539 3539 4200 4219 3539 3632 3760 3689 3550 4019 4019
result:
ok 31 tokens
Test #27:
score: 0
Accepted
time: 706ms
memory: 43980kb
input:
996176 30 996176 996175 996174 996174 996173 996172 996171 996170 996166 996165 996158 996158 996157 996154 996154 996151 996148 996148 996147 996146 996141 996141 996138 996136 996134 996132 996130 996130 996130 996129 996127 996126 996124 996123 996120 996116 996116 996115 996113 996112 996111 996...
output:
255896 17612 10612 8061 8638 7543 6648 5730 5764 6124 5764 5764 5508 5344 5621 5436 5979 5979 5979 5895 5223 4673 6520 5522 5522 4849 4429 4429 4183 4291 4422
result:
ok 31 tokens
Test #28:
score: 0
Accepted
time: 698ms
memory: 38240kb
input:
993076 30 -2 -4 -7 -9 -9 -10 -12 -12 -14 -15 -15 -16 -17 -20 -21 -22 -23 -25 -26 -27 -30 -30 -30 -32 -32 -32 -34 -34 -36 -38 -39 -40 -40 -41 -41 -41 -42 -44 -44 -44 -44 -45 -45 -47 -48 -49 -49 -50 -53 -53 -53 -54 -55 -57 -71 -72 -73 -74 -74 -75 -78 -79 -81 -85 -86 -93 -94 -97 -100 -101 -105 -106 -11...
output:
368604 13029 8823 7917 6878 6590 5844 5844 5322 5277 5277 4454 4917 4535 4535 4574 4551 3862 3862 4422 3730 3572 3746 3746 3746 3466 3466 3466 3466 3466 3633
result:
ok 31 tokens
Test #29:
score: 0
Accepted
time: 701ms
memory: 42420kb
input:
999001 30 998998 998997 998995 998993 998982 998981 998977 998976 998973 998970 998970 998970 998965 998965 998962 998958 998954 998949 998947 998946 998945 998943 998939 998939 998937 998935 998934 998934 998934 998929 998927 998926 998926 998924 998923 998921 998921 998920 998920 998919 998917 998...
output:
502397 16758 10215 7538 7538 6574 6454 6454 6454 5827 6067 6258 6258 4899 4899 5801 5886 6069 6069 4907 5768 5768 5768 4599 4599 4888 4888 4669 4669 4597 4597
result:
ok 31 tokens
Test #30:
score: 0
Accepted
time: 693ms
memory: 37516kb
input:
993089 30 -1 -1 -7 -8 -10 -11 -13 -16 -16 -20 -24 -25 -26 -26 -27 -28 -30 -31 -32 -34 -37 -37 -39 -41 -41 -45 -46 -49 -49 -49 -54 -54 -55 -56 -58 -58 -60 -60 -63 -65 -67 -69 -76 -76 -77 -79 -84 -85 -87 -88 -88 -89 -90 -94 -94 993087 993083 993081 993080 993079 993077 993076 993074 993074 993072 9930...
output:
539443 11442 9478 7215 6752 7099 6246 5102 5102 4801 4801 4801 4609 4609 4609 4023 4230 4505 4306 4064 3876 3770 4162 4521 4521 4049 4049 4091 4091 4125 4125
result:
ok 31 tokens
Test #31:
score: 0
Accepted
time: 680ms
memory: 42880kb
input:
992329 30 4 4 8 10 10 12 14 18 20 23 23 26 28 31 33 33 34 34 34 34 43 50 51 51 52 54 54 55 58 61 63 63 64 66 68 69 71 74 77 79 80 80 80 82 83 84 85 90 91 95 97 98 99 99 100 100 108 108 109 115 119 122 122 132 133 135 136 137 137 141 147 148 148 150 151 151 152 153 157 164 164 168 169 173 176 176 178...
output:
529035 15567 12167 10317 10317 8009 7511 6401 7269 7320 5624 5728 6823 5560 5560 5850 4906 5272 6640 5735 5348 4632 5140 4597 4597 4273 4597 4597 4597 4597 4423
result:
ok 31 tokens