pbds中hash_table
libohan0905 · · 个人记录
hash_table食用方法
引入头文件:
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
命名空间:
using namespace __gnu_pbds;
定义:
gp_hash_table<string,int>h;
或者
cc_hash_table<string,int>h;
使用:
h["abcde"]=12345;
A:它能干嘛呢?
B:就和map差不多,支持[ ]和find
A:那不如直接用map了
B:不不不,map的总时间复杂度是 O(nlogn) 的,而hash_table的总时间复杂度仅为 O(n)
比如:
P3879 [TJOI2010] 阅读理解
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
cc_hash_table<string,bitset<1005> >cch;
string s;
int main() {
int n,m;
cin>>n;
for(int i=1; i<=n; i++) {
int l;
cin>>l;
for(int j=1; j<=l; j++) {
cin>>s;
cch[s][i]=1;
}
}
cin>>m;
while(m--) {
cin>>s;
for(int i=1; i<=n; i++) {
if(cch[s][i]) cout<<i<<" ";
}
puts("");
}
}
pbds牛逼!就是背不下来