• luogu_1198 [JSOI2008]最大数


    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>    
    using namespace std;
    long long n,mod,a[2000010],t,cnt,y;
    
    int Max(int a,int b){
        if(a>=b)return a;
        else return b;
    }
    
    inline void update(int l,int r,int now,int v,int o){
        if(l==now && r==now){a[o]=v; return;}
        if(l==r)return;
        int mid=(l+r)>>1;
        if(mid>=now)update(l,mid,now,v,o<<1);
        else update(mid+1,r,now,v,o<<1|1);
        a[o]=Max(a[o<<1],a[o<<1|1]);
    }
    
    inline int query(int l,int r,int L,int R,int o){
        if(l>R || r<L)return -1;
        if(L<=l && r<=R)return a[o];
        int mid=(l+r)>>1;
        int q1=query(l,mid,L,R,o<<1);
        int q2=query(mid+1,r,L,R,o<<1|1);
        if(q1==-1)return q2;
        if(q2==-1)return q1;
        return Max(q1,q2);
    }
    
    int main(){
        long long k=0;
        scanf("%lld%lld",&n,&mod);
        while((1<<k)<n)k++;
        k=1<<k;
        while(n--){
            char x;
            x=getchar();
            while(x!='A' && x!='Q')x=getchar();
            if(x=='A'){
                scanf("%lld",&y); y=(y+t)%mod;
                cnt++;
                update(1,k,cnt,y,1);
            }
            else if(x=='Q'){
                scanf("%lld",&y);
                t=query(1,k,cnt-y+1,cnt,1);
                printf("%lld
    ",t);
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    关于页面跳转
    javascript之继承
    ubuntu+mysql+php+apache2+wordpress建站全记录
    Vue双向绑定原理解析
    Excel导入
    Excel文件下载(导出)
    IDEA创建Activiti工作流(集成的方式,生成表)
    git基本操作
    git中分支操作
    整合dubbo的依赖
  • 原文地址:https://www.cnblogs.com/codetogether/p/7642731.html
Copyright © 2020-2023  润新知