fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using ll = long long;
  5.  
  6. struct suffix_array {
  7.  
  8. string s;
  9. int n;
  10. vector<int> c, p;
  11. suffix_array(string s){
  12. s += '$';
  13. this->s = s;
  14. this->n = s.length();
  15. int n = s.length();
  16. vector<int> c(n, 0), p(n, 0), cnt(max(n, 256), 0);
  17. for(char x : s) cnt[x]++;
  18. for(int i = 1; i < 256; i++) cnt[i] += cnt[i-1];
  19. for(int i = 0; i < n; i++) p[--cnt[s[i]]] = i;
  20. c[p[0]] = 0;
  21. 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]];
  22. for(int i = 2; i <= 2*n; i <<= 1){
  23. vector<pair<int, int>> v;
  24. vector<int> pn = p, cn = c;
  25. for(int j = 0; j < n; j++){
  26. v.push_back({j, (j + i/2)%n});
  27. }
  28. for(int &j : cnt) j = 0;
  29. for(int j = 0; j < n; j++) cnt[c[v[j].second]]++;
  30. for(int j = 1; j < n; j++) cnt[j] += cnt[j-1];
  31. for(int j = 0; j < n; j++) pn[--cnt[c[v[j].second]]] = j;
  32. for(int &j : cnt) j = 0;
  33. for(int j = 0; j < n; j++) cnt[c[pn[j]]]++;
  34. for(int j = 1; j < n; j++) cnt[j] += cnt[j-1];
  35. for(int j = 0; j < n; j++) p[--cnt[c[pn[n-1-j]]]] = pn[n-1-j];
  36. cn[p[0]] = 0;
  37. int classes = 1;
  38. for (int j = 1; j < n; j++) {
  39. pair<int, int> cur = {c[p[j]], c[(p[j] + i/2) % n]};
  40. pair<int, int> prev = {c[p[j-1]], c[(p[j-1] + i/2 + n) % n]};
  41. if (cur != prev) ++classes;
  42. cn[p[j]] = classes - 1;
  43. }
  44. c.swap(cn);
  45. }
  46. // c.pop_back();
  47. // for(int &x : c) x--;
  48. // p.erase(p.begin());
  49. this->p = p;
  50. this->c = c;
  51. }
  52.  
  53. void prt(){
  54. for(int x : p) cout << x << " ";
  55. cout << endl;
  56. }
  57.  
  58. int first_occ(string x){
  59. int l = 0, r = n-1, ans = -1;
  60. while(l <= r){
  61. int mid = (l + r)/2;
  62. string sub = s.substr(p[mid], min(s.length() - p[mid], x.length()));
  63. if(sub >= x){
  64. if(sub == x) ans = mid;
  65. r = mid-1;
  66. } else {
  67. l = mid+1;
  68. }
  69. }
  70. return ans;
  71. }
  72.  
  73. bool exist(string x){
  74. int l = 0, r = n-1, ans = -1;
  75. while(l <= r){
  76. int mid = (l + r)/2;
  77. string sub1 = s.substr(p[mid], s.length() - p[mid]);
  78. string sub = sub1.substr(0, min(sub1.length(), x.length()));
  79. if(sub >= x){
  80. if(sub == x) ans = mid;
  81. r = mid-1;
  82. } else {
  83. l = mid+1;
  84. }
  85. }
  86. return (ans != -1);
  87. }
  88.  
  89. };
  90.  
  91. char buf[300010];
  92.  
  93. string read(){
  94. scanf("%s", buf);
  95. return buf;
  96. }
  97.  
  98. int main(){
  99.  
  100. string s = read();
  101. suffix_array suf(s);
  102.  
  103. int q;
  104. scanf("%d", &q);
  105. while(q--){
  106. string x = read();
  107. puts(suf.exist(x) ? "Yes" : "No");
  108. }
  109.  
  110.  
  111. }
  112.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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
stdout
Standard output is empty