1 solutions

  • 0
    @ 2024-1-6 18:54:14

    【线段树】 最大数

    维护区间最大值,没啦!!

    Code

    #include<bits/stdc++.h>
    using namespace std;
    const int N=2e5+12;
    long long m,d,n,t,sum[N<<2],w;
    char c;
    void pushup(int x) { sum[x]=max(sum[x<<1],sum[x<<1|1]); }
    void update(int x,int l,int r,int p,int v)
    {
      if(l==r) {sum[x]=v;return;}
      int mid=l+r>>1;
      if( l<r )
      { int mid=l+r>>1;
        if( p<=mid ) update(x<<1,l,mid,p,v);
        else update(x<<1|1,mid+1,r,p,v);
      }
      pushup(x);
    }
    long long getmax(int x,int l,int r,int L,int R)
    {
      if( L<=l and r<=R ) return sum[x];
      int mid=l+r>>1;
      long long ans=0;
      if( L<=mid ) ans=getmax(x<<1,l,mid,L,R);
      if( R>mid ) ans=max(getmax(x<<1|1,mid+1,r,L,R),ans);
      return ans;
    }
    int main(){
      cin>>m>>d;
      int now=0;
      for(int i=1;i<=m;i++)
      {
        cin>>c>>w;
        if( c=='A' ) {update(1,1,m,++now,(w+t)%d);}
        else{
          t=getmax(1,1,m,now-w+1,now);
          cout<<t<<endl;
         }
      }
    }
    
    • 1

    Information

    ID
    11805
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    (None)
    # Submissions
    3
    Accepted
    2
    Uploaded By