用deque实时维护栈的情况。

  数加入栈顶部,删掉栈顶部的数,相当于加入一个数,删掉最早出现的数,每次求最大值,这个直接记录一下就好了。

  数加入栈底部,删掉栈顶部的数,相当于加入一个数,删掉最晚出现的数,每次求最大值,这个可以用单调队列。

  两种数分别处理即可,被两个细节搞的调了好久T T

#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<deque>
#define MOD(x) ((x)>=modd?(x)-modd:(x))
using namespace std;
const int maxn=, modd=1e9+;
deque<int>ds;
int n, A, B, C, a, b, mod, tott, ans;
int x[maxn], q[maxn], ty[maxn], mx[maxn];
int main()
{
scanf("%d%d%d%d%d%d%d%d", &n, &A, &B, &C, &x[], &a, &b, &mod);
int l=, r=;
for(int i=;i<=n;i++)
{
x[i]=(1ll*x[i-]*a+b)%mod;
if(x[i]%(A+B+C)<A || ds.size()<=) ty[i]=;
else if(x[i]%(A+B+C)<A+B) ty[i]=;
else if(A+B<=x[i]%(A+B+C)) ty[i]=;
if(!ty[i]) ds.push_front(i), ++tott, mx[tott]=max(mx[tott-], x[i]);
else if(ty[i]==)
{
ds.push_back(i);
while(l<=r && x[q[r]]<=x[i]) r--;
q[++r]=i;
}
else
{
int delta=ds.front(); ds.pop_front();
if(ty[delta]) {if(q[l]==delta) l++;}
else --tott;
}
ans+=max(mx[tott], q[l]?x[q[l]]:); ans=MOD(ans);
}
printf("%d\n", ans);
}

最新文章

  1. Hive安装配置指北(含Hive Metastore详解)
  2. [leetcode] 提醒整理之进制
  3. 关于redis扩展安装及使用
  4. Struts1 action重定向跳转 带参数
  5. Maven提高篇系列之(五)——处理依赖冲突
  6. hive odbc
  7. 安装jdk源码
  8. SharePoint自动化系列——Select-option标签的定位方法总结
  9. C# - 设置DLL的属性Embed Interop Type 设为False
  10. 数据结构之------C++指针冒泡排序算法
  11. June 28th. 2018, Week 26th. Thursday
  12. oracle sql生成临时递增数据
  13. delphi:Exception EInvalidPointer in module Project1.exe
  14. 【BZOJ5285】[HNOI2018]寻宝游戏(神仙题)
  15. caffe编译报错解决
  16. Mac python 2.X 升级到 3.X
  17. SQL-4查找所有已经分配部门的员工的last_name和first_name(自然连接)
  18. linux 3.10中完成量的使用
  19. 使用putty连接本地VirtualBox上的centos7 linux主机
  20. GPU并行编程小结

热门文章

  1. 常用SQL语句大全(SQL Server)
  2. SQL中NULL的妙用
  3. POJ 3579 Median 二分加判断
  4. ORA-28000: the account is locked 查哪个具体ip地址造成
  5. ES6的新特性(16)——Generator 函数的语法
  6. CSS3在线实战
  7. 软件工程第八周PSP
  8. 强化学习之QLearning
  9. 使用C和C++实现“电梯”的区别
  10. a5