传送门

i < m i<m i<m

i i i个字符就是 [ 1 , i ] [1,i] [1,i]所有二进制数字异或的结果

现在已经知道了结果 w w w,知道 [ 1 , i − 1 ] [1,i-1] [1,i1]的异或结果,那么当前位数很容易求出来

然后当 i > m & & i < = n i>m\&\&i<=n i>m&&i<=n

显然每往后挪动一位数就会消掉之前的某一位,然后按照上面一样递推即可

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+10;
int n,m,b[maxn];
char a[maxn];
int main()
{
	cin >> n >> m >> (a+1);
	int x = 0;zhong
	for(int i=1;i<=n;i++)
	{
		if( i<=m )
		{
			int now = 0;
			if( x==0&&a[i]=='0' )	now = 0;
			else if( x==0&&a[i]=='1' )	now = 1;
			else if( x==1&&a[i]=='0' )	now = 1;
			else if( x==1&&a[i]=='1' )	now = 0;	
			cout << now;
			x^=now; b[i] = now;
			continue;
		}
		else if( i>m&&i<=n )
		{
			x^=b[i-m];
			int now = 0;
			if( x==0&&a[i]=='0' )	now = 0;
			else if( x==0&&a[i]=='1' )	now = 1;
			else if( x==1&&a[i]=='0' )	now = 1;
			else if( x==1&&a[i]=='1' )	now = 0;	
			cout << now;
			x^=now; b[i] = now;
			continue;
		}
		
	}
}