【BZOJ 1012】 [JSOI2008]最大数maxnumber

以前看过这个题 这次一遍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;
}
posted @ 2016-01-09 17:25  sxb_201  阅读(137)  评论(0编辑  收藏  举报