QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#358739#4629. Longest Increasing SubsequenceKevin5307WA 1ms5880kbC++201.9kb2024-03-19 23:28:302024-03-19 23:28:31

Judging History

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

  • [2024-03-19 23:28:31]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5880kb
  • [2024-03-19 23:28:30]
  • 提交

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];
array<ll,3> calc(ll len,int d)
{
	if(len==1) return {0,0,0};
	if(len==2)
	{
		if(d) return {1,1,1};
		return {1,1,0};
	}
	if(len==3)
		return {1,2,1};
	array<ll,3> a1=calc(len/2,d-1),a2=calc(len-len/2,d-1);
	return {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];
	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
				{
					dp[i][j]=max(dp[i][j],dp[i+1][j]+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: 0ms
memory: 5636kb

input:

7
7 41 53 58 75 78 81

output:

22

result:

ok single line: '22'

Test #2:

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

input:

8
174 223 259 368 618 738 893 1810

output:

671

result:

ok single line: '671'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3540kb

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

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: -100
Wrong Answer
time: 1ms
memory: 5880kb

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:

25015

result:

wrong answer 1st lines differ - expected: '25026', found: '25015'