#include <iostream>
#define int long long
using namespace std;
const int N = 2e5 + 20, P = 1e9 + 7;
string s;
int f[N][65];
int lst[N * 2], po[70];
signed main()
{
freopen("re.in", "r", stdin);
freopen("re.out", "w", stdout);
po[0] = 1;
for (int i = 1; i <= 60; i ++ )
{
po[i] = po[i - 1] * 2;
}
int n, m, q;
scanf("%lld%lld%lld", &n, &m, &q);
cin >> s;
bool flag = 1;
for (int i = 0; i < n; i ++ )
{
if(s[i] == '1') flag = 0;
}
if(flag)
{
for (int i = 1; i <= q; i ++ )
{
int bg, k, ans, now;
scanf("%lld%lld", &bg, &k);
ans = (bg + k) % P;
printf("%lld\n", ans);
}
return 0;
}
int yl = -1;
for (int i = 0; i < 2 * n; i ++ )
{
if(s[i % n] == '0')
{
lst[i] = yl;
}
else if(s[i % n] == '1')
{
lst[i] = i;
yl = i;
}
// cout << i << " " << lst[i] << endl;
}
for (int j = 0; j < n; j ++ )
{
int pos = (j + m) % n;
if(m < n - j)
{
int pos1 = lst[(j + m) % n];
if(pos1 > j)
{
f[j][0] = lst[(j + m) % n] - j;
}
else
{
f[j][0] = 1;
}
}
else if(m < 2 * n - j)
{
// if(j == 6) cout << "#";
int pos1 = lst[n + (j + m) % n];
if(pos1 > j)
{
f[j][0] = lst[n + (j + m) % n] - j;
}
else
{
f[j][0] = 1;
}
}
else
{
if(lst[n + (j + m) % n] < 0)
{
f[j][0] = 1;
}
else f[j][0] = ((j + m - (n + (j + m) % n - lst[n + (j + m) % n]) - j) % P + P) % P;
}
}
for (int i = 1; i <= 60; i ++ )
{
for (int j = 0; j < n; j ++ )
{
f[j][i] = (f[j][i - 1] + f[(j + f[j][i - 1]) % n][i - 1]) % P;
}
}
for (int i = 1; i <= q; i ++ )
{
int bg, k, ans, now;
scanf("%lld%lld", &bg, &k);
bg --;
ans = bg % P;
now = bg % n;
for (long long j = 60; j >= 0; j -- )
{
// cout << j << endl;
if(k >= po[j])
{
k -= po[j];
ans = (ans + f[now][j]) % P;
now = (now + f[now][j]) % n;
}
}
printf("%lld\n", (ans + 1) % P);
}
// fclose(stdin);
// fclose(stdout);
return 0;
}
为什么数据扩大到15 ~ 20就全错了, 但是之前一点问题都没有