不是 #3到底是啥 (95pts)
查看原帖
不是 #3到底是啥 (95pts)
535758
_mumu楼主2024/11/22 14:08

不明白哪里错了
所有hack和大样例也都过了...


#include <bits/stdc++.h>
using namespace std;
#define ll long long

const ll N=2e5+5,P=1e9+7,M=60;
ll n,m,q,pre[N*2],nxt[N][M],w[N][M],n2,pw[M],s0,k;
string s;

ll read() {
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0' || ch>'9') {
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0' && ch<='9') {
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
	return f==1?x:-x;
}

int main(){
	//freopen("kingdom5.in","r",stdin);
	//freopen("kingdom5.out","w",stdout);
	pw[0]=1;
	for(ll i=1;i<M;i++) pw[i]=pw[i-1]<<1;
	scanf("%lld%lld%lld",&n,&m,&q);
	n2=n<<1;
	cin >> s;
	ll l=1;
	for(ll i=1;i<=n2;i++){
		if(s[(i-1)%n]=='1') l=i;
		pre[i]=l;
	}

	for(ll i=1;i<=n;i++){
		ll r=(i+m-1)%n2+1;
		if(r<=n) r+=n;
		if(pre[r]==0 || r-pre[r]>=m){
			nxt[i][0]=i%n+1;
			w[i][0]=1;
		}
		else{
			nxt[i][0]=(pre[r]-1)%n+1;
			w[i][0]=(m-r+pre[r])%P;
		}
	}

	for(ll i=1;i<M;i++){
		for(ll x=1;x<=n;x++){
			nxt[x][i]=nxt[nxt[x][i-1]][i-1];
			w[x][i]=(w[x][i-1]+w[nxt[x][i-1]][i-1])%P;
		}
	}
	
	while(q--){
		s0=read();
		k=read();
		ll x=(s0-1)%n+1;
		s0%=P;
		for(ll i=M-1;i>=0;i--){
			if(k==0) break;
			if(k>=pw[i]){
				k-=pw[i];
				s0=(s0+w[x][i])%P;
				x=nxt[x][i];
			}
		}
		printf("%lld\n",s0);
	}
}
2024/11/22 14:08
加载中...