QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#116729 | #4629. Longest Increasing Subsequence | kshitij_sodani | WA | 2ms | 9632kb | C++14 | 2.7kb | 2023-06-29 23:10:00 | 2023-06-29 23:10:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
typedef long long llo;
#define endl '\n'
llo n;
llo it[100001];
llo val[100001][62];
llo dp[100001][61];
llo zz3[100001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for(llo i=0;i<n;i++){
cin>>it[i];
}
val[0][0]=1;
for(llo i=1;i<n;i++){
val[i][0]=1;
pair<llo,llo> cur={it[i]-it[i-1],1};
pair<llo,llo> cur2={it[i]-it[i-1],0};
llo su=0;
for(llo j=1;j<=60;j++){
su+=val[i][j-1];
pair<llo,llo> zz={(it[i]-it[i-1])/(1LL<<j),0};
pair<llo,llo> zz2={(it[i]-it[i-1]+(1LL<<j)-1)/(1LL<<j),0};
if(zz2.a==0){
break;
}
if(cur.a>1){
if(cur.a%2==0){
if((cur.a/2)==zz.a){
zz.b+=cur.b*2;
}
else{
zz2.b+=(cur.b*2);
}
}
else{
zz.b+=cur.b;
zz2.b+=cur.b;
}
}
else{
}
if(cur2.a>1){
if(cur2.a%2==0){
if((cur2.a/2)==zz.a){
zz.b+=cur2.b*2;
}
else{
zz2.b+=(cur2.b*2);
}
}
else{
zz.b+=cur2.b;
zz2.b+=cur2.b;
}
}
if(zz.a==0 and zz2.a==0){
val[i][j]=0;
break;
}
else if(zz.a==0 and zz2.a==1){
if(cur.b>cur2.b){
zz3[i]=cur.b-cur2.b;
}
val[i][j]=cur.b+zz2.b-su;
}
else{
val[i][j]=zz.b+zz2.b-su;
}
if(val[i][j]<0){
val[i][j]=0;
}
cur=zz;
cur2=zz2;
/*if(val[i][j]>0){
cout<<i<<":"<<j<<":"<<val[i][j]<<endl;
}*/
}
}
//cout<<val[2][5]<<",,"<<endl;
for(llo i=0;i<=60;i++){
dp[0][i]=1;
}
for(llo i=1;i<n;i++){
for(llo j=0;j<=60;j++){
dp[i][j]=dp[i-1][j]+val[i][j];
/*if(val[i][j]>0 and i==2){
cout<<j<<":"<<val[i][j]<<endl;
}*/
if(val[i][j]>0 and val[i][j+1]==0){
llo xx=(it[i]-it[i-1])&(it[i]-it[i-1]-1);
//cout<<(it[i]-it[i-1])<<":"<<(it[i]-it[i-1]-1)<<":"<<xx<<endl;
if(xx!=0){
llo cot=it[i]-it[i-1];
llo zot=0;
//cout<<i<<":"<<j<<",,"<<endl;
for(int jj=0;jj<j-1;jj++){
//cout<<cot<<endl;
if(((cot/2)&((cot/2)-1))==0){
if((cot/2)==1){
zot+=1;
}
else{
zot+=(cot/4);
}
//zot+=((cot)/4);
cot=(cot+1)/2;
/*if(jj==j-2){
if((cot&(cot-1))==0){
zot+=((cot)/2);
}
}*/
}
else{
cot/=2;
}
}
//cout<<zot<<"?"<<endl;
dp[i][j]=max(dp[i][j],dp[i-1][j-1]+zot+val[i][j]);
}
// dp[i-1][j]=max(dp[i-1])
}
}
for(llo j=1;j<=60;j++){
dp[i][j]=max(dp[i][j],dp[i][j-1]);
}
}
cout<<dp[n-1][60]<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9632kb
input:
7 7 41 53 58 75 78 81
output:
22
result:
ok single line: '22'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5404kb
input:
8 174 223 259 368 618 738 893 1810
output:
669
result:
wrong answer 1st lines differ - expected: '671', found: '669'