Topic Portal
1. Segment Tree
Line tree can be engaged.
But slow death 1300+ms.
1#include <cstdio>2#include <iostream>3 4 using namespacestd;5 6 intm, N, POS, QL, QR;7 Long Longc[2000001], X, D, t;8 Chars;9 Ten voidBuildintOintLintR) One { AC[o] =-2147283647; - if(L = = r)return; - intMid = (L + r)/2; theBuild (O *2, L, mid); -Build (O *2+1, Mid +1, R); - } - + voidUpdateintOintLintR) - { + if(L = =R) A { atC[o] =x; - return; - } - intMid = (L + r)/2; - if(POS <= mid) update (O *2, L, mid); - ElseUpdate (O *2+1, Mid +1, R); inC[o] = max (C[o *2], C[o *2+1]); - } to + intQueryintOintLintR) - { the if(QL <= l && r <= qr)returnC[o]; * intMid = (L + r)/2, ans =-2147283647; $ if(QL <= mid) ans = max (ans, query (o *2, L, mid));Panax Notoginseng if(Qr > mid) ans = max (ans, query (o *2+1, Mid +1, R)); - returnans; the } + A intMain () the { + intI, J; -scanf"%d%d", &m, &d); $Build1,1, m); $ for(i =1; I <= m; i++) - { -scanf"%s%d", &s, &x); the if(s = ='A') - {Wuyix = (x + t)%D; thepos++; -Update1,1, m); Wu } - Else About { $QL = Pos-x +1; -QR =Pos; -t = query (1,1, m); -printf"%d\n", T); A } + } the return 0; -}
View Code
2. Monotonic Stacks
The monotonic stack is fast and the code is small.
300+ms
1# include <iostream>2# include <cstdio>3# include <cstring>4# include <string>5# include <cmath>6# include <vector>7# include <map>8# include <queue>9# include <cstdlib>Ten# include <algorithm> One# define MAXN200001 A using namespacestd; - - intm, D, T, Len; the inttop, S[MAXN], A[MAXN]; - - intMain () - { + intI, J, X, y; - Charc[1]; +scanf"%d%d", &m, &d); A while(m--) at { -scanf"%s%d", C, &x); - if(c[0] =='A') - { -x = (x + t)%D; -A[++len] =x; in while(Top && A[s[top]] <= x) top--; -S[++top] =Len; to } + Else - { they = Lower_bound (s +1, S + top +1, Len-x +1) -s; *printf"%d\n", t =A[s[y]]); $ }Panax Notoginseng } - return 0; the}
View Code
[JSOI2008] Maximum number