1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| import java.util.*; import java.io.*;
public class Main { static int mod[]=new int[] {0,998244353,(int)(1e9+7)}; static int p[]=new int[] {0,131,13331}; static String str; public static void main(String args[]) { int n=in.nextInt(); int q=in.nextInt(); str=" "+in.next(); init(); while(q-->0) { int l1=in.nextInt(),r1=in.nextInt(); int l2=in.nextInt(),r2=in.nextInt(); if(check(l1,r1,1)==check(l2,r2,1)&&check(l1,r1,2)==check(l2,r2,2)) { out.println("YES"); }else { out.println("NO"); } } out.flush(); } static int N=(int)(2e5+10); static long dev[][]=new long[N][10]; static long node[][]=new long[N][10]; static void init() { dev[0][1]=1; for(int i=1;i<str.length();i++) { dev[i][1]=dev[i-1][1]*p[1]%mod[1]; node[i][1]=(node[i-1][1]*p[1]+str.charAt(i)-'0')%mod[1]; } dev[0][2]=1; for(int i=1;i<str.length();i++) { dev[i][2]=dev[i-1][2]*p[2]%mod[2]; node[i][2]=(node[i-1][2]*p[2]+str.charAt(i)-'0')%mod[2]; } } static long check(int l,int r,int idx){ return ((node[r][idx]-node[l-1][idx]*dev[r-l+1][idx]%mod[idx])%mod[idx]+mod[idx])%mod[idx]; } static PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); static input in=new input(); static class input{ static BufferedReader br; static StringTokenizer st; input(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next() { String str=""; while(st==null||!st.hasMoreElements()) { try { str=br.readLine(); }catch(Exception e) { e.printStackTrace(); } st=new StringTokenizer(str); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
|