题目来源
洛谷P1198最大数
https://www.luogu.org/problem/show?pid=1198
bzoj1012最大数maxnumber
http://www.lydsy.com/JudgeOnline/problem.php?id=1012
COGS1844最大数maxnumber
http://cogs.pro:8080/cogs/problem/problem.php?pid=1844
思路
top记录当前数列中有多少个数
num[i]数组记录i~top中的最大数
每次加入num[++top]时将小于num[top]的num[i]值均置为num[top]
询问时输出t=num[top-l+1]即可
代码(C++)
#include <cstdio>
using namespace std;
char c; long long m,d,n,top=0,num[200010],t=0;
int main()
{
//freopen("bzoj_1012.in","r",stdin);
//freopen("bzoj_1012.out","w",stdout);
scanf("%lld%lld",&m,&d);
for(int i=1;i<=m;++i)
{
scanf("%s%lld",&c,&n);
if(c=='Q')
printf("%lld\n",t=num[top-n+1]);
else
{
num[++top]=(t+n)%d;
for(int i=top-1;num[i]<num[top]&&i;--i)
num[i]=num[top];
}
}
return 0;
}