Pagini recente » Cod sursa (job #3278588) | Cod sursa (job #2646505) | Cod sursa (job #1306270) | Cod sursa (job #3189811) | Cod sursa (job #2330103)
/*
_ _ ___ ___ _ __ __
__| | __ _ / | / _ \ / _ \ (_)/ / _ \ \
/ _` | / _` | | | | | | | | | | | / / (_) | |
| (_| | | (_| | | | | |_| | | |_| | / /_ _ | |
\__,_| \__,_| |_| \___/ \___/ /_/(_) (_) | |
/_/
*/
//#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <set>
#include <algorithm>
#include <bitset>
#include <time.h>
#include <tuple>
#include <fstream>
#include <iomanip>
#include <utility>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#pragma warning "da 100% din tine. :)"
#define nl '\n'
#define cnl cout << '\n';
#define pb(x) push_back(x)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ll long long
#define ull unsigned ll
#ifdef INFOARENA
#define ProblemName "trie"
#endif
#define MCONCAT(A, B) A B
#ifdef ProblemName
#define InFile MCONCAT(ProblemName, ".in")
#define OuFile MCONCAT(ProblemName, ".out")
#else
#define InFile "a.in"
#define OuFile "a.out"
#endif
using namespace __gnu_pbds;
using namespace std;
ifstream cin(InFile);
ofstream cout(OuFile);
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;
template<class v, class type>
void print(v Vector, type nr) {
for_each(all(Vector), [](type x) {
cout << x << ' ';
});
}
#define a first
#define b second
pref_trie mytrie;
unordered_map<string, int> frecv;
int main() {
ios_base::sync_with_stdio(false);
// clock_t tStart = clock();
cin.tie(0);
int op;
string word;
while (cin >> op >> word) {
if (op == 0) {
++frecv[word];
mytrie.insert(word);
}
if (op == 3) {
int ans = 0;
for (int i = 1; i < word.length(); ++i) {
auto range = mytrie.prefix_range(word.substr(0, i));
if (range.first!=range.second)
ans = i;
}
cout << ans << nl;
}
if (op == 2) {
cout << frecv[word] << nl;
}
if (op == 1) {
auto it = mytrie.find(word);
mytrie.erase(it);
--frecv[word];
}
}
// printf("\nTime taken: %.2fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
}