QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#422266 | #241. Chiaki Sequence Revisited | ship2077 | 0 | 182ms | 3840kb | C++14 | 1.6kb | 2024-05-27 10:01:49 | 2024-05-27 10:01:50 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
int n,l,r,ans;
int read(){
int x=0;char ch=getchar();
while (!isdigit(ch)) ch=getchar();
while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
return x;
}
void solve(){
n=read()-1;l=0;r=n;
while (l<=r){
int mid=l+r>>1,sum=0;
for (int i=0;i<=60;i++) sum+=mid>>i;
if (sum<=n) ans=mid,l=mid+1; else r=mid-1;
} int sum=1;
for (int i=0,tmp;i<=60;i++)
tmp=(ans>>i)%mod,sum=(sum+tmp*(tmp+1)/2%mod*(1ll<<i))%mod,n-=ans>>i;
printf("%lld\n",(sum+(ans+1)%mod*n)%mod);
}
signed main(){int T=read();while (T--) solve();return 0;}
/*#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
int n,ans,sum,sum1[64],sum2[64];
int read(){
int x=0;char ch=getchar();
while (!isdigit(ch)) ch=getchar();
while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
return x;
}
void init(){
// for (int i=1;i<=8;i++){
// for (int j=1;j<=__builtin_ctz(i)+1;j++)
// cerr<<i<<", ";
// } cerr<<endl;
for (int i=1;i<=60;i++)
sum1[i]=sum1[i-1]*2+i,
sum2[i]=(sum2[i-1]*2+(1ll<<i-1)%mod*(sum1[i-1]%mod+i))%mod;
for (int i=0;i<=60;i++) cerr<<i<<":"<<sum1[i]<<','<<sum2[i]<<endl;
}
void solve(){
n=read()-1;ans=1;sum=0;
for (int i=60;~i;i--)
if (n>=sum1[i]){
n-=sum1[i];
ans=(ans+sum2[i]+sum1[i]*sum)%mod;
sum=(sum+(1ll<<i))%mod;
}
// for (int i=1;1;i++){
// int tmp=__builtin_ctz(i)+1;
// if (n>=tmp) ans+=tmp*i,n-=tmp;
// else {ans+=n*i;break;}
// }
printf("%lld\n",ans);
}
signed main(){init();int T=read();while (T--) solve();return 0;}*/
詳細信息
Test #1:
score: 0
Wrong Answer
time: 182ms
memory: 3840kb
input:
100000 1 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 1...
output:
1 2 4 6 9 13 17 21 26 32 38 45 53 61 69 77 86 96 106 117 129 141 153 166 180 194 209 225 241 257 273 289 306 324 342 361 381 401 421 442 464 486 509 533 557 581 605 630 656 682 709 737 765 793 822 852 882 913 945 977 1009 1041 1073 1105 1138 1172 1206 1241 1277 1313 1349 1386 1424 1462 1501 1541 158...
result:
wrong answer 10001st lines differ - expected: '550345233', found: '197508020'