单调栈的妙处!!

刚看到这题差点写个splay。。但是后来看到询问范围的只是后L个数,因为当有一个数新进来且大于之前的数时,那之前的数全都没有用了,满足这种性质的序列可用单调栈维护

栈维护下标(因为要时刻确定查询位置),最后在询问的时候,用二分找到大于等于len - l + 1的第一个位置即为最大值

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
inline int lowbit(int x){ return x & (-x); }
inline int read(){
int X = 0, w = 0; char ch = 0;
while(!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
while(isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
return w ? -X : X;
}
inline int gcd(int a, int b){ return a % b ? gcd(b, a % b) : b; }
inline int lcm(int a, int b){ return a / gcd(a, b) * b; }
template<typename T>
inline T max(T x, T y, T z){ return max(max(x, y), z); }
template<typename T>
inline T min(T x, T y, T z){ return min(min(x, y), z); }
template<typename A, typename B, typename C>
inline A fpow(A x, B p, C yql){
A ans = 1;
for(; p; p >>= 1, x = 1LL * x * x % yql)if(p & 1)ans = 1LL * x * ans % yql;
return ans;
}
const int N = 200005;
int s[N], tot, num[N];
int main(){ int m = read(), d = read(), t = 0, len = 0;
while(m --){
char opt; scanf("%c", &opt);
if(opt == 'A'){
int x = read();
x = (x + t) % d;
num[++len] = x;
while(tot > 0 && num[s[tot]] <= x) tot --;
s[++tot] = len;
}
else if(opt == 'Q'){
int l = read();
int index = lower_bound(s + 1, s + tot + 1, len - l + 1) - s;
t = num[s[index]];
printf("%d\n", t);
}
}
return 0;
}

BZOJ1012 最大数maxnumber的更多相关文章

  1. bzoj1012最大数maxnumber——单调栈

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1012 单调栈水题:用了一下lower_bound二分. 代码如下: #include< ...

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

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

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

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

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

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

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

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

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

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

  7. 【BZOJ】【1012】【JSOI2008】最大数maxnumber

    线段树 ……现在再来看这题感觉好水啊,当年的大老虎现在也变成小花猫了,真是令人感动<_< /************************************************ ...

  8. 【单调栈】Bzoj 1012: 最大数maxnumber

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

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

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

随机推荐

  1. poj3984 广度搜索BFS

      迷宫问题 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1 ...

  2. VO和DO转换(四) MapStruct

    VO和DO转换(一) 工具汇总 VO和DO转换(二) BeanUtils VO和DO转换(三) Dozer VO和DO转换(四) MapStruct MapStruct

  3. 架构 规则引擎 quartz

    通向架构师的道路(第五天)之tomcat集群-群猫乱舞-云栖社区-阿里云https://yq.aliyun.com/articles/259343 商业规则引擎和开源规则引擎的测试对比 - qq_39 ...

  4. 2 Servlet 细节

    1 Servlet 配置详解 ①  由于客户端在浏览器只能通过URL访问web服务器的资源,所以Servlet程序若想被外界访问,必须把Servlet 程序映射到一个URL 地址上,这个工作在项目we ...

  5. spark、standalone集群 (2)集群zookeeper 热备

     测试 cmd     spark-examples-1.6.0-hadoop2.6.0.jar   spark 2.0以后  就没有这个 jar.需要下载 ./bin/spark-submit -- ...

  6. Java8 Lambda和Stream的用法

    package com.zhangxueliang.demo; import java.util.ArrayList; import java.util.List; import java.util. ...

  7. Oracle创建表sql语句

    create table t_owners ( id number primary key, name ), addressid number, housenumber ), watermeter ) ...

  8. IntelliJ IDEA使用教程(非常全面)

    这个编辑器我就不再多做介绍了.直接开始新建maven hello world 的Java web项目啦 你电脑上得有jdk1.7,或者1.8,然后就是maven3.x吧,再有就是tomcat7以上吧. ...

  9. 过滤数组中的空数组array_filter()

    手册查询array_filter()的使用细节时,看到了:If no callback is supplied, all entries of input equal to FALSE (see co ...

  10. APP-SERVICE-SDK:setStorageSync:fail;at page/near/pages/shops/shops page lifeCycleMethod onUnload function

    APP-SERVICE-SDK:setStorageSync:fail;at page/near/pages/shops/shops page lifeCycleMethod onUnload fun ...