http://cogs.pro:8080/cogs/problem/problem.php?pid=1844
Luogu 的数据真zhizhang
Cogs AC
传错参数WA一下午,气炸
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; #define gc getchar() #define LL long long const LL oo = 2147483647; const int N = 2e5 + 10; LL n, Mod, Answer, tot; LL Max[N << 2]; #define lson jd << 1 #define rson jd << 1 | 1 void Build_tree(int l, int r, int jd) { Max[jd] = -oo; if(l == r) return ; int mid = (l + r) >> 1; Build_tree(l, mid, lson); Build_tree(mid + 1, r, rson); } void Poi_G(int l, int r, int jd, int x, LL num) { if(l == r) {Max[jd] = num; return ;} int mid = (l + r) >> 1; if(x <= mid) Poi_G(l, mid, lson, x, num); else Poi_G(mid + 1, r, rson, x, num); Max[jd] = max(Max[lson], Max[rson]); } void Sec_A(int l, int r, int jd, int x, int y) { if(x <= l && r <= y) {Answer = max(Answer, Max[jd]); return ;} int mid = (l + r) >> 1; if(x <= mid) Sec_A(l, mid, lson, x, y); if(y > mid) Sec_A(mid + 1, r, rson, x, y); } int main() { cin >> n >> Mod; Build_tree(1, n, 1); int m = n; while(m --) { char c; cin >> c; if(c == ‘A‘) { LL num; cin >> num; tot ++; Poi_G(1, n, 1, tot, (Answer + num) % Mod); } else { int len; cin >> len; if(!len) {cout << 0; break;} Answer = - oo; Sec_A(1, n, 1, tot - len + 1, tot); cout << Answer << endl; } } return 0; }