From 3f3a5b9423fa5f471bbe6180c47722c3a4714163 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sat, 15 Jan 2022 20:33:27 +0800 Subject: [PATCH] C - The Kth Time Query https://atcoder.jp/contests/abc235/submissions/28548889 --- AtCoder/ABC235/C/C.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 AtCoder/ABC235/C/C.cpp diff --git a/AtCoder/ABC235/C/C.cpp b/AtCoder/ABC235/C/C.cpp new file mode 100644 index 00000000..7a8dfe26 --- /dev/null +++ b/AtCoder/ABC235/C/C.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +using std::cin; +using std::cout; +using std::endl; + +int n, q, a, x, k; +std::unordered_map> map; + +int main() { + std::ios::sync_with_stdio(false); + cin >> n >> q; + for (int i = 1; i <= n; i++) { + cin >> a; + map[a].push_back(i); + } + while (q--) { + cin >> x >> k; + if (!map.count(x) || map[x].size() < k) { + cout << -1 << endl; + } else { + cout << map[x][k - 1] << endl; + } + } + return 0; +}