zoukankan      html  css  js  c++  java
  • BZOJ-1012: [JSOI2008]最大数maxnumber (线段树)

    1012: [JSOI2008]最大数maxnumber

    Time Limit: 3 Sec  Memory Limit: 162 MB
    Submit: 10896  Solved: 4760
    [Submit][Status][Discuss]

    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

    HINT

      数据如下http://pan.baidu.com/s/1i4JxCH3

    Source

    这年头……连BZOJ都有如此之水的题目了=_= !

     1 #include "bits/stdc++.h"
     2 #define lson rt<<1,l,m
     3 #define rson rt<<1|1,m+1,r
     4 using namespace std;
     5 typedef long long LL;
     6 const int MAX=200005;
     7 LL m,mod;
     8 LL mx[MAX<<2];
     9 inline LL read(){
    10     LL an=0,x=1;char c=getchar();
    11     while (c<'0' || c>'9'){if (c=='-') x=-1;c=getchar();}
    12     while (c>='0' && c<='9'){an=an*10+c-'0';c=getchar();}
    13     return x*an;
    14 }
    15 void PushUp(int rt){
    16     mx[rt]=max(mx[rt<<1],mx[rt<<1|1]);
    17 }
    18 void update(int rt,int l,int r,int x,LL y){
    19     if (l==r){
    20         mx[rt]=y;
    21         return;
    22     }
    23     int m=(l+r)>>1;
    24     if (x<=m)
    25         update(lson,x,y);
    26     else
    27         update(rson,x,y);
    28     PushUp(rt);
    29 }
    30 LL search(int rt,int l,int r,int x,int y){
    31     if (x<=l && r<=y)
    32         return mx[rt];
    33     int m=(l+r)>>1;
    34     LL res=0;
    35     if (x<=m)
    36         res=max(res,search(lson,x,y));
    37     if (y>m)
    38         res=max(res,search(rson,x,y));
    39     return res;
    40 }
    41 int main(){
    42     freopen ("maxnum.in","r",stdin);
    43     freopen ("maxnum.out","w",stdout);
    44     int i,j;char c;
    45     LL x;int len=0;
    46     memset(mx,0,sizeof(mx));
    47     m=read();mod=read();
    48     LL an=0;
    49     for (i=1;i<=m;i++){
    50         c=getchar();
    51         if (c=='Q'){
    52             x=read();
    53             an=search(1,1,m,len-(int)x+1,len);
    54             printf("%lld
    ",an);
    55         }
    56         if (c=='A'){
    57             x=read();
    58             len++;
    59             x=(x+an)%mod;
    60             update(1,1,m,len,x);
    61         }
    62     }
    63     return 0;
    64 }
    未来是什么样,未来会发生什么,谁也不知道。 但是我知道, 起码从今天开始努力, 肯定比从明天开始努力, 要快一天实现梦想。 千里之行,始于足下! ——《那年那兔那些事儿》
  • 相关阅读:
    svn的安装方法
    在powerDesigner中通过SQL生成pdm
    关于文件下载
    关于ClassPath的思考
    重读Spring之ConfigurationClassPostProcessor-改正错误
    SpringBoot自动装配原理
    SpringMVC之json是怎么传回前端的 @ResponseBody解析
    consumer配置参数之max.poll.interval.ms
    SpringMVC 之处理请求
    使用SpringMVC遇到的坑
  • 原文地址:https://www.cnblogs.com/keximeiruguo/p/7426558.html
Copyright © 2011-2022 走看看