1 条题解
-
0大金狮 (mengqingyu) LV 10 @ 2024-7-26 11:00:20
#include <iostream> #include <stack> #include <cmath> #include <vector> #include <map> #include <string.h> #include <queue> #include <stdio.h> #include <iomanip> #include <cstdio> #include <algorithm> #define int long long using namespace std; const int N = 2e5 + 10; const int INF = 0x3f3f3f3f; int m, d, n; struct node { int l, r; int sum; }tr[N << 2]; void push_up(int u) { tr[u].sum = max(tr[u << 1].sum, tr[u << 1 | 1].sum); } void build(int u, int l, int r) { tr[u].l = l, tr[u].r = r; tr[u].sum = -1e18; if(l == r) { return ; } int mid = (l + r) >> 1; build(u << 1, l, mid); build(u << 1 | 1, mid + 1, r); } int t; void change(int u, int l, int x) { if(tr[u].l == tr[u].r && tr[u].l == l) { tr[u].sum = (x + t) % d; return ; } int mid = (tr[u].l + tr[u].r) >> 1; if(l <= mid) change(u << 1, l, x); else change(u << 1 | 1, l, x); push_up(u); } int query(int u, int l, int r) { if(l <= tr[u].l && tr[u].r <= r) { return tr[u].sum; } int ans = -1e18; int mid = (tr[u].l + tr[u].r ) >> 1; if(l <= mid) ans = max(ans, query(u << 1, l, r)); if(mid < r) ans = max(ans, query(u << 1 | 1, l, r)); return ans; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> m >> d; build(1, 1, m); while(m--) { char opt; int x; cin >> opt >> x; if(opt == 'A') { change(1, ++n, x); } if(opt == 'Q') { t = query(1, n - x + 1, n); cout << t << endl; } } return 0; }
- 1
信息
- ID
- 454
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 10
- 标签
- 递交数
- 7
- 已通过
- 3
- 上传者