104392024-04-02 14:05:04111Túlcsorduláscpp17Wrong answer 70/100193ms15112 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define MOD 1000000007
#define BASE 64

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
3Accepted3ms2228 KiB
4Accepted3ms2468 KiB
5Accepted4ms2680 KiB
6Accepted3ms2972 KiB
7Accepted4ms3068 KiB
8Accepted4ms3052 KiB
9Accepted4ms3048 KiB
subtask330/30
10Accepted2ms2840 KiB
11Accepted19ms3796 KiB
12Accepted70ms7452 KiB
13Accepted71ms9632 KiB
14Accepted129ms13716 KiB
15Accepted192ms13408 KiB
16Accepted193ms12944 KiB
17Accepted182ms14136 KiB
subtask40/30
18Accepted8ms4240 KiB
19Accepted37ms14396 KiB
20Accepted65ms6684 KiB
21Accepted111ms12028 KiB
22Accepted190ms14712 KiB
23Wrong answer181ms15028 KiB
24Accepted189ms14660 KiB
25Accepted182ms14168 KiB
26Wrong answer187ms15044 KiB
27Accepted190ms15008 KiB
28Wrong answer180ms15112 KiB