How to do all can be a question. You can use a line segment tree. You can use the balance tree. Anyway, there's a lot of ways
Personal comparison of the magnetic monotone queue + binary search for the wording, constant small code less easy to understand.
The specific idea is to maintain a monotonous non-rising monotone queue, and then query in this monotone queue of two points to find just fine ~
//This problem can be regarded as a magic of the monotonous queue .//of course, there are many ways to use line tree, balance tree, tree array, etc., where the monotone queue is the most ingenious and simplest//Why is it possible to use a monotone queue for this problem? //(that is, the sequence stored in the queue must be the subscript monotone and the value is monotonous)//If each node has no subscript advantage (team early) and no numerical advantage (bigger), then obviously it can't be an answer.//and then how to query it? //obviously, using sequential lookups must be timed out.//Notice that the subscript is monotonous and satisfies the condition that you can use the two-point answer. We can use the two-point answer to find the location of the query.//(the element with the lowest subscript on the leftmost subscript of the >= query that satisfies the node)#include<deque>#include<cstdio>using namespacestd;structnode{Node (Constsize_t &a =0,Const int&b =0): Number (a), Value (b) {} size_t number; intValue;}; unsignedintM;intd;size_t Len;deque<node>S;intT;intSearch (Constsize_t &Left ) {size_t L (0), R (S.size ()), Mid; while(L <r) {Mid= L + ((r-l) >>1); if(S[mid]. Number >=Left ) R=mid; ElseL= Mid +1; } returnS[l]. Value;}intMain () {Charop[Ten]; intInput; scanf ("%u%d", &m, &D); while(m--) {scanf ("%s%d", OP, &Input); if(*op = ='A') {Input+=T; Input%=D; while(S.empty () = =false&& S.back (). Value <Input) S.pop_back (); S.push_back (Node (++Len, Input)); } Elseprintf ("%d\n", T = (S.empty ()?0: Search (Len-input +1))); } return 0;}
Bzoj 1012
Bzoj 1012 [JSOI2008] Maximum number maxnumber