建议加强数据/降(黄/橙)
查看原帖
建议加强数据/降(黄/橙)
1074084
asd890123楼主2024/5/14 17:50

本体可用set过,而且不要只卡nlogn的set,顺便也要卡一下,常数大的n的unordered_map:

#include <iostream>
#include <string>
#include <set>

int main(){
    
    std::ios::sync_with_stdio(0);
    std::cin.tie(0),std::cout.tie(0);
    
    int n,l,m;
    std::string word;
    std::set <std::string> ds[1005];
    
    std::cin >> n;
    for (int i = 1;i <= n;i++){
        
        std::cin >> l;
        while (l--) 
            std::cin >> word,ds[i].insert(word);
        
    }
    std::cin >> m;
    while (m--){
        
        std::cin >> word;
        for (int i = 1;i <= n;i++)
            if (ds[i].find(word) != ds[i].end())
                std::cout << i << ' ';
        std::cout << '\n';
        
    }
    
    return 0;
}
2024/5/14 17:50
加载中...