水题,每次记录一下当前有多少个数,然后按照题目所指示的那样模拟就行,每次向线段树末尾插入(其实是修改)题目中指定的数,然后询问当前的个数到前面Q个数中最大值是多少结果就是,好久不碰线段树了,用数组模拟线段树时数组要开大4倍,一开始没发现这点贡献了好多runtime_error TAT

#include<iostream>

#include<cstdio>

#include <math.h>

using namespace std;

int d;

int max(int a,int b)

{

if(a>=b)return a;else return b;

}

void insert(int node,int l,int r,int po,intvalue,int m[])

{

int mid=(l+r)>>1;

if (l+1==r){m[node]=value;return;}

else

{

if (po<=mid)insert(node*2,l,mid,po,value,m);

else insert(node*2+1,mid,r,po,value,m);

}

m[node]=max(m[node*2],m[node*2+1]);

}

int search(int node,int l,int r,int lq,intrq,int m[])

{

int mid = (l+r)>>1,temp=0;

if ((lq<=l)&&(r<=rq))return m[node];

if(lq<mid)temp=max(temp,search(node*2,l,mid,lq,rq,m));

if(rq>mid)temp=max(temp,search(node*2+1,mid,r,lq,rq,m));

returntemp;

}

int main()

{

int m,t,n[800001]={0},len=0,ans=0,ans_array[200001]={0},h=0;

char ch[5];

scanf("%d%d",&m,&d);

for (inti=1;i<=m;i++)

{

scanf("%s %d",ch,&t);

if (ch[0]=='A')

{

len++;

insert(1,0,m,len,(t+ans)%d,n);

}

if (ch[0]=='Q')

{

ans=search(1,0,m,len-t,len,n);

h++;

ans_array[h]=ans;

}

}

for (int i=1;i<=h;i++)printf("%d\n",ans_array[i]);

return 0;

}

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. BZOJ 1012: [JSOI2008]最大数maxnumber【线段树单点更新求最值,单调队列,多解】

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

  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. 【BZOJ 1012】 [JSOI2008]最大数maxnumber(线段树做法)

    [题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1012 [题意] [题解] 预开一个20W长度的线段树; 这里a[1..20W]={0} ...

随机推荐

  1. MySQL select * 和把所有的字段都列出来,哪个效率更高?

    MySQL select * 和把所有的字段都列出来,哪个效率更高 答案是:如何,都不推荐使用 SELECT * FROM (1)SELECT *,需要数据库先 Query Table Metadat ...

  2. Java中枚举类型Enum的一种使用方式

    枚举类定义如下: public enum Status { SCUUESS("1", "成功"), FAILED("2", "失败 ...

  3. mysqldumpslow及explain使用简介

  4. 融云参加RTC实时互联网大会 现场集成IM SDK

    9月21至22日,由全球实时云服务商声网Agora.io主办的RTC2017实时互联网大会在北京万豪酒店成功举办.作为亚洲最权威的RTC实时通信行业技术盛会,会议吸引了来自全球上千名开发者参加,Goo ...

  5. IOS7.1 企业应用 证书无效 已解决

    http://www.cocoachina.com/bbs/read.php?tid=194213&keyword=7.1 关于IOS7.1企业版发布后,用户通过SARAFI浏览器安装无效的解 ...

  6. win10 多桌面 win+tab | ctrl+win+左右箭头

    win10 多桌面 win+tab | ctrl+win+左右箭头

  7. python打开.pkl的文件并显示里面的内容

    pkl文件是pyhthon里面保存文件的一种格式,如果直接打开会显示一堆序列化的东西.正确的打开方式如下: import cPickle as pickle f = open('path') info ...

  8. (4)JSTL的SQL标签库

    jstl的SQL标签库 SQL tag Library中的标签用来提供在 JSP 页面中可以与数据库进行交互的功能Database access标签库有以下6组标签来进行工作: <sql:set ...

  9. shell脚本,按行读取文件的几种方法。

    第一种方法用while实现按读取文件.[root@localhost wyb]# cat a.txt 第一行 aaaaaa 第二行 bbbbbb 第三行 cccccc 第四行 dddddd 第五行 e ...

  10. KVM 重命名虚机

    KVM 重命名虚机 1. 查看虚机列表 [root@bjape01-kvm1 ~]# virsh  list --all Id    名称                         状态 --- ...