QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#760678#4629. Longest Increasing Subsequenceswt2009RE 0ms0kbC++142.0kb2024-11-18 18:20:362024-11-18 18:20:37

Judging History

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

  • [2024-11-18 18:20:37]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-18 18:20:36]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

7
7 41 53 58 75 78 81

output:


result: