1012: [JSOI2008]最大数maxnumber

Time Limit: 3 Sec  Memory Limit: 162 MB
Submit: 10374  Solved: 4535
[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如上文中所述,满足D在longint内。接下来
M行,查询操作或者插入操作。

Output

  对于每一个询问操作,输出一行。该行只有一个数,即序列中最后L个数的最大数。

Sample Input

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

Sample Output

96
93
96

HINT

  数据如下http://pan.baidu.com/s/1i4JxCH3

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1012

分析:线段树,,,,,我可能又是智障了,调了俩个小时,一个update写错一个细节,WA了三发,然后一直Re,mmp,开80W数组都不够?开了个270W的数组才过,这题目有毒!这题其实也很简单,先建一棵树,结点都为空,然后记录下插入的数的个数为cnt,逐个插入,每次询问cnt-l+1到cnt的最大值即可!

下面给出AC代码:

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=;
#define inf 0x7fffffff
inline int read()
{
int x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')
f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
inline void write(int x)
{
if(x<)
{
putchar('-');
x=-x;
}
if(x>)
write(x/);
putchar(x%+'');
}
struct Tree
{
int L,R,maxn;
}tree[N<<];
inline void buildtree(int l,int r,int pos)
{
tree[pos].L=l;
tree[pos].R=r;
tree[pos].maxn=-inf;
if(l==r)
return;
int mid=(l+r)/;
buildtree(l,mid,pos*);
buildtree(mid+,r,pos*+);
}
inline int Query(int l,int r,int pos)
{
if(tree[pos].L==l&&tree[pos].R==r)
return tree[pos].maxn;
int mid=(tree[pos].L+tree[pos].R)/;
if(r<=mid)
return Query(l,r,pos*);
else if(l>mid)
return Query(l,r,pos*+);
else return max(Query(l,mid,pos*),Query(mid+,r,pos*+));
}
inline void update(int l,int r,int pos)
{
if(tree[pos].L==tree[pos].R)
{
tree[pos].maxn=r;
return;
}
int mid=(tree[pos].L+tree[pos].R)/;
if(l<=mid)
update(l,r,pos*);
else update(l,r,pos*+);
tree[pos].maxn=max(tree[pos*].maxn,tree[pos*+].maxn);
}
int m,mod,last,cnt;
int main()
{
m=read();
mod=read();
buildtree(,m,);
for(int i=;i<=m;i++)
{
char ch[];
scanf("%s",ch);
int x;
if(ch[]=='A')
{
cnt++;
x=read();
x=(x+last)%mod;
update(cnt,x,);
}
else
{
x=read();
last=Query(cnt-x+,cnt,);
printf("%d\n",last);
}
}
return ;
}

似乎可以用单调队列写?

贴个AC代码:

 #include <bits/stdc++.h>
using namespace std;
const int maxn=;
int m,d,a[maxn<<],t,maxx[maxn<<],l,p;
char q[];
int main()
{
scanf("%d%d",&m,&d);
while(m--)
{
scanf("%s%d",q,&p);
if(q[]=='A')
{
a[++t]=(l+p)%d;
for(int i=t;i;i--)
{
if(maxx[i]<a[t])
maxx[i]=a[t];
else break;
}
}
else printf("%d\n",l=maxx[t-p+]);
}
return ;
}

BZOJ 1012: [JSOI2008]最大数maxnumber【线段树单点更新求最值,单调队列,多解】的更多相关文章

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

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

  2. BZOJ 1012: [JSOI2008]最大数maxnumber 线段树

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1012 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作.语法:Q L 功能: ...

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

    题目链接: 1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MB Description 现在请求你维护一个数列,要 ...

  4. 1012: [JSOI2008]最大数maxnumber 线段树

    https://www.lydsy.com/JudgeOnline/problem.php?id=1012 现在请求你维护一个数列,要求提供以下两种操作:1. 查询操作.语法:Q L 功能:查询当前数 ...

  5. HDU 1754 I Hate It 线段树单点更新求最大值

    题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...

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

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

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

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

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

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

  9. 【HDU】1754 I hate it ——线段树 单点更新 区间最值

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. iOS Swift 模块练习/swift基础学习

    SWIFT项目练习     SWIFT项目练习2 iOS Swift基础知识代码 推荐:Swift学习使用知识代码软件 0.swift中的宏定义(使用方法代替宏) 一.视图  +控件 1.UIImag ...

  2. ABP 找不到版本为 (>= 1.0.0-preview1-27891) 的包 Microsoft.AspNetCore.SignalR 错误

    错误描述: 下载ABP模板项目3.4.1的版本(当前最新版本),编译加载nuget包Microsoft.AspNetCore.SignalR时会报如下错误: 严重性     代码         说明 ...

  3. strtus2中的default-action-ref无效的解决方法

    strtus2中的default-action-ref的作用是我们在浏览器中访问错误的地址时可以跳转到自己设置的错误页面,而不是令人尴尬的系统错误页面,这个系统错误很常见,就是提示在namespace ...

  4. 如何检测mvc性能和sql语句

    mvc中使用linq如何检测sql语句 .net中使用mvc开发已经是一种趋势,不仅仅是.net ,java 等越来越多的开发者更倾向于mvc这种开发模式,在.net mvc 使用linq非常方便,各 ...

  5. Node.js平台的一些使用总结

    Node.js的安装 菜鸟教程 npm -v查看npm的版本. npm更新 npm官网 npm权限问题 由于npm经常会因为权限问题,不能全局安装模块,所以解决办法如下: npm官网 npm切换淘宝源 ...

  6. JMeter常见错误解决方法

    1.Windows 平台,双击 jmeter/bin 目录下 jmeter.bat 文件,jmeter 无法启动且报错如下: 此问题是没有配置 jdk 环境变量所致,配置好 jdk 环境变量即可. 2 ...

  7. Bilateral Filter

    最近在看图像风格化的论文的时候,频繁遇到 Bilateral Filter.google 一波后,发现并不是什么不得了的东西,但它的思想却很有借鉴意义. 简介 Bilateral Filter,中文又 ...

  8. 在linux环境下编译运行OpenCV程序的两种方法

    原来以为在Ubuntu下安装好了OpenCV之后,自己写个简单的程序应该很容易吧,但是呢,就是为了编译一个简单的显示图片的程序我都快被弄崩溃了. 在谷歌和上StackOverFlow查看相关问题解答之 ...

  9. perl多线程使用

    原文来自:博客园(华夏35度)http://www.cnblogs.com/zhangchaoyang 作者:Orisun <<=========================threa ...

  10. 使用performance monitor 查看 每一个cpu core的cpu time

    使用performance monitor 查看 每一个cpu core的cpu time: 打开performance monitor,添加 counter 如下 运行一段cpu bound 的代码 ...