#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct suffix_array {
string s;
int n;
vector<int> c, p;
suffix_array(string s){
s += '$';
this->s = s;
this->n = s.length();
int n = s.length();
vector<int> c(n, 0), p(n, 0), cnt(max(n, 256), 0);
for(char x : s) cnt[x]++;
for(int i = 1; i < 256; i++) cnt[i] += cnt[i-1];
for(int i = 0; i < n; i++) p[--cnt[s[i]]] = i;
c[p[0]] = 0;
for(int i = 1; i < n; i++) c[p[i]] = (s[p[i]] != s[p[i-1]]) ? c[p[i-1]] + 1 : c[p[i-1]];
for(int i = 2; i <= 2*n; i <<= 1){
vector<pair<int, int>> v;
vector<int> pn = p, cn = c;
for(int j = 0; j < n; j++){
v.push_back({j, (j + i/2)%n});
}
for(int &j : cnt) j = 0;
for(int j = 0; j < n; j++) cnt[c[v[j].second]]++;
for(int j = 1; j < n; j++) cnt[j] += cnt[j-1];
for(int j = 0; j < n; j++) pn[--cnt[c[v[j].second]]] = j;
for(int &j : cnt) j = 0;
for(int j = 0; j < n; j++) cnt[c[pn[j]]]++;
for(int j = 1; j < n; j++) cnt[j] += cnt[j-1];
for(int j = 0; j < n; j++) p[--cnt[c[pn[n-1-j]]]] = pn[n-1-j];
cn[p[0]] = 0;
int classes = 1;
for (int j = 1; j < n; j++) {
pair<int, int> cur = {c[p[j]], c[(p[j] + i/2) % n]};
pair<int, int> prev = {c[p[j-1]], c[(p[j-1] + i/2 + n) % n]};
if (cur != prev) ++classes;
cn[p[j]] = classes - 1;
}
c.swap(cn);
}
// c.pop_back();
// for(int &x : c) x--;
// p.erase(p.begin());
this->p = p;
this->c = c;
}
void prt(){
for(int x : p) cout << x << " ";
cout << endl;
}
int first_occ(string x){
int l = 0, r = n-1, ans = -1;
while(l <= r){
int mid = (l + r)/2;
string sub = s.substr(p[mid], min(s.length() - p[mid], x.length()));
if(sub >= x){
if(sub == x) ans = mid;
r = mid-1;
} else {
l = mid+1;
}
}
return ans;
}
bool exist(string x){
int l = 0, r = n-1, ans = -1;
while(l <= r){
int mid = (l + r)/2;
string sub1 = s.substr(p[mid], s.length() - p[mid]);
string sub = sub1.substr(0, min(sub1.length(), x.length()));
if(sub >= x){
if(sub == x) ans = mid;
r = mid-1;
} else {
l = mid+1;
}
}
return (ans != -1);
}
};
char buf[300010];
string read(){
scanf("%s", buf);
return buf;
}
int main(){
string s = read();
suffix_array suf(s);
int q;
scanf("%d", &q);
while(q--){
string x = read();
puts(suf.exist(x) ? "Yes" : "No");
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp1c2luZyBsbCA9IGxvbmcgbG9uZzsKCnN0cnVjdCBzdWZmaXhfYXJyYXkgewoKICAgIHN0cmluZyBzOwogICAgaW50IG47CiAgICB2ZWN0b3I8aW50PiBjLCBwOwogICAgc3VmZml4X2FycmF5KHN0cmluZyBzKXsKICAgICAgICBzICs9ICckJzsKICAgICAgICB0aGlzLT5zID0gczsKICAgICAgICB0aGlzLT5uID0gcy5sZW5ndGgoKTsKICAgICAgICBpbnQgbiA9IHMubGVuZ3RoKCk7CiAgICAgICAgdmVjdG9yPGludD4gYyhuLCAwKSwgcChuLCAwKSwgY250KG1heChuLCAyNTYpLCAwKTsKICAgICAgICBmb3IoY2hhciB4IDogcykgY250W3hdKys7CiAgICAgICAgZm9yKGludCBpID0gMTsgaSA8IDI1NjsgaSsrKSBjbnRbaV0gKz0gY250W2ktMV07CiAgICAgICAgZm9yKGludCBpID0gMDsgaSA8IG47IGkrKykgcFstLWNudFtzW2ldXV0gPSBpOwogICAgICAgIGNbcFswXV0gPSAwOwogICAgICAgIGZvcihpbnQgaSA9IDE7IGkgPCBuOyBpKyspIGNbcFtpXV0gPSAoc1twW2ldXSAhPSBzW3BbaS0xXV0pID8gY1twW2ktMV1dICsgMSA6IGNbcFtpLTFdXTsKICAgICAgICBmb3IoaW50IGkgPSAyOyBpIDw9IDIqbjsgaSA8PD0gMSl7CiAgICAgICAgICAgIHZlY3RvcjxwYWlyPGludCwgaW50Pj4gdjsKICAgICAgICAgICAgdmVjdG9yPGludD4gcG4gPSBwLCBjbiA9IGM7CiAgICAgICAgICAgIGZvcihpbnQgaiA9IDA7IGogPCBuOyBqKyspewogICAgICAgICAgICAgICAgdi5wdXNoX2JhY2soe2osIChqICsgaS8yKSVufSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZm9yKGludCAmaiA6IGNudCkgaiA9IDA7CiAgICAgICAgICAgIGZvcihpbnQgaiA9IDA7IGogPCBuOyBqKyspIGNudFtjW3Zbal0uc2Vjb25kXV0rKzsKICAgICAgICAgICAgZm9yKGludCBqID0gMTsgaiA8IG47IGorKykgY250W2pdICs9IGNudFtqLTFdOwogICAgICAgICAgICBmb3IoaW50IGogPSAwOyBqIDwgbjsgaisrKSBwblstLWNudFtjW3Zbal0uc2Vjb25kXV1dID0gajsKICAgICAgICAgICAgZm9yKGludCAmaiA6IGNudCkgaiA9IDA7CiAgICAgICAgICAgIGZvcihpbnQgaiA9IDA7IGogPCBuOyBqKyspIGNudFtjW3BuW2pdXV0rKzsKICAgICAgICAgICAgZm9yKGludCBqID0gMTsgaiA8IG47IGorKykgY250W2pdICs9IGNudFtqLTFdOwogICAgICAgICAgICBmb3IoaW50IGogPSAwOyBqIDwgbjsgaisrKSBwWy0tY250W2NbcG5bbi0xLWpdXV1dID0gcG5bbi0xLWpdOwogICAgICAgICAgICBjbltwWzBdXSA9IDA7CiAgICAgICAgICAgIGludCBjbGFzc2VzID0gMTsKICAgICAgICAgICAgZm9yIChpbnQgaiA9IDE7IGogPCBuOyBqKyspIHsKICAgICAgICAgICAgICAgIHBhaXI8aW50LCBpbnQ+IGN1ciA9IHtjW3Bbal1dLCBjWyhwW2pdICsgaS8yKSAlIG5dfTsKICAgICAgICAgICAgICAgIHBhaXI8aW50LCBpbnQ+IHByZXYgPSB7Y1twW2otMV1dLCBjWyhwW2otMV0gKyBpLzIgKyBuKSAlIG5dfTsKICAgICAgICAgICAgICAgIGlmIChjdXIgIT0gcHJldikgKytjbGFzc2VzOwogICAgICAgICAgICAgICAgY25bcFtqXV0gPSBjbGFzc2VzIC0gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBjLnN3YXAoY24pOwogICAgICAgIH0KICAgICAgICAvLyBjLnBvcF9iYWNrKCk7CiAgICAgICAgLy8gZm9yKGludCAmeCA6IGMpIHgtLTsKICAgICAgICAvLyBwLmVyYXNlKHAuYmVnaW4oKSk7CiAgICAgICAgdGhpcy0+cCA9IHA7CiAgICAgICAgdGhpcy0+YyA9IGM7CiAgICB9CgogICAgdm9pZCBwcnQoKXsKICAgICAgICBmb3IoaW50IHggOiBwKSBjb3V0IDw8IHggPDwgIiAiOwogICAgICAgIGNvdXQgPDwgZW5kbDsKICAgIH0KCiAgICBpbnQgZmlyc3Rfb2NjKHN0cmluZyB4KXsKICAgICAgICBpbnQgbCA9IDAsIHIgPSBuLTEsIGFucyA9IC0xOwogICAgICAgIHdoaWxlKGwgPD0gcil7CiAgICAgICAgICAgIGludCBtaWQgPSAobCArIHIpLzI7CiAgICAgICAgICAgIHN0cmluZyBzdWIgPSBzLnN1YnN0cihwW21pZF0sIG1pbihzLmxlbmd0aCgpIC0gcFttaWRdLCB4Lmxlbmd0aCgpKSk7CiAgICAgICAgICAgIGlmKHN1YiA+PSB4KXsKICAgICAgICAgICAgICAgIGlmKHN1YiA9PSB4KSBhbnMgPSBtaWQ7CiAgICAgICAgICAgICAgICByID0gbWlkLTE7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBsID0gbWlkKzE7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGFuczsKICAgIH0KICAgIAogICAgYm9vbCBleGlzdChzdHJpbmcgeCl7CiAgICAgICAgaW50IGwgPSAwLCByID0gbi0xLCBhbnMgPSAtMTsKICAgICAgICB3aGlsZShsIDw9IHIpewogICAgICAgICAgICBpbnQgbWlkID0gKGwgKyByKS8yOwogICAgICAgICAgICBzdHJpbmcgc3ViMSA9IHMuc3Vic3RyKHBbbWlkXSwgcy5sZW5ndGgoKSAtIHBbbWlkXSk7CiAgICAgICAgICAgIHN0cmluZyBzdWIgPSBzdWIxLnN1YnN0cigwLCBtaW4oc3ViMS5sZW5ndGgoKSwgeC5sZW5ndGgoKSkpOwogICAgICAgICAgICBpZihzdWIgPj0geCl7CiAgICAgICAgICAgICAgICBpZihzdWIgPT0geCkgYW5zID0gbWlkOwogICAgICAgICAgICAgICAgciA9IG1pZC0xOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgbCA9IG1pZCsxOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiAoYW5zICE9IC0xKTsKICAgIH0KCn07CgpjaGFyIGJ1ZlszMDAwMTBdOwoKc3RyaW5nIHJlYWQoKXsKICAgIHNjYW5mKCIlcyIsIGJ1Zik7CiAgICByZXR1cm4gYnVmOwp9CgppbnQgbWFpbigpewoKICAgIHN0cmluZyBzID0gcmVhZCgpOwogICAgc3VmZml4X2FycmF5IHN1ZihzKTsKCiAgICBpbnQgcTsKICAgIHNjYW5mKCIlZCIsICZxKTsKICAgIHdoaWxlKHEtLSl7CiAgICAgICAgc3RyaW5nIHggPSByZWFkKCk7CiAgICAgICAgcHV0cyhzdWYuZXhpc3QoeCkgPyAiWWVzIiA6ICJObyIpOwogICAgfQoKCn0K
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
^
Main.java:4: error: class, interface, or enum expected
using ll = long long;
^
Main.java:6: error: class, interface, or enum expected
struct suffix_array {
^
Main.java:9: error: class, interface, or enum expected
int n;
^
Main.java:10: error: class, interface, or enum expected
vector<int> c, p;
^
Main.java:11: error: class, interface, or enum expected
suffix_array(string s){
^
Main.java:13: error: class, interface, or enum expected
this->s = s;
^
Main.java:14: error: class, interface, or enum expected
this->n = s.length();
^
Main.java:15: error: class, interface, or enum expected
int n = s.length();
^
Main.java:16: error: class, interface, or enum expected
vector<int> c(n, 0), p(n, 0), cnt(max(n, 256), 0);
^
Main.java:17: error: class, interface, or enum expected
for(char x : s) cnt[x]++;
^
Main.java:18: error: class, interface, or enum expected
for(int i = 1; i < 256; i++) cnt[i] += cnt[i-1];
^
Main.java:18: error: class, interface, or enum expected
for(int i = 1; i < 256; i++) cnt[i] += cnt[i-1];
^
Main.java:18: error: class, interface, or enum expected
for(int i = 1; i < 256; i++) cnt[i] += cnt[i-1];
^
Main.java:19: error: class, interface, or enum expected
for(int i = 0; i < n; i++) p[--cnt[s[i]]] = i;
^
Main.java:19: error: class, interface, or enum expected
for(int i = 0; i < n; i++) p[--cnt[s[i]]] = i;
^
Main.java:19: error: class, interface, or enum expected
for(int i = 0; i < n; i++) p[--cnt[s[i]]] = i;
^
Main.java:20: error: class, interface, or enum expected
c[p[0]] = 0;
^
Main.java:21: error: class, interface, or enum expected
for(int i = 1; i < n; i++) c[p[i]] = (s[p[i]] != s[p[i-1]]) ? c[p[i-1]] + 1 : c[p[i-1]];
^
Main.java:21: error: class, interface, or enum expected
for(int i = 1; i < n; i++) c[p[i]] = (s[p[i]] != s[p[i-1]]) ? c[p[i-1]] + 1 : c[p[i-1]];
^
Main.java:21: error: class, interface, or enum expected
for(int i = 1; i < n; i++) c[p[i]] = (s[p[i]] != s[p[i-1]]) ? c[p[i-1]] + 1 : c[p[i-1]];
^
Main.java:22: error: class, interface, or enum expected
for(int i = 2; i <= 2*n; i <<= 1){
^
Main.java:22: error: class, interface, or enum expected
for(int i = 2; i <= 2*n; i <<= 1){
^
Main.java:22: error: class, interface, or enum expected
for(int i = 2; i <= 2*n; i <<= 1){
^
Main.java:24: error: class, interface, or enum expected
vector<int> pn = p, cn = c;
^
Main.java:25: error: class, interface, or enum expected
for(int j = 0; j < n; j++){
^
Main.java:25: error: class, interface, or enum expected
for(int j = 0; j < n; j++){
^
Main.java:25: error: class, interface, or enum expected
for(int j = 0; j < n; j++){
^
Main.java:27: error: class, interface, or enum expected
}
^
Main.java:29: error: class, interface, or enum expected
for(int j = 0; j < n; j++) cnt[c[v[j].second]]++;
^
Main.java:29: error: class, interface, or enum expected
for(int j = 0; j < n; j++) cnt[c[v[j].second]]++;
^
Main.java:29: error: class, interface, or enum expected
for(int j = 0; j < n; j++) cnt[c[v[j].second]]++;
^
Main.java:30: error: class, interface, or enum expected
for(int j = 1; j < n; j++) cnt[j] += cnt[j-1];
^
Main.java:30: error: class, interface, or enum expected
for(int j = 1; j < n; j++) cnt[j] += cnt[j-1];
^
Main.java:30: error: class, interface, or enum expected
for(int j = 1; j < n; j++) cnt[j] += cnt[j-1];
^
Main.java:31: error: class, interface, or enum expected
for(int j = 0; j < n; j++) pn[--cnt[c[v[j].second]]] = j;
^
Main.java:31: error: class, interface, or enum expected
for(int j = 0; j < n; j++) pn[--cnt[c[v[j].second]]] = j;
^
Main.java:31: error: class, interface, or enum expected
for(int j = 0; j < n; j++) pn[--cnt[c[v[j].second]]] = j;
^
Main.java:32: error: class, interface, or enum expected
for(int &j : cnt) j = 0;
^
Main.java:33: error: class, interface, or enum expected
for(int j = 0; j < n; j++) cnt[c[pn[j]]]++;
^
Main.java:33: error: class, interface, or enum expected
for(int j = 0; j < n; j++) cnt[c[pn[j]]]++;
^
Main.java:33: error: class, interface, or enum expected
for(int j = 0; j < n; j++) cnt[c[pn[j]]]++;
^
Main.java:34: error: class, interface, or enum expected
for(int j = 1; j < n; j++) cnt[j] += cnt[j-1];
^
Main.java:34: error: class, interface, or enum expected
for(int j = 1; j < n; j++) cnt[j] += cnt[j-1];
^
Main.java:34: error: class, interface, or enum expected
for(int j = 1; j < n; j++) cnt[j] += cnt[j-1];
^
Main.java:35: error: class, interface, or enum expected
for(int j = 0; j < n; j++) p[--cnt[c[pn[n-1-j]]]] = pn[n-1-j];
^
Main.java:35: error: class, interface, or enum expected
for(int j = 0; j < n; j++) p[--cnt[c[pn[n-1-j]]]] = pn[n-1-j];
^
Main.java:35: error: class, interface, or enum expected
for(int j = 0; j < n; j++) p[--cnt[c[pn[n-1-j]]]] = pn[n-1-j];
^
Main.java:36: error: class, interface, or enum expected
cn[p[0]] = 0;
^
Main.java:37: error: class, interface, or enum expected
int classes = 1;
^
Main.java:38: error: class, interface, or enum expected
for (int j = 1; j < n; j++) {
^
Main.java:38: error: class, interface, or enum expected
for (int j = 1; j < n; j++) {
^
Main.java:38: error: class, interface, or enum expected
for (int j = 1; j < n; j++) {
^
Main.java:40: error: class, interface, or enum expected
pair<int, int> prev = {c[p[j-1]], c[(p[j-1] + i/2 + n) % n]};
^
Main.java:41: error: class, interface, or enum expected
if (cur != prev) ++classes;
^
Main.java:42: error: class, interface, or enum expected
cn[p[j]] = classes - 1;
^
Main.java:43: error: class, interface, or enum expected
}
^
Main.java:45: error: class, interface, or enum expected
}
^
Main.java:50: error: class, interface, or enum expected
this->c = c;
^
Main.java:51: error: class, interface, or enum expected
}
^
Main.java:55: error: class, interface, or enum expected
cout << endl;
^
Main.java:56: error: class, interface, or enum expected
}
^
Main.java:60: error: class, interface, or enum expected
while(l <= r){
^
Main.java:62: error: class, interface, or enum expected
string sub = s.substr(p[mid], min(s.length() - p[mid], x.length()));
^
Main.java:63: error: class, interface, or enum expected
if(sub >= x){
^
Main.java:65: error: class, interface, or enum expected
r = mid-1;
^
Main.java:66: error: class, interface, or enum expected
} else {
^
Main.java:68: error: class, interface, or enum expected
}
^
Main.java:71: error: class, interface, or enum expected
}
^
Main.java:75: error: class, interface, or enum expected
while(l <= r){
^
Main.java:77: error: class, interface, or enum expected
string sub1 = s.substr(p[mid], s.length() - p[mid]);
^
Main.java:78: error: class, interface, or enum expected
string sub = sub1.substr(0, min(sub1.length(), x.length()));
^
Main.java:79: error: class, interface, or enum expected
if(sub >= x){
^
Main.java:81: error: class, interface, or enum expected
r = mid-1;
^
Main.java:82: error: class, interface, or enum expected
} else {
^
Main.java:84: error: class, interface, or enum expected
}
^
Main.java:87: error: class, interface, or enum expected
}
^
Main.java:91: error: class, interface, or enum expected
char buf[300010];
^
Main.java:93: error: class, interface, or enum expected
string read(){
^
Main.java:95: error: class, interface, or enum expected
return buf;
^
Main.java:96: error: class, interface, or enum expected
}
^
Main.java:101: error: class, interface, or enum expected
suffix_array suf(s);
^
Main.java:103: error: class, interface, or enum expected
int q;
^
Main.java:104: error: class, interface, or enum expected
scanf("%d", &q);
^
Main.java:105: error: class, interface, or enum expected
while(q--){
^
Main.java:107: error: class, interface, or enum expected
puts(suf.exist(x) ? "Yes" : "No");
^
Main.java:108: error: class, interface, or enum expected
}
^
88 errors