QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#300240 | #7630. Yet Another Maximize Permutation Subarrays | li4m | AC ✓ | 299ms | 46304kb | C++17 | 2.8kb | 2024-01-07 21:40:13 | 2024-01-07 21:40:13 |
Judging History
answer
//ts
#include <bits/stdc++.h>
//The quick brown fox jumps over the lazy dog//
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define ashar(x) setprecision(x)
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define TXT freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define int ll
const int inf = 1e9;
const int maxn = 1000010;
int n, t;
int a[maxn], ind[maxn];
int sum, mx1, mx2, mn1, mn2, ans, f, s;
int psum[maxn];
bool mark[maxn];
map <pii, int> cnt;
int jam(int s, int e)
{
return (s + e) * ( e - s + 1 ) / 2;
}
void add(int i, int j)
{
if(i < j)
swap(i, j);
//cout << "@ " << a[i] << " " << a[j] << "\n";
cnt[{a[i], a[j]}] ++;
}
int ffpos(int sum, int del, int s, int e)
{
sum -= del;
return jam(s, e) - sum;
}
int32_t main()
{
fast_io
cin >> t;
while(t--)
{
cin >> n;
cnt.clear();
mx1 = mx2 = 0;
mn1 = mn2 = inf;
f = s = ans = sum = 0;
for(int i = 1; i <= n; i++ )
{
cin >> a[i];
ind[a[i]] = i;
mark[i] = 0;
}
for(int i = 1; i <= n; i++)
{
//cout << " ################### " << i << "\n";
int pos = ind[i];
sum += pos;
if(pos > mx1)
{
mx2 = mx1;
mx1 = pos;
}
else if(pos > mx2) mx2 = pos;
if(pos < mn1)
{
mn2 = mn1;
mn1 = pos;
}
else if(pos < mn2) mn2 = pos;
if(i == 1) continue;
if(mx1 - mn1 + 1 == i){
mark[i] = 1;
if(mx1 < n) add(mn1, mx1 + 1);
if(mn1 > 1) add(mn1 - 1, mx1);
}
if(mx2 - mn1 + 1 == i)
{
int p = ffpos(sum, mx1, mn1, mx2);
add(mx1, p);
}
if(mx2 - mn1 + 1 == (i - 1) and mx1 != mx2 + 1)
{
add(mx1, mx2 + 1);
if(mn1 > 1)
add(mx1, mn1 - 1);
}
if(mx1 - mn2 + 1== i)
{
int p = ffpos(sum, mn1, mn2, mx1);
add(mn1, p);
}
if(mx1 - mn2 + 1 == (i - 1) and mn1 != mn2 - 1)
{
// cout <<"ii" << i <<" " << mn1 <<" " << mn2 <<" " << mx1 <<" " << mx2 <<"\n";
add(mn1, mn2 - 1);
if(mx1 < n)
add(mn1, mx1 + 1);
}
// cout <<"i: " << i << " mn1 " << mn1 << " mn2 " << mn2 << " mx1 " << mx1 << " mx2 " << mx2 << " " << cnt[{2, 1}] << endl;
}
mark[1] = 0;
for(int i = 1; i <= n; i++)
{
// cout << " $ " << i << " " << mark[i] << "\n";
psum[i] = mark[i] + psum[i - 1];
}
for(auto i: cnt)
{
int a = i.F.F;
int b = i.F.S;
if(b > a) swap(a, b);
int good = psum[a - 1] - psum[b - 1];
int res = i.S - good;
//cout << " ~ " << a << " " << b << " " << res << " " << i.S << " " << good << "\n";
if(res > ans)
{
f = ind[b];
s = ind[a];
ans = res;
}
}
if(!f)
cout <<"1 1\n";
else
cout << f << " " << s << endl;
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7728kb
input:
8 3 1 2 3 3 1 3 2 5 1 3 2 5 4 6 4 5 6 1 2 3 9 8 7 6 3 2 1 4 5 9 10 7 10 5 1 9 8 3 2 6 4 10 8 5 10 9 2 1 3 4 6 7 10 2 3 5 7 10 1 8 6 4 9
output:
1 1 3 2 1 4 1 3 1 1 4 9 2 4 1 5
result:
ok 8 cases
Test #2:
score: 0
Accepted
time: 0ms
memory: 7696kb
input:
10 9 6 2 8 3 4 5 7 1 9 17 15 10 11 9 4 5 17 1 2 7 6 8 14 12 13 16 3 19 5 10 12 11 14 6 15 19 2 18 8 1 16 13 7 4 3 17 9 18 5 8 10 6 4 7 9 2 11 3 18 1 13 17 12 14 16 15 2 1 2 8 8 7 6 5 4 1 3 2 9 1 2 3 4 9 7 5 8 6 11 1 11 3 4 2 9 7 6 8 10 5 6 1 6 5 2 3 4 11 7 8 10 1 9 11 4 2 3 5 6
output:
8 3 17 7 12 10 12 9 1 1 8 7 9 5 5 2 1 3 4 6
result:
ok 10 cases
Test #3:
score: 0
Accepted
time: 0ms
memory: 7728kb
input:
10 18 10 13 12 1 2 3 4 5 6 8 9 7 17 11 15 14 16 18 8 3 1 4 2 6 5 8 7 12 10 9 1 7 6 5 3 2 8 4 11 12 15 15 14 12 13 10 5 9 7 8 6 1 2 3 4 11 6 5 4 3 2 1 6 14 13 3 4 2 10 5 8 1 7 12 9 11 6 14 1 1 1 1 5 5 2 1 4 3 17 1 8 9 7 10 6 2 5 4 3 11 17 13 15 16 14 12
output:
1 13 4 3 3 9 6 9 1 1 8 5 1 1 1 1 5 4 1 5
result:
ok 10 cases
Test #4:
score: 0
Accepted
time: 1ms
memory: 7720kb
input:
9 4 4 2 3 1 5 5 2 3 1 4 8 7 8 6 5 3 2 1 4 17 15 16 13 12 14 1 3 4 2 5 6 7 9 11 10 8 17 2 1 2 17 16 14 11 8 5 4 3 15 2 6 7 9 10 12 13 1 17 8 1 5 6 7 2 3 4 8 15 10 7 13 2 8 4 1 15 6 5 11 14 3 12 9 7 2 4 3 1 5 6 7
output:
4 3 4 3 1 2 16 5 1 1 16 8 1 4 7 5 4 2
result:
ok 9 cases
Test #5:
score: 0
Accepted
time: 1ms
memory: 7740kb
input:
9 80 78 77 73 72 69 70 66 64 62 63 61 60 58 57 56 54 53 55 50 51 49 43 44 38 36 35 34 33 27 25 24 26 19 17 14 16 15 9 1 5 2 3 4 6 8 7 10 11 12 13 18 20 21 22 23 28 31 30 29 32 37 41 42 39 40 45 46 47 48 52 59 68 65 67 71 75 74 76 79 80 52 49 48 35 31 30 32 27 25 1 23 22 21 17 15 16 14 13 12 9 10 11 ...
output:
39 40 9 28 61 65 2 11 135 4 149 92 1 66 12 32 63 51
result:
ok 9 cases
Test #6:
score: 0
Accepted
time: 1ms
memory: 7744kb
input:
8 151 150 151 149 148 129 131 130 125 126 124 128 127 123 119 115 117 122 121 116 120 118 111 112 113 110 109 108 107 105 106 103 104 102 100 98 101 99 97 96 95 80 79 72 73 71 68 69 70 56 51 47 50 48 49 46 33 35 27 34 31 30 29 32 26 28 25 24 23 22 21 20 17 19 18 16 11 12 7 5 6 1 4 3 2 10 8 9 14 13 1...
output:
58 63 12 2 10 4 1 32 85 37 4 12 163 70 170 86
result:
ok 8 cases
Test #7:
score: 0
Accepted
time: 1ms
memory: 7800kb
input:
7 144 144 143 142 141 139 137 138 136 135 133 131 130 129 127 125 120 119 116 117 109 108 107 105 104 103 80 99 100 98 95 92 91 89 88 85 81 101 79 73 72 64 63 61 59 60 58 57 56 52 51 50 45 43 44 42 41 36 34 32 33 31 30 29 27 26 21 22 20 19 13 12 11 9 5 4 3 2 1 6 7 8 10 16 17 15 14 18 24 23 25 28 35 ...
output:
26 37 22 19 141 53 40 96 75 71 101 29 19 18
result:
ok 7 cases
Test #8:
score: 0
Accepted
time: 1ms
memory: 7720kb
input:
8 487 487 486 485 484 481 480 479 477 475 472 473 469 465 464 463 458 453 452 451 450 448 449 446 435 434 433 432 431 430 429 428 427 426 419 418 414 413 408 406 405 396 390 391 389 384 386 385 382 381 380 379 376 374 375 373 372 370 371 369 368 366 367 360 359 357 356 355 354 353 351 349 350 345 34...
output:
413 365 976 125 936 806 73 490 794 324 498 381 59 609 1097 19
result:
ok 8 cases
Test #9:
score: 0
Accepted
time: 2ms
memory: 7784kb
input:
8 403 402 400 399 398 394 393 395 396 391 390 389 388 387 386 385 384 383 376 373 372 371 370 366 368 369 367 364 360 361 359 355 356 352 351 350 349 341 340 338 339 336 335 327 326 325 324 319 318 317 315 314 313 311 308 310 309 307 306 305 304 299 302 300 301 296 293 290 288 289 287 286 285 284 28...
output:
245 218 228 282 2 1464 565 482 289 213 100 596 224 747 199 1465
result:
ok 8 cases
Test #10:
score: 0
Accepted
time: 2ms
memory: 7808kb
input:
9 464 427 67 114 302 21 32 268 339 309 366 432 286 88 10 347 290 353 248 249 261 360 9 284 191 405 17 464 110 341 349 188 49 33 235 451 100 81 95 410 457 355 62 381 266 37 351 189 402 107 263 184 246 350 94 186 438 93 233 279 441 158 140 379 417 55 156 439 342 278 320 13 435 142 265 270 36 173 218 7...
output:
388 384 1473 736 850 699 568 515 208 63 530 397 399 343 433 725 19 200
result:
ok 9 cases
Test #11:
score: 0
Accepted
time: 12ms
memory: 9580kb
input:
7 2236 2234 2235 2236 2222 2221 2220 2219 2212 2213 2208 2209 2206 2205 2207 2197 2196 2194 2193 2192 2195 2191 2189 2188 2190 2180 2181 2175 2176 2177 2179 2178 2171 2168 2166 2165 2170 2167 2164 2169 2155 2154 2153 2152 2151 2129 2125 2126 2123 2120 2122 2121 2119 2117 2114 2115 2107 2106 2105 210...
output:
1939 1500 14094 9639 16385 15053 105 709 14867 11301 12653 1909 1596 8769
result:
ok 7 cases
Test #12:
score: 0
Accepted
time: 12ms
memory: 9268kb
input:
9 14132 14128 14132 14131 14129 14130 14126 14117 14115 14114 14111 14110 14112 14108 14105 14104 14103 14102 14101 14100 14091 14093 14092 14090 14088 14082 14083 14081 14077 14075 14073 14072 14074 14071 14068 14067 14060 14059 14058 14057 14056 14055 14053 14052 14051 14043 14042 14038 14034 1403...
output:
2533 2905 14624 12074 6106 5335 1000 704 4140 1216 9473 1308 87 54 2160 5749 1647 1432
result:
ok 9 cases
Test #13:
score: 0
Accepted
time: 10ms
memory: 8880kb
input:
9 11668 122 3358 10900 8761 11606 6985 11355 6706 11563 3705 7295 627 11650 6491 8905 8408 1648 3401 4976 9571 8524 2075 10416 9513 3700 3565 4160 5098 8140 909 3951 11517 7913 9256 10863 3141 5284 5805 784 4403 3751 8015 10058 6313 3547 8244 726 719 9645 9538 8839 10802 681 4118 9712 8591 4722 6306...
output:
216 209 16303 357 11147 10575 1503 2840 5651 5422 472 313 9799 9101 535 6035 2792 1766
result:
ok 9 cases
Test #14:
score: 0
Accepted
time: 89ms
memory: 28480kb
input:
7 193626 193626 193625 193622 193621 193624 193623 193620 193617 193618 193619 193605 193606 193587 193578 193575 193574 193555 193563 193558 193561 193566 193554 193571 193570 193556 193567 193557 193560 193562 193559 193568 193553 193569 193565 193564 193573 193572 193550 193549 193547 193548 1935...
output:
139831 82765 116795 58002 6379 14664 36836 35585 30649 10542 38850 24113 490 1448
result:
ok 7 cases
Test #15:
score: 0
Accepted
time: 120ms
memory: 20364kb
input:
10 55747 55745 55744 55737 55734 55731 55729 55726 55724 55723 55725 55721 55720 55719 55718 55715 55713 55706 55705 55702 55701 55697 55695 55694 55692 55690 55687 55686 55685 55683 55681 55682 55680 55678 55669 55667 55666 55662 55654 55653 55649 55648 55645 55644 55643 55642 55641 55628 55627 556...
output:
25048 28220 85833 49749 167132 41617 11329 5147 331 1530 5963 53264 3056 30379 133195 126366 6947 31910 92794 90122
result:
ok 10 cases
Test #16:
score: 0
Accepted
time: 111ms
memory: 33308kb
input:
8 161886 161886 161884 161883 161881 161880 161877 161874 161873 161871 161872 161869 161868 161866 161865 161862 161858 161856 161855 161852 161851 161845 161846 161841 161839 161837 161836 161834 161833 161830 161828 161826 161820 161819 161821 161818 161817 161815 161810 161809 161807 161803 1618...
output:
14047 145753 66627 48604 48450 15192 48992 35562 54651 54249 33403 41987 82807 78930 39152 5621
result:
ok 8 cases
Test #17:
score: 0
Accepted
time: 299ms
memory: 46268kb
input:
8 477214 477214 477209 477208 477207 477206 477204 477205 477199 477198 477200 477196 477192 477193 477189 477190 477188 477185 477184 477182 477181 477180 477174 477173 477172 477171 477170 477163 477164 477162 477157 477158 477156 477155 477154 477151 477145 477146 477134 477135 477133 477132 4771...
output:
69720 198310 151 10152 139375 127265 402556 101073 198298 175992 142366 129760 5990 14234 368817 191453
result:
ok 8 cases
Test #18:
score: 0
Accepted
time: 210ms
memory: 37976kb
input:
7 104640 80979 94896 93379 84998 101575 69108 32621 13413 19543 63751 74406 100342 91227 41571 7722 15382 88496 71052 98146 91567 98194 76721 20313 26614 79982 69719 85888 82373 104512 10114 34784 77042 99044 54249 83799 63420 72841 67390 96124 80151 102095 44828 82307 74818 58750 94133 63179 74514 ...
output:
40810 37999 46196 108910 108875 85667 11560 27356 36269 25502 334416 218547 31523 85710
result:
ok 7 cases
Test #19:
score: 0
Accepted
time: 156ms
memory: 46304kb
input:
7 3719 3719 3718 3715 3712 3710 3711 3701 3700 3698 3696 3692 3690 3687 3686 3683 3682 3681 3678 3677 3676 3675 3673 3674 3670 3669 3664 3663 3661 3660 3658 3659 3655 3654 3651 3650 3643 3641 3635 3634 3633 3631 3632 3630 3628 3629 3627 3626 3624 3622 3618 3617 3614 3611 3610 3606 3605 3604 3599 359...
output:
3633 2315 40408 38220 21572 11209 115100 70030 216701 207417 150862 161659 58611 264533
result:
ok 7 cases
Extra Test:
score: 0
Extra Test Passed