【题解】[P1198 JSOI2008]最大数

正难则反,意想不到。

这道题是动态让你维护一个数列,已经在数列里面的数据不做改变,每次在最后加上一个数,强制在线。

既然正着做很难,考虑如果时间倒流,不会改变之前的维护的任何数据结构。于是我们反着维护一个St表。

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<bitset>
#include<vector>
#include<map>
#include<ctime>
#include<cstdlib>
#include<set>
#include<bitset>
#include<stack>
#include<list>
#include<cmath>
using namespace std;
#define RP(t,a,b) for(register int (t)=(a),edd_=(b);t<=edd_;++t)
#define DRP(t,a,b) for(register int (t)=(a),edd_=(b);t>=edd_;--t)
#define ERP(t,a) for(int t=head[a];t;t=e[t].to)
#define Max(a,b) ((a)<(b)?(b):(a))
#define Min(a,b) ((a)<(b)?(a):(b))
#define TMP template<class ccf>
typedef long long ll;
TMP inline ccf qr(ccf k){
char c=getchar();
ccf x=0;
int q=1;
while(c<48||c>57)
q=c==45?-1:q,c=getchar();
while(c>=48&&c<=57)
x=x*10+c-48,c=getchar();
if(q==-1)
x=-x;
return x;
} const int maxn=2e5+15;
int n;
int top;
ll data[maxn];
ll ans[maxn][25];
int lg[maxn];
ll t1,t2,t3;
char c;
int cnt;
ll mod;
ll lastans; inline void init(){
n=qr(1);
mod=qr(1ll);
memset(ans,0xcc,sizeof ans);
RP(t,1,n+5){
lg[t]=lg[t-1];
if((1<<(lg[t]+1))==t)
lg[t]++;
}
RP(t,1,n){
cin>>c;
if(c=='A'){
data[top+1]=(qr(1ll)%mod+lastans%mod)%mod;
++top;
ans[top][0]=data[top];
RP(k,1,lg[top])
ans[top][k]=Max(ans[top][k-1],ans[top-(1<<(k-1))][k-1]);
}
else{
t1=qr(1);
lastans=Max(ans[top][lg[t1]],ans[top-t1+(1<<lg[t1])][lg[t1]]);
printf("%lld\n",lastans);
}
}
} int main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
init();
return 0;
}

【题解】[JSOI2008]最大数的更多相关文章

  1. 洛谷P1198 [JSOI2008]最大数

    P1198 [JSOI2008]最大数 267通过 1.2K提交 题目提供者该用户不存在 标签线段树各省省选 难度提高+/省选- 提交该题 讨论 题解 记录 最新讨论 WA80的戳这QwQ BZOJ都 ...

  2. [JSOI2008]最大数maxnumber

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

  3. 洛谷 P1198 [JSOI2008]最大数

    洛谷 P1198 [JSOI2008]最大数 题目描述 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作. 语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值. ...

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

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

  5. bzoj1012: [JSOI2008]最大数maxnumber(貌似是道线段树喔)

    1012: [JSOI2008]最大数maxnumber 题目:传送门 题解: 发现自己空了一道水题... 1~210000建线段树,其实就是一道裸题... 单点修改+区间查询...1A~ 代码: # ...

  6. P1198 [JSOI2008]最大数(线段树基础)

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

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

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

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

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

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

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

随机推荐

  1. IDEA阅读源码的技巧

    目录 1. 查看当前类内容 2. 查看当前类的继承体系 3. 查看当前方法的调用链 本教程仅支持 MAC 系统下的 IDEA 开发工具,如果需要 Windows 对应的操作起自行替代相应快捷键即可. ...

  2. java加载类的方法1.classloader 2.class.forName()

    java加载类的方法1.classloader 2.class.forName() 加载一个类后,是在方法去创建这个类的元信息class对象,在方法区立刻创建.在方法区创建.

  3. C# DBHelper类

    class DBHelper { //public static string connstr = "server=.;database=SuperKTV;uid=sa;pwd=123456 ...

  4. Windows脚本\批处理命令学习笔记

    1.为新建变量赋值: set 变量=值 2.输出变量的值 echo %变量% 3.关闭批处理中命令行的显示(默认是显示命令行的) 在文件開始处增加:echo off 若需又一次显示:echo on 若 ...

  5. PHP执行linux系统命令

    本文是第一篇,讲述如何在PHP中执行系统命令从而实现一些特殊的目的,比如监控服务器负载,重启MySQL.更新SVN.重启Apache等.第二篇<PHP监控linux服务器负载>:http: ...

  6. 身份证识别接口编写的JAVA调用示例

    此java文章是基本聚合数据证件识别接口来演示,基本HTTP POST请求上传图片并接收JSON数据来处理. 使用前你需要通过 https://www.juhe.cn/docs/api/id/153 ...

  7. python例子

    例一:for循环 for i in range(1,100): if i==23: print "great,%s you got your lucky number:" %(i) ...

  8. spring 官方文档

    英文 http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/ 翻译(1-6章) http:// ...

  9. 设计模式之Protocol实现代理模式

    使用场合 使用步骤 不使用protocol实现代理 使用protocol实现代理 一.使用场合 A想让B帮忙,就让B代理 A想通知B发生了一些事情,或者传一些数据给B 观察者模式 二.使用步骤 定义一 ...

  10. PHP增加$_ENV变量

    在日常开发过程中,我们常常会将一些系统或模块配写在配置文件里.这样便于程序维护与修改.通常的配置文件有.ini , .xml等.配置文件的好处在于:1,便于管理.2,可读性高.但是,使用配置文件也会有 ...