水题,每次记录一下当前有多少个数,然后按照题目所指示的那样模拟就行,每次向线段树末尾插入(其实是修改)题目中指定的数,然后询问当前的个数到前面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. ThreadLocal使用,应用场景,源码实现,内存泄漏

    首先,ThreadLocal 不是用来解决共享对象的多线程访问问题的,一般情况下,通过ThreadLocal.set() 到线程中的对象是该线程自己使用的对象,其他线程是不需要访问的,也访问不到的.各 ...

  2. 运行powershell 脚本 在此系统上禁止运行脚本

    解决方法: 首次在计算机上启动 Windows PowerShell 时,现用执行策略很可能是 Restricted(默认设置). Restricted 策略不允许任何脚本运行. 若要了解计算机上的现 ...

  3. "Mac OS X"录屏幕视频并转成gif

    第一步: 使用软件QuickTime Player录屏幕视频,创建方式选择新建屏幕录制: 选择区域录制,录好保存后,就需要转gif,需要另外一个软件. 第二步: 使用GIFBrewery软件创建gif ...

  4. python 1:列表和字典

    初学Python, 对列表和字典的嵌套使用. phoneBook = [] #列表 list peopleInfo = {} #字典 dict i=0 while i<3: peopleInfo ...

  5. Fiddler模拟POST请求

    在进行接口测试时,会模拟post请求,发送不同的请求参数,返回不同的结果,今天我们就来分享一下,怎么用Fiddler工具模拟post请求: 打开Fiddler工具,在右侧点击“composer”的选项 ...

  6. ftpaccess - ftpd的配置档

    描述 DESCRIPTION 这个ftpaccess档案是用来配置下述功能的运作 存取功能(AccessCapabilities) autogroup<群组名称><类别>[&l ...

  7. Java获取2个日期里面的所有月份

    public static void main(String[] args) { String t1="2018-08-01"; t1 = t1.replaceAll(" ...

  8. 导出Excel插件——Export-CSV ---20150610

    出处:http://bbs.hcharts.cn/thread-99-1-1.html   导出Excel插件——Export-CSV 一.插件信息 插件名:Export-CSV(导出Execl文件) ...

  9. noip_最后一遍_2-图论部分

    大体按照 数学 图论 dp 数据结构 这样的顺序 模板集 这个真的只有模板了……………… ·spfa #include<bits/stdc++.h> using namespace std ...

  10. 【数位dp】bzoj3209: 花神的数论题

    Description 背景众所周知,花神多年来凭借无边的神力狂虐各大 OJ.OI.CF.TC …… 当然也包括 CH 啦.描述话说花神这天又来讲课了.课后照例有超级难的神题啦…… 我等蒟蒻又遭殃了. ...