| #include <bits/stdc++.h> |
| using namespace std; |
|
|
| static inline bool is_space(char c) { |
| return c==' ' || c=='\t' || c=='\n' || c=='\r' || c=='\v' || c=='\f'; |
| } |
|
|
| static vector<string> split_lines(const string &s) { |
| vector<string> lines; |
| string line; |
| for (size_t i = 0; i < s.size(); ++i) { |
| if (s[i] == '\n') { |
| lines.push_back(line); |
| line.clear(); |
| } else if (s[i] != '\r') { |
| line.push_back(s[i]); |
| } |
| } |
| if (!line.empty() || (!s.empty() && s.back()=='\n')) lines.push_back(line); |
| return lines; |
| } |
|
|
| static vector<long long> parse_ints_from_line(const string &line) { |
| vector<long long> v; |
| istringstream iss(line); |
| long long x; |
| while (iss >> x) v.push_back(x); |
| return v; |
| } |
|
|
| int main() { |
| ios::sync_with_stdio(false); |
| cin.tie(nullptr); |
|
|
| |
| std::string all; |
| { |
| std::ostringstream ss; |
| ss << cin.rdbuf(); |
| all = ss.str(); |
| } |
| if (all.empty()) return 0; |
|
|
| |
| size_t pos = 0; |
| while (pos < all.size() && is_space(all[pos])) pos++; |
| if (pos == all.size()) return 0; |
|
|
| if (all[pos] == '0' || all[pos] == '1') { |
| |
| |
| vector<string> lines = split_lines(all); |
| vector<long long> hidden_ll; |
| int n = 0; |
|
|
| for (const auto &ln : lines) { |
| auto toks = parse_ints_from_line(ln); |
| if (!toks.empty() && toks[0] == 1) { |
| hidden_ll = toks; |
| } |
| } |
| if (!hidden_ll.empty()) { |
| |
| n = (int)hidden_ll.size() - 1; |
| } else { |
| |
| return 0; |
| } |
| vector<int> hidden(n); |
| for (int i = 0; i < n; ++i) hidden[i] = (int)hidden_ll[i + 1]; |
|
|
| for (const auto &ln : lines) { |
| auto toks = parse_ints_from_line(ln); |
| if (toks.empty()) continue; |
| if (toks[0] == 0) { |
| if ((int)toks.size() < 1 + n) { |
| |
| cout << 0 << "\n"; |
| continue; |
| } |
| int match = 0; |
| for (int i = 0; i < n; ++i) { |
| if ((int)toks[i + 1] == hidden[i]) match++; |
| } |
| cout << match << "\n"; |
| } else if (toks[0] == 1) { |
| |
| |
| |
| break; |
| } |
| } |
| return 0; |
| } else { |
| |
| |
| |
| vector<long long> nums; |
| nums.reserve(1 << 16); |
| { |
| istringstream iss(all); |
| long long x; |
| while (iss >> x) nums.push_back(x); |
| } |
| if (nums.empty()) return 0; |
| size_t idx = 0; |
| long long nll = nums[idx++]; |
| if (nll <= 0 || nll > 1000000) { |
| |
| return 0; |
| } |
| int n = (int)nll; |
| vector<int> hidden(n); |
| bool hasHidden = true; |
| if (idx + (size_t)n <= nums.size()) { |
| for (int i = 0; i < n; ++i) hidden[i] = (int)nums[idx++]; |
| } else { |
| hasHidden = false; |
| } |
| if (!hasHidden) { |
| |
| cout << 1; |
| for (int i = 1; i <= n; ++i) cout << " " << i; |
| cout << "\n"; |
| return 0; |
| } |
| |
| while (idx < nums.size()) { |
| long long t = nums[idx++]; |
| if (t == 0) { |
| if (idx + (size_t)n > nums.size()) break; |
| int match = 0; |
| for (int i = 0; i < n; ++i) { |
| int qv = (int)nums[idx++]; |
| if (qv == hidden[i]) match++; |
| } |
| cout << match << "\n"; |
| } else if (t == 1) { |
| |
| if (idx + (size_t)n > nums.size()) break; |
| |
| idx += n; |
| break; |
| } else { |
| |
| break; |
| } |
| } |
| return 0; |
| } |
| } |