• BZOJ 1012: [JSOI2008]最大数maxnumber 单调队列/线段树/树状数组/乱搞


    1012: [JSOI2008]最大数maxnumber

    Time Limit: 3 Sec  Memory Limit: 162 MB
    Submit: 4750  Solved: 2145
    [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如上文中所述,满足(0

    Output

    对于每一个查询操作,你应该按照顺序依次输出结果,每个结果占一行。

    Sample Input

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

    Sample Output

    96
    93
    96

    HINT

    题解:

    这道题就是裸的rmq题目,我推荐一种单调队列的搞法!

    搞搞搞,看代码就知道肿么做啦~

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 250001
    #define eps 1e-9
    const int inf=0x7fffffff;   //无限大 
    //**************************************************************************************
    int a[maxn],max_num[maxn],t=0,ans=0;
    int main()
    {
        int n,d;
        scanf("%d%d",&n,&d);
        char ch[3];
        int g;
        while(n--)
        {
            scanf("%s%d",ch,&g);
            if(ch[0]=='A')
            {
                a[++t]=(ans+g)%d;
                for(int i=t;i;i--)
                {
                    if(max_num[i]<a[t])
                        max_num[i]=a[t];
                    else
                        break;
                }
            }
            else
            {
                ans=max_num[t-g+1];
                printf("%d
    ",ans);
            }
        }
        return 0;
    }
  • 相关阅读:
    composer "Illegal offset type in isset or empty"报错解决方案
    Yii2 使用a标签发送post请求
    YII2 项目安装步骤及异常记录
    三级城市联动菜单
    最新全国省、市、县数据库
    Sanic官翻-SSL示例
    Sanic官翻-WebSocket
    Sanic官翻-部署
    Sanic官翻-概述
    老子的道德经
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4349230.html
Copyright © 2020-2023  润新知