这个题有毒,卡最大值。。。我开1 << 30爆零让我以为我分块错了。。。gg,然后去写RMQ,但是这个题st表是真简单啊。后来刘胜与巨佬一眼看出来我最大值不够大。。。然后1LL<<60也爆零,然而1 << 60 AC,(60LL)AC,1e8爆零。。。无良数据。。。

题目:

Description

  现在请求你维护一个数列,要求提供以下两种操作:、 查询操作。语法:Q L 功能:查询当前数列中末尾L
个数中的最大的数,并输出这个数的值。限制:L不超过当前数列的长度。、 插入操作。语法:A n 功能:将n加
上t,其中t是最近一次查询操作的答案(如果还未执行过查询操作,则t=),并将所得结果对一个固定的常数D取
模,将所得答案插入到数列的末尾。限制:n是非负整数并且在长整范围内。注意:初始时数列是空的,没有一个
数。
Input   第一行两个整数,M和D,其中M表示操作的个数(M <= ,),D如上文中所述,满足D在longint内。接下来
M行,查询操作或者插入操作。
Output
  对于每一个询问操作,输出一行。该行只有一个数,即序列中最后L个数的最大数。
Sample Input A
Q
A
Q
Q
Sample Output

分块代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const long long INF = (60LL);
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
int bl,n,m,d,len = ;
ll k[];
ll a[];
char s[];
int main()
{
read(m);read(d);
bl = sqrt(m);
int t = ,l = ;
duke(i,,m)
{
ll x;
scanf("%s%lld",s,&x);
if(s[] == 'Q')
{
n = len - x + ;
if(n > (len / bl - ) * bl)
{
ll maxn = ;
duke(i,n,len)
{
if(maxn < a[i])
maxn = a[i];
}
printf("%lld\n",maxn);
t = maxn;
}
else
{
ll maxn = ;
duke(i,n / bl + ,len / bl)
{
if(maxn < k[i])
maxn = k[i];
}
duke(i,l,len)
{
if(maxn < a[i])
maxn = a[i];
}
duke(i,n,(n / bl + ) * bl)
{
if(maxn < a[i])
maxn = a[i];
}
t = maxn;
printf("%lld\n",maxn);
}
}
else
{
x += t;
if(x < )
x += d;
x %= d;
a[++len] = x;
if(len % bl == )
{
ll maxn = INF;
duke(i,l,len)
{
if(maxn < a[i])
maxn = a[i];
}
k[len / bl] = maxn;
l = len + ;
}
}
}
}
/*
9 100
A 1
A 2
A 3
A 4
A 5
Q 3
A 7
A 8
Q 4
*/
/*
5 100
A 96
Q 1
A 97
Q 1
Q 2
*/

RMQ代码:

#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#define ll long long
using namespace std;
ll a[],f[][],t,D;
int n,m;
bool flag;
void change(int u) //用change函数来进行修改
{
f[u][]=a[u];
for(int i=; u-(<<i)>=; i++) f[u][i]=max(f[u][i-],f[u-(<<(i-))][i-]);
}
ll find(int x,int y)
{
double t=log(y-x+)/log();
int K=t;
return max(f[y][K],f[x+(<<K)-][K]);
}
int main()
{
memset(f,,sizeof(f));
scanf("%d%lld",&m,&D);
for (int i=; i<=m; i++)
{
char c;
cin>>c;
ll x;
if (c=='A') //根据题面的操作,注意细节。
{
scanf("%lld",&x);
a[++n]=(x+t)%D;
change(n);
}
else
{
int L;
scanf("%d",&L);
ll ans;
if (L==)
{
printf("%lld\n",a[n]);
t=a[n];
continue;
}
ans=find(n-L+,n);
printf("%lld\n",ans);
t=ans;
}
}
return ;
}

B1012 [JSOI2008]最大数maxnumber 分块||RMQ的更多相关文章

  1. 大视野 1012: [JSOI2008]最大数maxnumber(线段树/ 树状数组/ 单调队列/ 单调栈/ rmq)

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 9851  Solved: 4318[Submi ...

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

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 4750  Solved: 2145[Submi ...

  3. BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 8748  Solved: 3835[Submi ...

  4. BZOJ-1012[JSOI2008]最大数maxnumber 线段树区间最值

    这道题相对简单下面是题目: 1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MB Submit: 6542 Solve ...

  5. 【bzoj1012】[JSOI2008]最大数maxnumber

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 8339  Solved: 3624[Submi ...

  6. Cogs 1844. [JSOI2008]最大数maxnumber

    [JSOI2008]最大数maxnumber ★★ 输入文件:bzoj_1012.in 输出文件:bzoj_1012.out 简单对比 时间限制:3 s 内存限制:162 MB [题目描述] 现在请求 ...

  7. BZOJ 1012: [JSOI2008]最大数maxnumber【线段树单点更新求最值,单调队列,多解】

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 10374  Solved: 4535[Subm ...

  8. [JSOI2008]最大数maxnumber

    [JSOI2008]最大数maxnumber 标签: 线段树 单独队列 题目链接 题解 线段树裸题. 如果一直RE可能是你用的cin/cout. Code #include<cstdio> ...

  9. bzoj 1012: [JSOI2008]最大数maxnumber (线段树)

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 13081  Solved: 5654[Subm ...

随机推荐

  1. 【java基础】(1)Java的权限修饰符(public,protected,default,private)

    访问权限修饰符权限从高到低排列是public  ,protected  ,default, private. 一.根据“是否是同包”.“是否是子类”分为4中情况+本类 5种情况 二.把 同包中的子类 ...

  2. Android高亮TextView

    HighlightTextView Android文本高亮控件,基于View实现. 特点 文本高亮 单词自动换行 高亮词组保持在同一行显示 截图 Demo Java: public class Mai ...

  3. python特性小记(一)

    一.关于构造函数和析构函数 1.python中有构造函数和析构函数,和其他语言是一样的.如果子类需要用到父类的构造函数,则需要在子类的构造函数中显式的调用,且如果子类有自己的构造函数,必然不会自动调用 ...

  4. 【Oracle】设置快速恢复区及reset快速恢复区

    快速恢复区 概念 是一个默认放置所有备份恢复操作有关文件的地方,包括:控制文件在线镜像.在线重做日志.归档日志.外来归档日志.控制文件镜像复制.数据文件镜像复制.RMAN备份片和闪回日志. 如果启用的 ...

  5. 【sqli-labs】 less3 GET - Error based - Single quotes with twist string (基于错误的GET单引号变形字符型注入)

    实质上和less1没有多大区别,看懂了一样走流程 提交参数 加单引号 http://localhost/sqli/Less-3/?id=1' 观察报错,看near 和 at 的引号之间内容 '1'') ...

  6. Centos6.6 安装Subversion服务

    一.介绍 Subversion 简称就是svn服务器,用来托管代码的,类似的还有git 1)Centos6.6 2)Subversion 二.安装 yum -y install subversion ...

  7. windows10上安装mysql详细图文教程

    在windows10上安装mysql详细图文教程   这篇文章主要介绍了在windows10上安装mysql详细图文教程,本文介绍的非常详细,具有参考借鉴价值,感兴趣的朋友一起看看吧 环境:windw ...

  8. eas之排序接口

    KDTable目前本身并不支持排序功能,但提供了排序的接口,用户通过实现该接口(ISortManager)即可实现排序的功能.同时KDTable提供了一个简单实现KDTSortManager,这个类完 ...

  9. HDU 2266 How Many Equations Can You Find(模拟,深搜)

    题目 这是传说中的深搜吗....不确定,,,,貌似更加像是模拟,,,, //我要做深搜题目拉 //实际上还是模拟 #include<iostream> #include<string ...

  10. 洛谷P1090 合并果子【贪心】

    在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.多多决定把所有的果子合成一堆. 每一次合并,多多可以把两堆果子合并到一起,消耗的体力等于两堆果子的重量之和.可以看出,所 ...