Pagini recente » Cod sursa (job #2192991) | Cod sursa (job #216847) | Cod sursa (job #3217670) | Cod sursa (job #1769006) | Cod sursa (job #1697018)
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
ifstream in("trie.in");
ofstream out("trie.out");
typedef trie<
string,
null_type,
trie_string_access_traits<>,
pat_trie_tag,
trie_prefix_search_node_update>
pref_trie;
unordered_map<string, int> mp;
int main() {
int T,n,m,t;
char Q;
string x;
pref_trie base;
while(!in.eof()) {
in >> T >> x;
if(in.eof())
break;
if(T == 0) {
base.insert(x);
mp[x]++;
} else if(T == 1) {
base.erase(x);
mp[x]--;
} else if(T == 2) {
out << mp[x] << '\n';
} else {
int i = 0;
for(i = 0; i < x.size(); i++) {
auto range = base.prefix_range(x.substr(0, i));
if(range.first == range.second)
break;
}
out << i-1 << '\n';
}
}
}