BZOJ 1012: [JSOI2008]最大数maxnumber 单调队列/线段树/树状数组/乱搞

1012: [JSOI2008]最大数maxnumber

Time Limit: 3 Sec  Memory Limit: 162 MB
Submit: 4750  Solved: 2145
[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如上文中所述,满足(0

Output

对于每一个查询操作,你应该按照顺序依次输出结果,每个结果占一行。

Sample Input

5 100
A 96
Q 1
A 97
Q 1
Q 2

Sample Output

96
93
96

HINT

题解:

这道题就是裸的rmq题目,我推荐一种单调队列的搞法!

搞搞搞,看代码就知道肿么做啦~

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 250001
#define eps 1e-9
const int inf=0x7fffffff; //无限大
//**************************************************************************************
int a[maxn],max_num[maxn],t=,ans=;
int main()
{
int n,d;
scanf("%d%d",&n,&d);
char ch[];
int g;
while(n--)
{
scanf("%s%d",ch,&g);
if(ch[]=='A')
{
a[++t]=(ans+g)%d;
for(int i=t;i;i--)
{
if(max_num[i]<a[t])
max_num[i]=a[t];
else
break;
}
}
else
{
ans=max_num[t-g+];
printf("%d\n",ans);
}
}
return ;
}
上一篇:CentOS7 下 安装 supervisor以及使用


下一篇:对list代理扩展功能