题目链接:

1012: [JSOI2008]最大数maxnumber

Time Limit: 3 Sec  Memory Limit: 162 MB

Description

  现在请求你维护一个数列,要求提供以下两种操作:1、 查询操作。语法:Q L 功能:查询当前数列中末尾L
个数中的最大的数,并输出这个数的值。限制:L不超过当前数列的长度。2、 插入操作。语法:A n 功能:将n加
上t,其中t是最近一次查询操作的答案(如果还未执行过查询操作,则t=0),并将所得结果对一个固定的常数D取
模,将所得答案插入到数列的末尾。限制:n是非负整数并且在长整范围内。注意:初始时数列是空的,没有一个
数。

Input

  第一行两个整数,M和D,其中M表示操作的个数(M <= 200,000),D如上文中所述,满足D在longint内。接下来
M行,查询操作或者插入操作。

Output

  对于每一个询问操作,输出一行。该行只有一个数,即序列中最后L个数的最大数。

Sample Input

5 100
A 96
Q 1
A 97
Q 1
Q 2

Sample Output

96
93
96
 
题意
 
 
思路
 
线段树的入门题;
 
AC代码
 
#include <bits/stdc++.h>
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(b));
typedef long long LL;
const LL mod=1e9+;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int N=2e5+;
int m;
LL d;
struct Node
{
int l,r;
LL num;
}tree[*N];
void pushup(int node)
{
tree[node].num=max(tree[*node].num,tree[*node+].num);
}
void build(int node,int L,int R)
{
tree[node].l=L;
tree[node].r=R;
tree[node].num=;
if(L==R)return ;
int mid=(L+R)>>;
build(*node,L,mid);
build(*node+,mid+,R);
pushup(node);
}
void update(int node,int pos,LL num)
{
if(tree[node].l==tree[node].r&&tree[node].l==pos)
{
tree[node].num=num;
return ;
}
int mid=(tree[node].l+tree[node].r)>>;
if(pos<=mid)update(*node,pos,num);
else update(*node+,pos,num);
pushup(node);
}
LL query(int node,int L,int R)
{
if(L<=tree[node].l&&R>=tree[node].r)
{
return tree[node].num;
}
int mid=(tree[node].l+tree[node].r)>>;
if(R<=mid)return query(*node,L,R);
else if(L>mid)return query(*node+,L,R);
else return max(query(*node,L,mid),query(*node+,mid+,R));
}
int main()
{
while(scanf("%d%lld",&m,&d)!=EOF)
{
int cnt=;
LL t=;
build(,,m);
Riep(m)
{
char s;
scanf(" %c",&s);
if(s=='A')
{
LL n;
scanf("%lld",&n);
n+=t;
n%=d;
update(,cnt,n);
cnt++;
}
else
{
int len;
scanf("%d",&len);
// cout<<cnt-len<<" "<<cnt-1<<"@"<<endl;
t=query(,cnt-len,cnt-);
printf("%lld\n",t);
}
}
}
return ;
}

bzoj-1012 1012: [JSOI2008]最大数maxnumber(线段树)的更多相关文章

  1. 【BZOJ 1012】 [JSOI2008]最大数maxnumber(线段树做法)

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

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

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

  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: 8748  Solved: 3835[Submi ...

  5. BZOJ 1012: [JSOI2008]最大数maxnumber 线段树

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1012 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作.语法:Q L 功能: ...

  6. 1012: [JSOI2008]最大数maxnumber 线段树

    https://www.lydsy.com/JudgeOnline/problem.php?id=1012 现在请求你维护一个数列,要求提供以下两种操作:1. 查询操作.语法:Q L 功能:查询当前数 ...

  7. BZOJ1012:[JSOI2008]最大数maxnumber(线段树)

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

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

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

  9. BZOJ 1012 最大数maxnumber 线段树

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1012 题目大意: 见链接 思路: 直接用线段树模拟一下就可以了. #include&l ...

随机推荐

  1. go初识

    for循环 ; i < ; i++ { fmt.Println(i*i) } ls := "agd" for _, arg := range ls{ fmt.Println( ...

  2. css3 nth-child 与 nth-of-type 的区别

    by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=1709 一.深呼吸,直 ...

  3. R必学包之dplyr

    http://www.360doc.com/content/17/1204/10/50223086_709726679.shtml

  4. Vue1.x 迁移 Vue2.x(项目进行不断修改)

    一.$dispatch 和 $broadcast 已经被弃用. 请使用更多简明清晰的组件间通信和更好的状态管理方案,如:Vuex 这些方法的最常见用途之一是父子组件的相互通信.在这些情况下,你可以使用 ...

  5. T9270 mjt树

    题目背景 从前森林里有一棵很大的mjt树,树上有很多小动物. 题目描述 mjt树上有 n 个房间,第 i 个房间住着 ai 只第bi 种小动物. 这n个房间用n-1条路连接起来,其中房间1位mjt树的 ...

  6. 【Todo】Java Callable和Future学习

    参考这篇文章:http://blog.csdn.net/ghsau/article/details/7451464  还有一个系列<Java多线程>

  7. 【转载】“菜”鸟理解.NET Framework(CLI,CLS,CTS,CLR,FCL,BCL)

    既然要学.NET,就要先认识认识她,我不喜欢大段大段文字的东西,自己通过理解,画个图,来看看.NET的沉鱼落雁,闭月羞花之容. 最下层蓝色部分是.NET Framework的基础,也是所有应用软件的基 ...

  8. Linux bridge-utils tunctl 使用

    网络 brctl是Linux下用来管理以太网桥.在内核中建立.维护.检查网桥配置的命令 STP - Spanning Tree Protocol(生成树协议)逻辑上断开环路.防止二层网络的广播风暴的产 ...

  9. LeetCode_3Sum

    一.题目 3Sum Total Accepted: 45112 Total Submissions: 267165My Submissions Given an array S of n intege ...

  10. TagCanvas - HTML5 Canvas Tag Cloud

    http://www.goat1000.com/tagcanvas.php watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbmlja3JvcHJhaw==/ ...