/* -*- coding: utf-8 -*- * * 2372.cc: No.2372 既視感 - yukicoder */ #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 500; const int M = 6; /* typedef */ typedef deque dqs; typedef unordered_map umsi; /* global variables */ /* subroutines */ void addp(int n, dqs &pq, umsi &pmp, string &s) { pq.push_back(s); pmp[s]++; while (pq.size() > n) { string &t = pq.front(); if (--pmp[t] == 0) pmp.erase(t); pq.pop_front(); } } /* main */ int main() { int n, k, qn; scanf("%d%d%d", &n, &k, &qn); dqs pq; umsi pmp; while (qn--) { int op; scanf("%d", &op); if (op == 1) { char s[16]; scanf("%s", s); string w(s); addp(n, pq, pmp, w); } else { string ts[M]; int sum = 0, c = 0; for (int i = 0; i < M; i++) { char t[16]; int d; scanf("%s%d", t, &d); ts[i] = string(t); sum += pmp.count(ts[i]) ? min(d, k) : d; if (sum <= 60) c++; } printf("%d\n", c); for (int i = 0; i < M; i++) addp(n, pq, pmp, ts[i]); } } return 0; }