The maximum number (point changes, for the most value

# The meaning of problems

Only the initial numbers m, m representing a query Q operations after the maximum sequence number L, A t represents a number plus the sequence length becomes n + 1,

The number is added (t + a) mod p, a is the value of a query

# Explanations

Segment tree operation can only be updated up properties, and additionally recording the number of array values ​​previous query

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int N=2e5+10;
 4 struct node{
 5     int l,r;
 6     int v;
 7 }tr[4*N];
 8 
 9 inline void push_up(int u){//从下向上更新信息
10     tr[u].v=max(tr[u<<1].v,tr[u<<1|1].v);
11 }
12 //void push_down(int u){// delay marker, from the downward update
 13 is  
14  // } 
15 inline void Build ( int U, int L, int R & lt) {
 16      TR [U] .L = L, TR [U] .r = R & lt;
 . 17      IF (L == R & lt) {
 18 is          return ;
 . 19      }
 20 is      int MID = L + R & lt >> . 1 ;
 21 is      Build (U << . 1 , L, MID);
 22 is      Build (U << . 1 | . 1 , MID + . 1 , R & lt);
 23 is  }
 24 inlinevoid change(int u,int x,int v){ // 单点修改将a[x]值改为v
25     if(tr[u].l==x && tr[u].r ==x){
26         tr[u].v=v;
27     }
28     else{
29         int mid=tr[u].l+tr[u].r>>1;
30         if(x <= mid) change(u<<1,x,v);
31         else change(u<<1|1,x,v);
32         push_up(u);
33     }
34 }
35inline int ASK ( int U, int L, int R & lt) {
 36      IF (TR [U] .L> && TR = L [U] .r <= R & lt) return TR [U] .v;
 37 [      int MID = TR [U] .L + TR [U] .r >> . 1 ;
 38 is      int V = 0 ; // negative infinity 
39      IF (L <= MID) // midpoint of the left point to the right of 
40          V = ASK (U << . 1 , L, R & lt);
 41 is      IF (R & lt> MID) // midpoint at the right point on the left 
42 is          V max = (V, ASK (U << . 1 | . 1 , L, R & lt));
 43 is     return v;
44 }
45 int m,p;
46 int main(){
47     cin>>m>>p;
48     int n=0,last=0;
49     build(1,1,m);
50     int x;
51     string op;
52     while(m--) {
53         cin >> op >> x;
54         if(op[0]=='Q'){
55             last=ask(1,n-x+1,n);
56             cout<<last<<endl;
57         }
58         else {
59             change(1,n+1,(x+last)%p);
60             n++;
61         }
62     }
63 
64 }

 

Guess you like

Origin www.cnblogs.com/hhyx/p/12459979.html
Recommended