zoukankan      html  css  js  c++  java
  • bzoj 1012 维护一个单调数列

    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

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

    看懂题意 维护一个单调队列  其他方法还会更新!!!

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <map>
    #include <stack>
    #define inf 0xfffff
    typedef long long ll;
    using namespace std;
    #define MAXN  10000
    #define mod 10007
    #define eps 1e-9
    stack<int> q1;
    ll dis[200005];
    int main()
    {
        int m,d=0,t;
         int re;
         ll nl;
         char what;
         while(scanf("%d%d",&m,&d)!=EOF)
        {   memset(dis,0,sizeof(dis));
            getchar();
            while(!q1.empty())//这个是鸡肋
                q1.pop();
                t=0;
             for(int i=1; i<=m; i++)
            {
                scanf("%c %lld",&what,&nl);
                getchar();
                if(what=='A')
                   {
                    q1.push((nl+t)%d);
                     re=q1.size();
                    dis[re]=(nl+t)%d;
                    for(int i=re-1;i>=1;i--)//维护一个单调数组
                    {
                        if(dis[i]<dis[re])
                            dis[i]=dis[re];
                            else
                                break;//break 很重要 不然超时
                    }
                 if(what=='Q')
                {
                    t=dis[re-nl+1];
                   printf("%d ",t);
                }
            }
        }
        return 0;
    }

  • 相关阅读:
    caffe for python (官方翻译)
    实验三、页式地址重定位模拟
    实验二、银行家算法
    实验一:进程调度实验
    植物大战僵尸作弊器源代码(MFC版)
    植物大战僵尸作弊器源代码(控制台版)
    CE寻找游戏基址
    植物大战僵尸内存地址(转)
    Detour的简单使用
    C/S模型之命名管道
  • 原文地址:https://www.cnblogs.com/hsd-/p/4656787.html
Copyright © 2011-2022 走看看