/* -*- coding: utf-8 -*- * * 714.cc: No.714 回転寿司屋のシミュレート - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int SN = 20; /* typedef */ typedef vector vi; typedef map msi; /* global variables */ msi smap; bool used[SN]; vi vs[SN]; /* subroutines */ int getid(string &s, int &m) { msi::iterator mit = smap.find(s); if (mit != smap.end()) return mit->second; return (smap[s] = m++); } /* main */ int main() { int n; cin >> n; int m = 0; while (n--) { int op; cin >> op; if (op == 0) { int ni, mi; cin >> ni >> mi; ni--; used[ni] = true; vi &v = vs[ni]; v.resize(mi); for (int i = 0; i < mi; i++) { string s; cin >> s; int id = getid(s, m); v[i] = id; //printf("%d ", id); } sort(v.begin(), v.end()); //putchar('\n'); } else if (op == 1) { string s; cin >> s; int id = getid(s, m); //printf("%s = %d\n", s.c_str(), id); int found = -1; for (int ni = 0; found < 0 && ni < SN; ni++) if (used[ni]) { vi &v = vs[ni]; vi::iterator vit = lower_bound(v.begin(), v.end(), id); if (vit != v.end() && *vit == id) { found = ni + 1; v.erase(vit); } } printf("%d\n", found); } else { // op == 2 int ni; cin >> ni; ni--; used[ni] = false; } } return 0; }