TLE&&WA32求调
查看原帖
TLE&&WA32求调
1772213
Ahler楼主2025/7/29 19:21
#include<bits/stdc++.h>
#include<bits/extc++.h>
#define cen cout << endl
using namespace std;
using namespace __gnu_pbds;
void f(){
    map<string,int> mp;
    trie<string, null_type, trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> t;
    int n,q;
    cin >> n >> q;
    string str;
    for(int i=0;i<n;i++){
        cin >> str;
        t.insert(str);
    }
    while(q--){
        cin >> str;
        if(mp[str]){
            cout << mp[str];
            cen;
            continue;
        }
        auto temp=t.prefix_range(str);
        int sum=distance(temp.first,temp.second);
        cout << sum;
        cen;
        mp[str]=sum;
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while(t--){
        f();
    }
    return 0;
}
/*

*/

是使用pbds本身就会TLE吗

2025/7/29 19:21
加载中...