用map也能卡过

P8306 【模板】字典树

liwenxi114514 @ 2024-07-13 09:33:53

#include<bits/stdc++.h>
using namespace std;
string s,ll;
int n,m,maxn,t;
map<string,int> p;
int main(){
    cin>>t;
    while(t--){
        p.clear();
        scanf("%d%d",&n,&m);
        getchar();
        string s="";
        int sum=0;
        while(1){
            char ch=getchar();
            if(ch=='\n'){
                s="";
                sum++;
                if(sum==n){
                    break;
                }
            }else{
                s+=ch;
                p[s]++;
            }
        }
        while(m--){
            string ll="";
            char ch=getchar();
            while(ch!='\n'){
                ll+=ch;
                ch=getchar();
            }
            cout<<p[ll]<<"\n";
        }
    }
    return 0;
}

记录

但是unordered_map会被卡成 O(n)


by J_Kobe @ 2024-07-13 09:58:23

%%%


by crz_qwq @ 2024-07-13 10:09:00

@liwenxi114514 %%%


by crz_qwq @ 2024-07-13 10:09:33

@liwenxi114514 %%% orz srds tlqtj jbl


by lIBsen @ 2024-07-20 10:28:09

抽象


|