您的位置:首页 > Web前端 > JavaScript

【BZOJ 1012】 [JSOI2008]最大数maxnumber

2016-03-10 19:01 573 查看
以前看过这个题 这次一遍A 真舒服

留下最大值 每次二分就行

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;
LL a[200000+1],b[200000+1];
LL n,MO;
LL tot=1;
int main()
{
//  fre0open("a.in","r",stdin);
cin>>n>>MO;LL tmp=0;
int cnt=0;
for(int i=1;i<=n;i++)
{
char c;getchar();c=getchar();
if(c=='A')
{
LL x;scanf("%lld",&x);x+=tmp;x%=MO;
while(a[tot]<=x&&tot>0) tot--;
a[++tot]=x;
b[tot]=++cnt;
}
else
{
LL x;scanf("%d",&x);
x=cnt-x+1;//cout<<a[1]<<' '<<a[2]<<endl;
int L=1,R=tot;
while(L<R)
{
int mid=(L+R)/2;
if(b[mid]<x) L=mid+1;
else R=mid;
}
tmp=a[L];
printf("%lld\n",tmp);
}

}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: