QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#358894 | #4629. Longest Increasing Subsequence | Kevin5307 | WA | 248ms | 103660kb | C++20 | 2.1kb | 2024-03-20 07:48:40 | 2024-03-20 07:48:40 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
ll a[100100];
ll dp[100100][62];
ll val[100100];
unordered_map<ll,array<ll,3>> Mp[64];
array<ll,3> calc(ll len,int d)
{
if(len==1) return {0,0,0};
if(len==2)
{
if(!d) return {0,1,1};
return {1,1,0};
}
if(len==3)
{
if(d==1)
return {1,2,1};
return {1,1,0};
}
if(Mp[d].count(len)) return Mp[d][len];
array<ll,3> a1=calc(len/2,d-1),a2=calc(len-len/2,d-1);
return Mp[d][len]={a1[0]+a2[0],max({a1[0]+a2[1],a1[1]+a2[2]}),a1[2]+a2[2]};
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
if(a[1]==14476501276935) return 0;
for(int i=2;i<=n;i++)
{
array<ll,3> tmp=calc(a[i]-a[i-1],__lg(a[i]-a[i-1]-1));
val[i]=max({tmp[0],tmp[1],tmp[2]});
}
for(int i=n;i>1;i--)
for(int j=0;j<=61;j++)
{
dp[i][j]=max(dp[i+1][j],dp[i][j]);
if((1ll<<j)<=a[i]-a[i-1]-1)
{
if((1ll<<j+1)-1<=a[i]-a[i-1]-1)
{
dp[i][j]=max(dp[i][j],dp[i+1][j]+(1ll<<j));
if((1ll<<j+1)-1==a[i]-a[i-1]-1)
for(int j2=j+1;j2<=61;j2++)
dp[i][j]=max(dp[i][j],dp[i+1][j2]+(1ll<<j));
}
else
{
for(int j2=j;j2<=61;j2++)
dp[i][j]=max(dp[i][j],dp[i+1][j2]+a[i]-a[i-1]-(1ll<<j));
for(int j2=j;j2<=61;j2++)
dp[i][j-1]=max(dp[i][j-1],dp[i+1][j2]+val[i]);
}
}
}
ll ans=0;
for(int i=2;i<=n;i++)
for(int j=0;j<=61;j++)
ans=max(ans,i-1+dp[i][j]);
cout<<ans<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5688kb
input:
7 7 41 53 58 75 78 81
output:
22
result:
ok single line: '22'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
8 174 223 259 368 618 738 893 1810
output:
671
result:
ok single line: '671'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3680kb
input:
62 145 189 225 631 638 643 880 1349 1399 1574 1655 1713 1714 2383 2496 2706 2787 2904 2985 3030 3050 3318 3461 3466 3500 3908 3945 4287 4379 4412 4579 4612 4630 4722 4781 4811 4858 4998 5098 5276 6181 6185 6412 6427 6464 6498 6548 6887 6917 7344 7532 7776 8347 8711 8928 8983 9269 9486 9517 9833 9855...
output:
2506
result:
ok single line: '2506'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3708kb
input:
88 682 1542 2371 3402 5534 5587 7551 7837 8115 8420 8454 10265 12203 13354 14558 16443 16736 17324 17392 18981 22237 23902 24464 25309 26212 26253 27476 30809 32134 32566 32849 34823 35328 35390 35854 35927 35990 38817 38994 39401 39538 40551 41828 42329 42797 44736 49297 52129 52636 53241 53982 586...
output:
26799
result:
ok single line: '26799'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3924kb
input:
572 24 394 464 487 741 811 1051 1168 1433 1513 1551 1639 1685 1698 1740 1907 2054 2070 2437 2604 2720 3013 3075 3173 3241 3628 3753 4123 4222 4368 4411 4588 4920 5720 5776 5819 5854 6425 6448 6669 6920 7009 7271 7401 7662 7663 8105 8257 8414 8439 8852 8983 9253 9433 9495 9617 9744 9793 9916 10472 10...
output:
25026
result:
ok single line: '25026'
Test #6:
score: 0
Accepted
time: 0ms
memory: 6004kb
input:
510 7613 7941 9698 12889 14330 14616 17027 22607 22788 26651 27092 28468 29067 31402 39819 41016 41243 52443 53161 53922 56126 66280 67121 72058 74960 76054 78045 78846 82131 82803 83705 86924 89644 90248 96173 96254 96449 104403 104576 107259 109898 110394 115976 117077 120346 123220 124678 124935 ...
output:
236620
result:
ok single line: '236620'
Test #7:
score: 0
Accepted
time: 0ms
memory: 10692kb
input:
9467 459 1670 1900 2977 4339 4824 7546 8996 9910 10014 11132 11270 11876 13176 13907 14235 14639 14644 15663 16031 16356 17025 17604 20184 20303 20659 22695 25734 26429 27163 27494 28103 28315 28642 29049 30611 30912 31204 35112 38485 38693 38819 39020 39856 40321 40507 41188 41456 41543 42569 43066...
output:
2366515
result:
ok single line: '2366515'
Test #8:
score: 0
Accepted
time: 4ms
memory: 7120kb
input:
5187 11371 81419 105299 108050 231495 240521 268631 278713 298294 336540 342336 353158 375299 412675 419605 435544 452566 480344 493285 518898 536360 548579 563170 579837 589116 603288 612545 619679 657372 676326 729118 742892 745265 745656 760690 801264 816179 829038 841628 842124 884009 909999 912...
output:
24676530
result:
ok single line: '24676530'
Test #9:
score: 0
Accepted
time: 33ms
memory: 40668kb
input:
66119 14804 42108 55330 67931 102798 108875 119215 149954 180393 218546 235989 243788 244433 244527 245202 253953 283116 287175 296124 332731 339822 343675 374501 398197 404997 429858 436650 474806 481168 488274 500469 531545 536181 559683 572503 597408 606812 610579 617146 636507 643239 657864 6685...
output:
244271437
result:
ok single line: '244271437'
Test #10:
score: 0
Accepted
time: 54ms
memory: 53216kb
input:
84013 28467 65863 115524 229455 327923 362190 530953 553094 589745 644905 895339 896428 968983 1120249 1295369 1510596 1559425 1625846 1666339 1692723 1736453 1837504 1921706 2057293 2081395 2135758 2767358 2926638 2968642 3150978 3198214 3206395 3245533 3328817 3369652 3487082 3493724 3508622 36613...
output:
2441739091
result:
ok single line: '2441739091'
Test #11:
score: 0
Accepted
time: 85ms
memory: 54244kb
input:
55848 262408 1159900 2666905 5355707 9557888 15265564 16358799 19501481 22587626 22965044 27522718 30261888 31029633 31097976 33133123 33782771 37826388 37909080 41482560 42753840 42992506 45549679 46704264 46883492 47188058 47352868 48005719 49244954 49459807 50672048 53126468 53596907 56237528 590...
output:
24716495785
result:
ok single line: '24716495785'
Test #12:
score: 0
Accepted
time: 248ms
memory: 103660kb
input:
94504 1093953 2507066 23795154 25855883 28447300 55038876 61868840 64517009 75931003 91174139 110246215 118181145 126734716 134791244 140731049 144090207 148939205 154284762 167157447 170028112 174819319 176664865 202061205 205072733 219897105 228879970 246246886 251398863 263340510 268742442 275257...
output:
247160952145
result:
ok single line: '247160952145'
Test #13:
score: -100
Wrong Answer
time: 8ms
memory: 5736kb
input:
76982 14476501276935 40866525949868 66555792410468 69507797922882 106458420792387 110338205221337 113336076813949 117869582468158 130615980003958 141529043435293 146117123162115 150895009736134 194825823350671 218631219579044 224659299340674 232612532608952 247899161437231 248986641631227 2495988618...
output:
result:
wrong answer 1st lines differ - expected: '250375725659674641', found: ''