QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#760683#4629. Longest Increasing Subsequenceswt2009AC ✓21ms57972kbC++142.0kb2024-11-18 18:23:082024-11-18 18:23:08

Judging History

你现在查看的是最新测评结果

  • [2024-11-18 18:23:08]
  • 评测
  • 测评结果:AC
  • 用时:21ms
  • 内存:57972kb
  • [2024-11-18 18:23:08]
  • 提交

answer

//#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
using namespace std;  

#define int long long
#define pii pair<int,int>
#define mkp make_pair
#define fi first
#define se second
#define pb push_back
#define lowbit(x) ((x)&(-x))

//#define ppc __builtin_popcount

#define lc(p) ((p)<<1)
#define rc(p) ((p)<<1|1)

#define sqr(x) ((x)*(x))

// #define mod 1000000007
// #define mod 998244353
#define eps 1e-10

//#define debug cout<<__LINE__<<" "<<__FUNCTION__<<"\n";
#define spa putchar(' ')
#define ero putchar('\n')

// mt19937 rnd(time(0));

const int N=1e5+10,inf=1e18;

inline int read(){
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
inline void write(int x){
	if(!x)putchar('0');
	if(x<0)x=-x,putchar('-');
	int cnt=0,a[30];
	while(x)a[++cnt]=x%10,x/=10;
	while(cnt--)putchar(a[cnt+1]+'0');
}

int f[N][70],a[N];

void solve(){
    int n=read();
    for(int i=1;i<=n;i++){
        a[i]=read();
    }
    for(int i=0;i<=64;i++){
        f[1][i]=1;
    }
    for(int i=2;i<=n;i++){
        int b=a[i]-a[i-1]; // 差
        int s=log2(b); // 层数
        if(!s){
            f[i][0]=f[i-1][0]+1;
        }
        else{
			for(int j=0;j<s;j++){
				f[i][j]=f[i-1][j]+(1ll<<j);
			}
			int res1=b-(1ll<<s); // 本层?
            int res2=1ll<<s-1; // 倒数第二层?
			f[i][s]=max(f[i-1][s]+res1,f[i-1][s-1]+max(res1,res2)+(res1>0));
        }
        for(int j=0;j<=61;j++){
			f[i][j]=max(f[i][j],f[i-1][j]); // 接上一棵树
			if(j){
                f[i][j]=max(f[i][j],f[i][j-1]); // 本树的上一层
            }
		}
    }
    write(f[n][61]);
}

signed main(){
	// freopen("lis.in","r",stdin);
	// freopen("lis.out","w",stdout);
	// ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); 
    // int T=read();
    int T=1;
    while(T--){
        solve();
    }
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3708kb

input:

7
7 41 53 58 75 78 81

output:

22

result:

ok single line: '22'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3728kb

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: 3752kb

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: 3824kb

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: 1ms
memory: 5752kb

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: 1ms
memory: 5764kb

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: 9792kb

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: 0ms
memory: 6500kb

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: 15ms
memory: 42628kb

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: 15ms
memory: 50408kb

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: 11ms
memory: 35492kb

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: 20ms
memory: 57972kb

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: 0
Accepted
time: 21ms
memory: 46444kb

input:

76982
14476501276935 40866525949868 66555792410468 69507797922882 106458420792387 110338205221337 113336076813949 117869582468158 130615980003958 141529043435293 146117123162115 150895009736134 194825823350671 218631219579044 224659299340674 232612532608952 247899161437231 248986641631227 2495988618...

output:

250375725659674641

result:

ok single line: '250375725659674641'