QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#430318 | #8087. Dedenne | grass8cow | AC ✓ | 423ms | 4104kb | C++17 | 1.6kb | 2024-06-03 17:52:02 | 2024-06-03 17:52:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll I=1e18,N=1e15;
void ad(ll &x,ll y){x=min(x,y);}
ll f[110],c[110];
ll n=100;
int m;
struct qb{ll x,b,k;}e[100100];
ll C(ll x){
ll su=0;
for(int i=0;(1ll<<i)<=x;i++)
su+=(min(x,(1ll<<(i+1))-1)-(1ll<<i)+1)*(i+1);
return su;
}
bool bj;
ll F(ll x){
int l=1,r=m,jx=-1;
while(l<=r){
int mi=(l+r)>>1;
if(e[mi].x<=x)jx=mi,l=mi+1;
else r=mi-1;
}
return e[jx].b+(x-e[jx].x)*e[jx].k;
}
ll F_(ll x){
ll l=2,r=x-1,ox=1;
while(l<=r){
ll mi=(l+r)>>1,m_=mi-1;
ll t_=F(m_)+F(x-m_)+C(m_),t=F(mi)+F(x-mi)+C(mi);
if(t_>t)ox=mi,l=mi+1;
else r=mi-1;
}
return F(ox)+F(x-ox)+C(ox)+C(x);
}
int main(){
f[0]=0,f[1]=c[1]=1;
m=1,e[1]=(qb){0,0,1};
for(int i=2;i<=n;i++){
f[i]=I;c[i]=c[i-1]+1+((int)log2(i));
for(int j=1;j<i;j++)if(f[i]>=f[j]+f[i-j]+c[j])
f[i]=f[j]+f[i-j]+c[j];
if(f[i]>f[i-1]+1)f[i]=f[i-1]+1;
f[i]+=c[i];
if(f[i]-f[i-1]!=f[i-1]-f[i-2])e[++m]=(qb){i-1,f[i-1],f[i]-f[i-1]};
}
while(e[m].x<N){
ll l=e[m].x+1,r=N,wh=N+1;
while(l<=r){
ll mi=(l+r)>>1;
if(F_(mi)>e[m].b+(mi-e[m].x)*e[m].k)wh=mi,r=mi-1;
else l=mi+1;
}
if(wh==N+1)break;
ll ct=F_(wh),f0=e[m].b+(wh-1-e[m].x)*e[m].k;
e[++m]=(qb){wh-1,f0,ct-f0};
}
int T;scanf("%d",&T);while(T--){
scanf("%lld",&n);bj=1;
printf("%lld\n",F(n));
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 412ms
memory: 3980kb
input:
3 2 4 10
output:
5 20 98
result:
ok 3 number(s): "5 20 98"
Test #2:
score: 0
Accepted
time: 414ms
memory: 4036kb
input:
50000 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...
output:
5 11 20 30 41 53 67 82 98 114 131 149 167 186 206 227 248 270 293 316 339 363 387 412 437 462 488 514 540 567 595 623 652 681 710 739 769 799 830 861 892 923 955 987 1019 1051 1083 1116 1149 1183 1217 1251 1285 1319 1354 1389 1424 1459 1494 1529 1565 1601 1638 1675 1712 1750 1788 1826 1864 1902 1940...
result:
ok 50000 numbers
Test #3:
score: 0
Accepted
time: 423ms
memory: 4044kb
input:
44644 6435807548 1566269317562 80032 8796093022206 866975236 133081413 31731462 93596222 724 77043136571 1827564952 7142275747603 177833563899817 2230487 3812375940 42154 1082718908933 109468445827189 154345 190937 3038279 191477576 71714255783600 719208629 948372457248532 7397628 118302 46607351595...
output:
4726565959549 1789801113084272 14354400 11343209351918880 527103900888 66626611101 13507662933 45085386028 44143 69928416797517 1194479180990 9080749315166700 278647456955472379 676066149 2669456822864 6715599 1204421903682018 166427605549492857 31047913 39811389 961055799 99701760883 10615521937784...
result:
ok 44644 numbers
Test #4:
score: 0
Accepted
time: 422ms
memory: 4104kb
input:
50000 266113 958250975553374 12447568646 12608206092 18432295756342 14843103600 66 773 39699 1110200608573 4194830913 39077116 15264090531101 222735641098011 9064 433220326 666 159 1231497858140 121 6609346830 442421917 194 21860729512 24895 27 218495 1194 49983281 6 34963306935 79424824708851 105 1...
output:
58593094 1661675060292477195 9692354708922 9828446123976 24981334316867684 11735833866268 1712 48063 6252821 1237257192009372 2963086447466 17046069344 20429538776875822 353875002743674754 1054069 245648588418 39590 5862 1382891331647021 4019 4865630505710 251405168889 7693 17869930763344 3579648 46...
result:
ok 50000 numbers
Test #5:
score: 0
Accepted
time: 411ms
memory: 4024kb
input:
1 1000000000000000
output:
1738413860843500846
result:
ok 1 number(s): "1738413860843500846"
Test #6:
score: 0
Accepted
time: 418ms
memory: 4040kb
input:
50000 430056375982 120251419455 28 325679 7859323378 85910912887197 106287244917583 451 1148 1382187975 21 27704323631 29 382067026721892 30497 119819946880636 369049233 400023 1859 96334 7874817209713 455478040494117 124525 8316230479 17789351251 4 1184548027 508 7536515 130735625607 4901786567 155...
output:
446627665045468 113118275636107 488 74098651 5876051124055 128636892665393252 161293026389566908 23770 79928 879511858065 316 23106669890244 514 627261272910824096 4564144 183196011166968560 205843350877 94039538 147545 17859990 10079141821299551 755729582366687226 24141696 6248954036998 14286586861...
result:
ok 50000 numbers
Test #7:
score: 0
Accepted
time: 423ms
memory: 4032kb
input:
50000 5871 92087266136 95 1862263583 30171845 7470126551364 327875 20014020 21939695 543126781639818 11 200913190 100876303597 91 48827 8772564230 2215426 7697708577172 82 109 188642080 5569360772242 7905314269610 316647 2505623 134005806133 376083 684123533246 1372062119 86 2043894010 1237612218 38...
output:
619026 84796684015078 2873 1219341911839 12767965563 9526764202169648 74678395 8063973433 8938089281 910685961708030150 114 105154222614 93573829609856 2705 7998744 6623161651107 670870104 9837164964514998 2333 3479 98068515187 6960784641919253 10120831302178750 71720119 771901482 127144161601507 87...
result:
ok 50000 numbers