注意到数列只增不减,而题目中又明确说道m<=200000;这样的数据规模线段树完全可以承受得了。所以我们可以事先建好一棵200000个子节点的线段树,然后求极值就好了。

type node=record l,r,mx:longint;end;
var i,j,m,p,x,tmp,tot:longint;
ch:char;
t:array[..] of node;
function max(x,y:longint):longint;
begin
if x>y then exit(x) else exit(y);
end;
procedure build(x,y,k:longint);
var mid:longint;
begin
with t[k] do
begin
l:=x;r:=y;
if l=r then exit;
mid:=(l+r)>>;
build(x,mid,k<<);
build(mid+,r,k<<+);
end;
end;
procedure change(x,y,k:longint);
var mid:longint;
begin
with t[k] do
begin
if l=r then
begin
mx:=y;
exit;
end;
mid:=(l+r)>>;
if x>mid then change(x,y,k<<+)
else change(x,y,k<<);
mx:=max(t[k<<].mx,t[k<<+].mx);
end;
end;
function getmx(x,y,k:longint):longint;
var mid:longint;
begin
with t[k] do
begin
if (l=x) and (r=y) then exit(mx);
mid:=(l+r)>>;
if x>mid then exit(getmx(x,y,k<<+))
else if y<=mid then exit(getmx(x,y,k<<))
else exit(max(getmx(x,mid,k<<),getmx(mid+,y,k<<+)));
end;
end;
procedure main;
begin
build(,,);
readln(m,p);tmp:=;tot:=;
for i:= to m do
begin
read(ch);
if ch='A' then
begin
readln(x);
inc(tot);
change(tot,(x+tmp) mod p,);
end
else
begin
readln(x);
tmp:=getmx(tot-x+,tot,);
writeln(tmp);
end;
end;
end;
begin
main;
end.

不过话说起来,1A的感觉真棒!

(update:ms还可以用单调栈,不过没实现过)

JSOI2008最大数(线段树)的更多相关文章

  1. [JSOI2008]最大数 (线段树)

    题目描述 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作. 语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值. 限制:L不超过当前数列的长度.(L>=0 ...

  2. [JSOI2008]最大数 线段树解法

    题目描述 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作. 语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值. 限制:L不超过当前数列的长度. 2. 插入操作 ...

  3. BZOJ1012 [JSOI2008]最大数 线段树

    题目描述 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作. 语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值. 限制:LLL不超过当前数列的长度.(L> ...

  4. P1198 最大数 线段树水题

    这道题模拟一下可以过,但是我们发现线段树也可以安全水过...... 写的线段树只需要滋磁单点修改,区间求max即可 我一开始犯了一个很SB的错误:每次插入修改了t,然后疯狂爆0到怀疑人生... 而且我 ...

  5. 洛谷 - P1198 - 最大数 - 线段树

    https://www.luogu.org/problemnew/show/P1198 要问区间最大值,肯定是要用线段树的,不能用树状数组.(因为没有逆元?但是题目求的是最后一段,可以改成类似前缀和啊 ...

  6. Luogu P1198 BZOJ 1012 最大数 (线段树)

    手动博客搬家: 本文发表于20170821 14:32:05, 原地址https://blog.csdn.net/suncongbo/article/details/77449455 URL: (Lu ...

  7. LG1198/BZOJ1012 「JSOI2008」最大数 线段树+离线

    问题描述 LG1198 BZOJ1012 题解 我们把所有操作离线,设一共有\(n\)个插入操作. 于是提前建立\(n\)个数,全部设为\(-INF\) 接着逐个处理操作即可. \(\mathrm{C ...

  8. 【BZOJ】1012: [JSOI2008]最大数maxnumber 树状数组求区间最值

    题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1012 题意:维护一个数列,开始时没有数值,之后会有两种操作, Q L :查询数列末 ...

  9. P1198 [JSOI2008]最大数【树状数组】

    题目描述 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作. 语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值. 限制: L 不超过当前数列的长度. (L &g ...

  10. P1198最大数——线段树点修改&&模板题

    题目 题目链接 大意:维护一个数列,有两种操作: 查询操作Q  L:查询当前数列中末尾L个数中的最大的数 插入操作A  n:将n加上t再对D取模,将所得值插入数列末尾 解决方案 由题意知,只有两种操作 ...

随机推荐

  1. vc终端输入结束符

    操作系统使用不同的值作为文件结束符.Windows上我们通过键入ctrl+z键作为文件结束符.Unix系统中,包括Mac OS-X机器,通常用ctrl+d作为文件结束符.用VC++6.0的时候,要输入 ...

  2. 基于Hash算法的高维数据的最近邻检索

    一.摘要 最紧邻检索:一种树基于树结构,一种是基于hash a.随机投影算法,需要产生很多哈希表,才能提高性能. b.基于学习的哈希算法在哈希编码较短时候性能不错,但是增加编码长度并不能显著提高性能. ...

  3. GetSurfaceLevel

      if( SUCCEEDED( g_pTexture->GetSurfaceLevel( 0, &pSurface) ) )    {        pd3dDevice->Se ...

  4. 【WCF--初入江湖】13 实战

    13 实战 在线升级 using System; using System.Collections.Generic; using System.ComponentModel; using System ...

  5. Unity3D Script Execution Order ——Question

    我 知道 Monobehaviour 上的 那些 event functions 是 在主线程 中 按 顺序调用的.这点从Manual/ExecutionOrder.html 上的 一张图就可以看出来 ...

  6. 让IE系列浏览器支持HTML5(share)

    引用Google的html5.js文件 <!--[if IE]> <script src=”http://html5shiv.googlecode.com/svn/trunk/htm ...

  7. hdu2013

    http://acm.hdu.edu.cn/showproblem.php?pid=2013 #include<iostream> #include<stdio.h> #inc ...

  8. [转]Ubuntu 12.04 安装屏保

    From:http://www.howtogeek.com/114027/how-to-add-screensavers-to-ubuntu-12.04/ How to Add Screensaver ...

  9. lintcode:递归打印数字

    题目 用递归打印数字 用递归的方法找到从1到最大的N位整数. 样例 给出 N = 1, 返回[1,2,3,4,5,6,7,8,9]. 给出 N = 2, 返回[1,2,3,4,5,6,7,8,9,10 ...

  10. Android:改变Activity切换方式

    overridePendingTransition(enterAnim, exitAnim); Intent intent =new Intent(this,item2.class); startAc ...