104382024-04-02 14:03:51111Túlcsorduláscpp17Wrong answer 70/100193ms15540 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define MOD 1000000007
#define BASE 256
#define BASE_INV 285156252

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
1Accepted3ms2004 KiB
2Accepted3ms2152 KiB
subtask240/40
3Accepted3ms2380 KiB
4Accepted3ms2588 KiB
5Accepted4ms2588 KiB
6Accepted3ms3156 KiB
7Accepted4ms2912 KiB
8Accepted4ms3112 KiB
9Accepted4ms3348 KiB
subtask330/30
10Accepted3ms3268 KiB
11Accepted19ms3920 KiB
12Accepted71ms7776 KiB
13Accepted74ms10064 KiB
14Accepted131ms14152 KiB
15Accepted188ms13868 KiB
16Accepted186ms13488 KiB
17Accepted182ms14672 KiB
subtask40/30
18Accepted8ms5000 KiB
19Accepted35ms15180 KiB
20Accepted64ms7268 KiB
21Accepted112ms12452 KiB
22Accepted189ms15300 KiB
23Wrong answer180ms15540 KiB
24Accepted187ms15040 KiB
25Accepted180ms14552 KiB
26Wrong answer188ms15436 KiB
27Accepted193ms15400 KiB
28Wrong answer180ms15396 KiB