104402024-04-02 14:08:00111Túlcsorduláscpp17Accepted 100/100196ms15388 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define MOD (int)1000000007
#define BASE (int)256

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin>>N;
	string A,B;
	cin>>A>>B;
	for(char&c:B){
		c='0'+'1'-c;
	}
	vector<int>p(N+1,1),ha(N+1),hb(N+1);
	for(int i=0;i<N;i++){
		p[i+1]=p[i]*BASE%MOD;
		ha[i+1]=(ha[i]*BASE+A[i])%MOD;
		hb[i+1]=(hb[i]*BASE+B[i])%MOD;
	}
	int Q;
	cin>>Q;
	while(Q--){
		int x,y,L;
		cin>>x>>y>>L;
		int l=0,h=L;
		while(l<h){
			int m=(l+h)/2;
			if((ha[x+m+1]-ha[x]*p[m+1]+MOD*MOD)%MOD==(hb[y+m+1]-hb[y]*p[m+1]+MOD*MOD)%MOD){
				l=m+1;
			}
			else{
				h=m;
			}
		}
		cout<<(h==L||A[x+h]=='0'?1:0)<<' ';
	}
	cout<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Accepted3ms2056 KiB
subtask240/40
3Accepted3ms2260 KiB
4Accepted3ms2344 KiB
5Accepted4ms2496 KiB
6Accepted3ms2932 KiB
7Accepted4ms3112 KiB
8Accepted4ms3184 KiB
9Accepted4ms3436 KiB
subtask330/30
10Accepted3ms3380 KiB
11Accepted19ms4108 KiB
12Accepted71ms7868 KiB
13Accepted72ms10320 KiB
14Accepted133ms14564 KiB
15Accepted190ms14052 KiB
16Accepted192ms13864 KiB
17Accepted185ms14892 KiB
subtask430/30
18Accepted8ms4956 KiB
19Accepted37ms15032 KiB
20Accepted65ms7100 KiB
21Accepted112ms12692 KiB
22Accepted196ms15248 KiB
23Accepted180ms15296 KiB
24Accepted194ms14676 KiB
25Accepted182ms14304 KiB
26Accepted192ms15208 KiB
27Accepted192ms15204 KiB
28Accepted180ms15388 KiB