[JSOI2008]最大數

來源:互聯網
上載者:User

標籤:zoj   eof   class   max   mem   amp   ==   思路   void   

題目:洛穀P1198、BZOJ1012

題目大意:要你維護一個數列,支援兩個操作:①查詢當前數列中末尾L個數裡的最大數;②讀入s,在數列尾部插入$(s+t)%D$(t是上次詢問的值,初始為0)。

解題思路:線段樹。m最大為200000,開一個線段樹,初始化為一個很小的值,然後直接插入、查詢即可。

C++ Code:

 

#include<cstdio>#include<algorithm>#include<cstring>#define N 200000using namespace std;int t=0,m,D,l,r,d[2*N+6],endd=0;char c[12];void insert(int L,int R,int o){    if(L==R){        d[o]=r;        return;    }    int m=(L+R)>>1;    if(endd<=m)insert(L,m,o<<1);else    insert(m+1,R,o<<1|1);    d[o]=max(d[o<<1],d[o<<1|1]);}int query(int L,int R,int o){    if(l<=L&&R<=r)return d[o];    int m=(L+R)>>1;    int x=0x80808080,y=0x80808080;    if(l<=m)x=query(L,m,o<<1);    if(m<r)y=query(m+1,R,o<<1|1);    return max(x,y);}int main(){    memset(d,0x80,sizeof(d));    scanf("%d%d",&m,&D);    while(m--){        scanf("%s %d",c,&r);        if(c[0]==‘A‘){            endd++;            r=(r+t)%D;            insert(1,N,1);        }else{            l=endd-r+1;            r=endd;            t=query(1,N,1);            printf("%d\n",t);        }    }    return 0;}

 

[JSOI2008]最大數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.