bzoj1012: [JSOI2008]最大數maxnumber

來源:互聯網
上載者:User

標籤:

簡單線段樹,然而開始cnt忘了初始化。注意初始化注意初始化

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;#define rep(i,n) for(int i=1;i<=n;i++)#define lson l,m,x<<1#define rson m+1,r,x<<1|1#define ll long longconst int inf=0x7f7f7f7f;const int nmax=200005;int Max[nmax<<2];void update(int p,int add,int l,int r,int x){if(l==r) {Max[x]=add;return ;}int m=(l+r)>>1;p<=m?update(p,add,lson):update(p,add,rson);Max[x]=max(Max[x<<1],Max[x<<1|1]);}int query(int tl,int tr,int l,int r,int x){if(tl<=l&&tr>=r) return Max[x];int m=(l+r)>>1,ans=-1;if(tl<=m) ans=max(ans,query(tl,tr,lson));if(tr>m) ans=max(ans,query(tl,tr,rson));return ans;}int main(){int n;ll mod;scanf("%d %lld",&n,&mod);char ch[10];ll u;int tmp=0,cnt=0;rep(i,n){scanf("%s%lld",ch,&u);if(ch[0]==‘A‘) cnt++,update(cnt,(u+tmp)%mod,1,n,1);else printf("%d\n",tmp=query(cnt-u+1,cnt,1,n,1));}return 0;}

  

1012: [JSOI2008]最大數maxnumberTime Limit: 3 Sec  Memory Limit: 162 MB
Submit: 7859  Solved: 3411
[Submit][Status][Discuss]Description

  現在請求你維護一個數列,要求提供以下兩種操作:1、 查詢操作。文法:Q L 功能:查詢當前數列中末尾L
個數中的最大的數,並輸出這個數的值。限制:L不超過當前數列的長度。2、 插入操作。文法:A n 功能:將n加
上t,其中t是最近一次查詢操作的答案(如果還未執行過查詢操作,則t=0),並將所得結果對一個固定的常數D取
模,將所得答案插入到數列的末尾。限制:n是非負整數並且在長整範圍內。注意:初始時數列是空的,沒有一個
數。

Input

  第一行兩個整數,M和D,其中M表示操作的個數(M <= 200,000),D如上文中所述,滿足D在longint內。接下來
M行,查詢操作或者插入操作。

Output

  對於每一個詢問操作,輸出一行。該行只有一個數,即序列中最後L個數的最大數。

Sample Input5 100
A 96
Q 1
A 97
Q 1
Q 2Sample Output96
93
96HINT

 

  資料如下http://pan.baidu.com/s/1i4JxCH3

 

Source [Submit][Status][Discuss]

bzoj1012: [JSOI2008]最大數maxnumber

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.