Language: C++

#include <bits/stdc++.h>
using namespace std;
template <typename T> inline void read (T &x) { bool b = 0; char c; while (!isdigit (c = getchar()) && c != '-');
if (c == '-') c = getchar(), b = 1; x = c - 48; while (isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - 48; if (b) x = -x; }
template <typename T> inline void wrip(T x) { if (x > 9) wrip(x / 10); putchar(x%10 + 48); }
template <typename T> inline void write(T x) { if (x < 0) putchar('-'), x = -x; wrip(x);}
void reads(string &s) { char c; while (!isalpha(c = getchar())); s = c; while (isalpha(c = getchar())) s += c; }
typedef const int csint;

const int N = 4e5 + 11;
int n, Nnode, child[N][26], f[N], len[N], links[N];
int index[N];
string s[100011];
inline void add(string s, int pos) {
    int node = 0;
    for (int i = 0; i < s.size(); i++) {
        if (!child[node][s[i] - 'a']) {
            child[node][s[i] - 'a'] = ++Nnode;
            len[Nnode] = len[node] + 1;
        }
        node = child[node][s[i] - 'a'];
    }
    index[node] = pos;
    f[node]++;
}
inline int Solve(string str, int id) {
    int node = 0, res = 0;
    while(1) {
        if (links[node] != node)
            node = links[node];
        res += (index[node] > 0);
        if (index[node] == id)
            break;
        int d = s[id][len[node]];
        for (int j = 0; j <= 25; j++) {
            if (str[j] == d)
                break;
            if (child[node][str[j] - 'a'])
                res += f[child[node][str[j] - 'a']];
        }
        node = child[node][d - 'a'];
    }
    return res;
}
int main() {
    #ifdef makacha
        freopen("m.inp", "r", stdin);
        freopen("m.out", "w", stdout);
    #endif // makacha
    read(n);
    for (int i = 1; i <= n; i++) {
        reads(s[i]);
        add(s[i], i);
    }
    for (int i = Nnode; i >= 0; i--)
        for (int j = 0; j <= 25; j++)
            if (child[i][j])
                f[i] += f[child[i][j]];
    for (int i = Nnode; i >= 0; i--) {
        links[i] = i;
        for (int j = 0; j <= 25; j++)
            if (child[i][j] && f[i] == f[child[i][j]])
                links[i] = links[child[i][j]];
    }
    int nquery;
    read(nquery);
    while (nquery--) {
        int k;
        string str;
        read(k);
        reads(str);
        write(Solve(str, k));
        putchar('\n');
    }
}


Compiler output:
a.cc:12:12: error: 'int index [400011]' redeclared as different kind of entity
   12 | int index[N];
      |            ^
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:121,
                 from a.cc:1:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'void add(std::string, int)':
a.cc:23:10: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   23 |     index[node] = pos;
      |          ^
a.cc: In function 'int Solve(std::string, int)':
a.cc:31:22: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   31 |         res += (index[node] > 0);
      |                      ^
a.cc:32:18: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   32 |         if (index[node] == id)
      |                  ^