標籤:des ace names pen sam gre define nbsp logs
1012: [JSOI2008]最大數maxnumberTime Limit: 3 Sec Memory Limit: 162 MB
Submit: 10711 Solved: 4683
[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
/** @Author: lyuc* @Date: 2017-08-14 14:21:13* @Last Modified by: lyuc* @Last Modified time: 2017-08-14 14:48:36*/#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>#define MAXN 200005#define LL long long#define INF 0x3f3f3f3f#define lson i*2,l,m#define rson i*2+1,m+1,rusing namespace std;LL m,d;LL sum[MAXN*4];char str[2];LL t;LL n;LL tol=0;void pushup(LL i,LL l,LL r){ sum[i]=max(sum[i*2],sum[i*2+1]);}void Insert(LL key,LL val,LL i,LL l,LL r){ if(l==r){ sum[i]=val; return ; } LL m=(l+r)/2; if(m>=key) Insert(key,val,lson); else Insert(key,val,rson); pushup(i,l,r);}LL query(LL ql,LL qr,LL i,LL l,LL r){ if(ql<=l&&r<=qr){ return sum[i]; } LL m=(l+r)/2; LL res=-1; if(m>=ql) res=max(res,query(ql,qr,lson)); if(m<qr) res=max(res,query(ql,qr,rson)); return res;}void init(){ memset(sum,0,sizeof sum); tol=0; t=0;}int main(){ // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); init(); scanf("%lld%lld",&m,&d); while(m--){ scanf("%s%lld",str,&n); if(str[0]==‘A‘){ n+=t; Insert(++tol,n%d,1,1,MAXN-4); }else{ t=query(tol-n+1,tol,1,1,MAXN-4); printf("%lld\n",t); } } return 0;}
1012: [JSOI2008]最大數maxnumber