单调栈维护下,二分就好了
bzoj用%I64d一直格式错误,换了%lld就好了
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAXN = 200100;
LL num[MAXN];
int len;
int s[MAXN];
int t;
int M;
LL D,n,pre;
int main()
{
char op;
scanf("%d %lld",&M,&D);
for(int i = 0; i < M; ++i)
{
scanf(" %c %lld",&op,&n);
if(op == 'Q')
{
int index = len-n;
index = lower_bound(s,s+t,index)-s;
pre = num[s[index]];
printf("%lld\n",num[s[index]]);
}
else
{
n = (n+pre)%D;
num[len++] = n;
while(t > 0 && num[s[t-1]] <= num[len-1])
--t;
s[t++] = len-1;
}
}
return 0;
}