From 0d6f09eb17e135814a2fc5f689e05e0019141e80 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 19 May 2022 10:59:25 +0800 Subject: [PATCH] =?UTF-8?q?P4168=20[Violet]=E8=92=B2=E5=85=AC=E8=8B=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/76005637 --- Luogu/P4168/P4168.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Luogu/P4168/P4168.cpp diff --git a/Luogu/P4168/P4168.cpp b/Luogu/P4168/P4168.cpp new file mode 100644 index 00000000..6fee5c78 --- /dev/null +++ b/Luogu/P4168/P4168.cpp @@ -0,0 +1,53 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int n, m, a[N], b[N]; +std::vector nums; + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n >> m; + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + nums.push_back(a[i]); + } + + std::sort(nums.begin(), nums.end()); + nums.erase(std::unique(nums.begin(), nums.end()), nums.end()); + for (int i = 1; i <= n; i++) { + a[i] = std::lower_bound(nums.begin(), nums.end(), a[i]) - nums.begin(); + } + + for (int i = 1, l, r, x = 0; i <= m; i++) { + memset(b, 0x00, sizeof(b)); + + std::pair ans; + + cin >> l >> r; + l = (l + x - 1) % n + 1; + r = (r + x - 1) % n + 1; + if (l > r) std::swap(l, r); + + for (int i = l; i <= r; i++) b[a[i]]++; + + for (int i = 0; i < nums.size(); i++) { + if (b[i] > ans.first) { + ans = std::make_pair(b[i], i); + } + } + + cout << (x = nums[ans.second]) << endl; + } + + return 0; +}