B1012 [JSOI2008]最大数maxnumber 分块||RMQ
这个题有毒,卡最大值。。。我开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的更多相关文章
- 大视野 1012: [JSOI2008]最大数maxnumber(线段树/ 树状数组/ 单调队列/ 单调栈/ rmq)
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 9851 Solved: 4318[Submi ...
- BZOJ 1012: [JSOI2008]最大数maxnumber 单调队列/线段树/树状数组/乱搞
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 4750 Solved: 2145[Submi ...
- BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 8748 Solved: 3835[Submi ...
- BZOJ-1012[JSOI2008]最大数maxnumber 线段树区间最值
这道题相对简单下面是题目: 1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MB Submit: 6542 Solve ...
- 【bzoj1012】[JSOI2008]最大数maxnumber
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 8339 Solved: 3624[Submi ...
- Cogs 1844. [JSOI2008]最大数maxnumber
[JSOI2008]最大数maxnumber ★★ 输入文件:bzoj_1012.in 输出文件:bzoj_1012.out 简单对比 时间限制:3 s 内存限制:162 MB [题目描述] 现在请求 ...
- BZOJ 1012: [JSOI2008]最大数maxnumber【线段树单点更新求最值,单调队列,多解】
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 10374 Solved: 4535[Subm ...
- [JSOI2008]最大数maxnumber
[JSOI2008]最大数maxnumber 标签: 线段树 单独队列 题目链接 题解 线段树裸题. 如果一直RE可能是你用的cin/cout. Code #include<cstdio> ...
- bzoj 1012: [JSOI2008]最大数maxnumber (线段树)
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 13081 Solved: 5654[Subm ...
随机推荐
- (转)JavaScript深入之从原型到原型链
构造函数创建对象 我们先使用构造函数创建一个对象: function Person() { } var person = new Person(); person.name = 'Kevin'; co ...
- JDBC: 批量处理提高SQL处理速度
引用:忘了 当需要成批插入或者更新记录时.可以采用Java的批量更新机制,这一机制允许多条语句一次性提交给数据库批量处理.通常情况下比单独提交处理更有效率 JDBC的批量处理语句包括下面两个方法: a ...
- 华为 荣耀 等手机解锁BootLoader
下载工具按提示操作即可 链接:https://pan.baidu.com/s/1qZezd1q 密码:8pad 备用链接:https://pan.baidu.com/s/1nwv0heD
- 【Oracle】DG中物理备库、快照备库的相互转换
一.物理备库切换快照备库 1. 如果正在运行日志应用,先停止 ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL; 2. 确保数据库为MOUN ...
- CNN结构:用于检测的CNN结构进化-结合式方法
原文链接:何恺明团队提出 Focal Loss,目标检测精度高达39.1AP,打破现有记录 呀 加入Facebook的何凯明继续优化检测CNN网络,arXiv 上发现了何恺明所在 FAIR 团 ...
- Python字典 day2
一.字典 1.字典的特点: 一系列键-值对(key-value),字典用放在花括号{ }中的一系列键值对表示; 字典中有多个元素时需要用逗号,隔开: key不能重复: 字典是无序的. 字典的优点:字典 ...
- jdk8时间格式处理
SimpleDateFormat 是线程不安全的类,一般不要定义为 static 变量,如果定义为 static,必须加锁,或者使用 DateUtils 工具类. 正例:注意线程安全,使用 DateU ...
- 63.es中的type数据类型
主要知识点 理解es中的type数据类型 一.type的理解 type是一个index中用来区分类似的数据的,但是可能有不同的fields,而且有不同的属性来控制索引建立.分词器.field的 ...
- Java 集合之Collection 接口和遍历方法
这几篇是我按网上的教程来实习的. URL: http://www.cnblogs.com/jbelial/archive/2013/03/27/2981395.html 打代码的感觉挻好的.. 注意在 ...
- asp.net--CRSF
asp.net使用了token来防止CRSF攻击 前台: 使用@Html.AntiForgeryToken(); 浏览器里面被存了一个cookie值,这个值是asp.net存给浏览器的,是readon ...