// java 又T了😂, 本机离线跑了3s结果是对的
import java.util.*;
public class Main{
void run(){
String dna = jin.next();
init(dna);
int n = jin.nextInt();
for (int i = 0 ; i < n ; i++){
int l1 = jin.nextInt();
int r1 = jin.nextInt();
int l2 = jin.nextInt();
int r2 = jin.nextInt();
boolean ans = compare(l1, r1, l2, r2);
System.out.println(ans ? "Yes" : "No");
}
}
void init(String str){
char[] value = str.toCharArray();
power.add(1L);
hash.add(0L);
for (int i = 0 ; i < str.length(); i++){
hash.add((hash.get(i) * base % mod + (long)(value[i] - 'a' + 1)) % mod);
power.add(power.get(i) * base % mod);
}
}
boolean compare(int l1, int r1, int l2, int r2){
long h1 = hash.get(r1) - hash.get(l1-1) * power.get(r1-l1+1) % mod;
long h2 = hash.get(r2) - hash.get(l2-1) * power.get(r2-l2+1) % mod;
return h1 == h2;
}
private List<Long> power = new ArrayList<>();
private List<Long> hash = new ArrayList<>();
private long base = 131L;
private long mod = Long.MAX_VALUE;
private Scanner jin = new Scanner(System.in);
public static void main(String[] args) throws Exception {new Main().run();}
}
应该还是你处理的IO不太高效,建议使用BufferedReader
以下是我用Java AC的代码