有没有人帮忙看看为什么全RE?

P8306 【模板】字典树

Snow_Dog7 @ 2023-12-04 18:29:13

#include <bits/stdc++.h>
using namespace std;

long long tree[11451][100];
long long T,n,q;
long long now;
long long jh[114514];

int push_char(char x){
    if(x >= 'A' && x <= 'Z') return x - 'A';
    else if(x >= 'a' && x <= 'z') return x - 'a' + 26;
    else return x - '0' + 52;
} 

int find(char s[]) {
    long long v = 0;
    for (long long i = 0;i < strlen(s);i++) {
        long long temp = push_char(s[i]);
        if (!tree[v][temp]) return 0;
        v = tree[v][temp];
    }
    return jh[v];
}

int main ( ) {
    ios::sync_with_stdio(0);
    cin >> T ;
    while (T--) {
        for(int i = 0;i <= now;i++)
            for(int j = 0;j <= 69;j++) tree[i][j] = 0;
        for(int i = 0;i <= now;i++) jh[i] = 0;
        cin >> n >> q ;
        char s[114514];
        for (long long i = 1;i <= n;i++) {
            cin >> s;
            long long v = 0;
            for (long long i = 0;i < strlen(s);i++) {
                long long temp = push_char(s[i]);
                if (!tree[v][temp]) tree[v][temp] = ++now;
                v = tree[v][temp];
                jh[v]++;
            }
        }
        for (long long i = 1;i <= q;i++) {
            cin >> s;
            cout << find(s) << '\n' ;
        }
    }
} 

by mathcode @ 2023-12-04 19:53:46

tree数组和jh数组要开到3e6啊


by Snow_Dog7 @ 2023-12-05 18:14:46

谢谢,很难形容我现在的心情 @mathcode


|