QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#561957 | #5424. NaN in a Heap | louhao088 | WA | 1ms | 3596kb | C++23 | 2.0kb | 2024-09-13 13:35:40 | 2024-09-13 13:35:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int n,m,ans,pw[35],T;
map<int,int>f[2][2],vis[2][2];
int Pow(int x,int y){
int res=1;
while(y){
if(y&1){
res=res*x%mod;
}
y=y/2;x=x*x%mod;
}return res;
}
int get(int x){
int res,o;
for(int i=1;i<=31;i++){
if(pw[i]-1<=x)o=i;
}
//cout<<x<<" "<<o<<" "<<pw[o]-1<<endl;
int u=pw[o-1]-1;
res=x-(pw[o]-1);
res=min(res,pw[o-1]);
res+=u;
return res;
}
int dfs(int x,int y,int z){
if(x==0)return 1;
if(x==1){
if(y==1&&z==0)return 0;
return 1;
}
if(vis[y][z][x]==1)return f[y][z][x];
int l1=get(x);
int l2=x-1-l1;
//cout<<x<<" "<<l1<<" "<<l2<<endl;
vis[y][z][x]=1;
int t;
if(y==0&&z==0){
t=dfs(l1,0,0)*dfs(l2,0,0)%mod*Pow(x,mod-2)%mod;
}
if(y==1&&z==1){
t=dfs(l1,0,0)*dfs(l2,0,0)%mod;
}
if(y==1&&z==0){
int p=2*l1*l2;p=p%mod;
t= dfs(l1,0,0)*dfs(l2,1,0)%mod*Pow(x-1,mod-2)%mod*l1%mod*(l2-1)%mod*Pow(p,mod-2)%mod;
t=(t+dfs(l1,1,0)*dfs(l2,0,0)%mod*Pow(x-1,mod-2)%mod*l2%mod*(l1-1)%mod*Pow(p,mod-2))%mod;
//cout<<t<<" "<<p<<" "<<Pow(12,mod-2)<<endl;
t=(t+dfs(l1,0,0)*dfs(l2,1,1)%mod*Pow(l1+1,mod-2)%mod*(l1)%mod*Pow(p,mod-2))%mod;
t=(t+dfs(l1,1,1)*dfs(l2,0,0)%mod*Pow(l2+1,mod-2)%mod*(l2)%mod*Pow(p,mod-2))%mod;
}
f[y][z][x]=t;
cout<<f[y][z][x]<<" "<<x<<" "<<y<<" "<<z<<" "<<l1<<" "<<l2<<endl;
return f[y][z][x];
}
signed main(){
cin>>T;
pw[0]=1;cout<<3*Pow(8,mod-2)%mod<<endl;
for(int i=1;i<=31;i++)pw[i]=pw[i-1]*2;
//cout<<get(3);return 0;
vis[1][1][2]=1;
vis[0][0][2]=1;
vis[1][0][2]=1;
f[1][1][2]=1;
f[0][0][2]=Pow(2,mod-2);
f[1][0][2]=1;
while(T--){
cin>>n;
ans=(dfs(n,1,0)*(n-1)+dfs(n,1,1))%mod*Pow(n,mod-2)%mod;
cout<<ans<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3596kb
input:
5 1 3 7 10 20221218
output:
375000003 1 500000004 3 1 0 1 1 1 3 1 1 1 1 666666672 333333336 3 0 0 1 1 712962968 7 1 0 3 3 111111112 7 1 1 3 3 55555556 27777778 6 0 0 3 2 781944450 6 1 0 3 2 166666668 6 1 1 3 2 375511344 10 1 0 6 3 342592595 10 1 1 6 3 72219467 15873016 7 0 0 3 3 309011508 15 0 0 7 7 884129596 31 0 0 15 15 3658...
result:
wrong answer 1st numbers differ - expected: '1', found: '375000003'