From 41e5ac636c43dd8cfe3307b84214e9a105b79b69 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Mon, 30 Nov 2020 19:22:56 +0800 Subject: [PATCH] =?UTF-8?q?P1198=20[JSOI2008]=E6=9C=80=E5=A4=A7=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R42912514 --- problem/P1198/P1198.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 problem/P1198/P1198.cpp diff --git a/problem/P1198/P1198.cpp b/problem/P1198/P1198.cpp new file mode 100644 index 00000000..920bd54e --- /dev/null +++ b/problem/P1198/P1198.cpp @@ -0,0 +1,40 @@ +#include + +using namespace std; + +long long t, d, a[200005], f[200005][25]; +int n, m, x; +char op; +bool flag; + +void change(int u) { + f[u][0] = a[u]; + for (int i = 1; u - (1 << i) >= 0; i++) { + f[u][i] = max(f[u][i - 1], f[u - (1 << (i - 1))][i - 1]); + } +} + +long long find(int x, int y) { + int d = (int)(log(y - x + 1) / log(2)); + return max(f[y][d], f[x + (1 << d) - 1][d]); +} + +int main() { + cin >> m >> d; + while (m--) { + cin >> op >> x; + if (op == 'A') { + a[++n] = (x + t) % d; + change(n); + } + else if (op == 'Q') { + if (x == 1) { + cout << (t = a[n]) << endl; + } + else { + cout << (t = find(n - x + 1, n)) << endl; + } + } + } + return 0; +}