Pagini recente » Cod sursa (job #458691) | Cod sursa (job #1356756) | Cod sursa (job #508163) | Cod sursa (job #449601) | Cod sursa (job #2750262)
#include <bits/stdc++.h>
#define readFast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fin cin
#define ll long long
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define output(x) ((int)x && cout << "YES\n") || cout << "NO\n";
#define LSB(x) ((-x)&x)
using namespace std;
#ifdef LOCAL
#define read() ifstream fin("date.in.txt")
#else
#define read() ifstream fin("trie.in"); ofstream fout("trie.out");
#endif // LOCAL
map<string,int> fr;
map<string,int> pref;
int op;
string w;
void mark(string &s) {
while(!s.empty()) {
++pref[s];
s.pop_back();
}
}
void deMark(string &s) {
while(!s.empty()) {
--pref[s];
s.pop_back();
}
}
void afis(int x) {
read();
#ifdef LOCAL
cout << x << "\n";
#else
fout << x << "\n";
#endif // LOCAL
}
int main() {
read();
while(fin >> op >> w) {
if(op == 0) {
++fr[w];
mark(w);
}
else if(op == 1) {
--fr[w];
deMark(w);
}
else if(op == 2) {
afis(fr[w]);
}
else {
int mx = 0;
while(!w.empty()) {
if(pref[w] != 0) {
mx = max(sz(w), mx);
//cout << sz(w) << " ";
}
w.pop_back();
}
// cout << '\n';
afis(mx);
}
}
return 0;
} /*stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
~Benq~*/