Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // #### Zeinab
- #include<bits/stdc++.h>
- using namespace std;
- #define nl "\n"
- #define fi first
- #define se second
- #define pb push_back
- #define ll long long
- #define RV return void
- #define sz(x) int(x.size())
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define cin(v) for(auto&x:v) cin >> x;
- #define cout(v) for(auto&x:v) cout << x << " ";
- map < pair < int , int > , int > mp;
- struct Trie{
- Trie * nxt[26];
- Trie(){
- memset(nxt, 0, sizeof nxt);
- }
- void insert(string s){
- int idx=0;
- Trie *temp = this;
- for(int i = sz(s) -1 ; i >=0 ; i--){
- int t = s[i]-'a';
- if(!temp->nxt[t]){
- temp->nxt[t] = new Trie();
- }
- temp = temp -> nxt[t];
- idx++;
- mp[{idx,t}]++;
- }
- }
- void del(string s){
- int idx=0;
- Trie *temp = this;
- for(int i = sz(s) -1 ; i >=0 ; i--){
- int t = s[i]-'a';
- temp = temp -> nxt[t];
- idx++;
- mp[{idx,t}]--;
- }
- }
- };
- void solve(){
- Trie root;
- int n,op , idx , k , len;
- cin >> n;
- mp.clear();
- vector < string > q(n);
- vector < bool >vis(n,0);
- for(int i =0 ; i < n ; i++){
- cin >> op;
- if(op==1){
- cin >> q[i];
- root.insert(q[i]);
- }
- else if(op==2){
- cin >> k >> len ;
- bool ok= false;
- for(int i =0 ; i < 26 ; i++){
- if(mp[{len,i}] >= k){
- ok=true;
- break;
- }
- }
- cout << (ok ? "YES" : "NO") << nl;
- }
- else{
- cin >> idx;
- --idx;
- if(!vis[idx])
- root.del(q[idx]);
- vis[idx]=1;
- }
- }
- }
- int main(){
- ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
- int t=1;
- // cin >> t ;
- for(int i=1 ; i <= t ; i++){
- // cout << "Case #"<< i <<": ";
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement