社区讨论
求问,悬1关
学术版参与者 2已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @mhjh2rfs
- 此快照首次捕获于
- 2025/11/04 02:27 4 个月前
- 此快照最后确认于
- 2025/11/04 02:27 4 个月前
在P11267中,我考虑 m>n 的情况,写出如下代码
C#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
long long n,m,q;
int a[400005];
int l[400005];
int lst;
long long stp[200005][70];
long long sta[200005][70];
char c;
int main()
{
cin>>n>>m>>q;
for(int i=1;i<=n;i++)
{
cin>>c;
a[i]=(c=='1');
a[i+n]=a[i];
}
for(int i=1;i<=2*n;i++)
{
if(a[i])lst=i;
l[i]=lst;
}
if(m<=n)
{
for(int i=1;i<=n;i++)
{
stp[i][0]=max(l[i+m],i+1);
sta[i][0]=(stp[i][0]-i)%mod;
stp[i][0]=(stp[i][0]-1)%n+1;
}
}
else
{
for(int i=1;i<=n;i++)
{
stp[i][0]=max(l[i+(m%n)],i+1);
if(m%n<i+1&&l[i+(m%n)])stp[i][0]=l[i+(m%n)];//注意这里的第一个条件
if(stp[i][0]>=i)sta[i][0]=(stp[i][0]-i+(m/n*n))%mod;
else sta[i][0]=(stp[i][0]+n-i+max(0ll,((m/n-1)*n)))%mod;
stp[i][0]=(stp[i][0]-1)%n+1;
}
}
for(int j=1;j<=65;j++)
{
for(int i=1;i<=n;i++)
{
stp[i][j]=stp[stp[i][j-1]][j-1];
sta[i][j]=(sta[i][j-1]+sta[stp[i][j-1]][j-1])%mod;
}
}
while(q--)
{
long long x,y;
cin>>x>>y;
int r=60;
long long ans=x%mod;
if(x>n)x=(x-1)%n+1;
while(y)
{
long long p=(1ll<<r);
if(y>=p)
{
y-=p;
ans+=sta[x][r];
x=stp[x][r];
ans%=mod;
}
// cout<<x<<' '<<y<<' '<<r<<' '<<p<<' '<<ans<<endl;
r--;
}
cout<<ans%mod<<endl;
}
return 0;
}
但85分,于是继续调发现39行判断条件好像是错的(m%n<i-1)
应该是小于1才对
但改完后只有45了 感觉不正确的代码得分更高
求大佬帮忙证明一下哪个是错误的,或由于其他问题导致
应该是小于1才对
但改完后只有45了 感觉不正确的代码得分更高
求大佬帮忙证明一下哪个是错误的,或由于其他问题导致
回复
共 4 条回复,欢迎继续交流。
正在加载回复...