【2019银川网络赛A:】Maximum Element In A Stack(动态求栈中最大值)
题目地址:https://nanti.jisuanke.com/t/41285
解题思路:
栈顶元素保存的是第i次操作之后栈中的最大值。
待入栈元素x, 栈不为空:若x>=栈顶值, x入栈,否则重新将栈顶值入栈;栈为空:直接入栈
ac代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e6+10;
int n, p, q, m;
unsigned int SA, SB, SC;
unsigned int rng61()
{SA ^= SA << 16;SA ^= SA >> 5;SA ^= SA << 1;unsigned int t = SA;SA = SB;SB = SC;SC ^= t ^ SA;return SC;
}
stack<ll> s;
int main()
{//freopen("/Users/zhangkanqi/Desktop/11.txt","r",stdin);int t, Case = 0;scanf("%d", &t);while(t--){ll ans = 0;while(!s.empty()) s.pop();scanf("%d%d%d%d%u%u%u", &n, &p, &q, &m, &SA, &SB, &SC);for(int i = 1; i <= n; i++){if(rng61() % (p+q) < p){ll x = rng61() % m + 1;if(!s.empty()) // 非空才有top(){if(x >= s.top()) s.push(x);else s.push(s.top());}else s.push(x);}else{if(!s.empty()) s.pop();}if(!s.empty()) ans ^= i*s.top();}printf("Case #%d: %lld\n", ++Case, ans);}return 0;
}
【2019银川网络赛A:】Maximum Element In A Stack(动态求栈中最大值)相关推荐
- 【2019.08.31】2019银川网络赛(2018银川现场赛)
补题地址:https://www.jisuanke.com/contest/2991 A:✅ B:✅ C:✅ D: E: F:✅ G: H:✅ I: J: K: L:https://blog.csdn ...
- 2019徐州网络赛G
2019徐州网络赛G 题意 给定s字符串,定义一个回文串的价值是这个回文串中不同字母的个数,求s中所有回文串的价值之和. 思路 马拉车加序列自动机. 代码 #include<bits/stdc+ ...
- ICPC 2019 徐州网络赛
ICPC 2019 徐州网络赛 比赛时间:2019.9.7 比赛链接:The Preliminary Contest for ICPC Asia Xuzhou 2019 赛后的经验总结 // 比赛完才 ...
- 【2018icpc宁夏邀请赛现场赛】【Gym - 102222A】Maximum Element In A Stack(动态的栈中查找最大元素)
https://nanti.jisuanke.com/t/41285 题干: As an ACM-ICPC newbie, Aishah is learning data structures in ...
- Maximum Element In A Stack 数据结构
Maximum Element In A Stack 时间限制: 10 Sec 内存限制: 128 MB 题目描述 As an ACM-ICPC newbie,Aishah is learning ...
- 2019南昌网络赛 C题,Hello 2019
题意:求包含9012,但是不包含8012的最小删除次数 解题思路:首先将字符串反转,按照题解思路为线段树维护矩阵即可 我们将线段树的每个区间用矩阵表示,矩阵mat[5][5]维护2019这个序列的情况 ...
- 2019南昌网络赛 I. Yukino With Subinterval 树状数组套线段树
I. Yukino With Subinterval 题目链接: Problem Descripe Yukino has an array \(a_1, a_2 \cdots a_n\). As a ...
- 2019 南昌网络赛D FFT多个多项式相乘
2019 Asia Nanchang D. Interesting Series 链接:https://nanti.jisuanke.com/t/41351 题意:首先题目给了若干定义 定义:Fn=( ...
- 2019南昌网络赛-I(单调栈+线段树)
题目链接:https://nanti.jisuanke.com/t/38228 题意:定义一段区间的值为该区间的和×该区间的最小值,求给定数组的最大的区间值. 思路:比赛时还不会线段树,和队友在这题上 ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 XKC's basketball team
XKC , the captain of the basketball team , is directing a train of nn team members. He makes all mem ...
最新文章
- LINQ 学习路程 -- 查询操作 GroupBy ToLookUp
- 使用javascript oop开发滑动(slide) 菜单控件
- 为什么总线要用一根来表示一bit
- [转]清除mysql表中数据
- Oracle11g rac监听,关于oracle11g RAC 监听器使用中出现的no services以及no listener分析...
- 51nod 1717 好数 (水题)
- 程序员幽默:老板让明天带条鱼来大家观察
- 头发剪短了要快速生发_怎样生发效果最好最快?四个方法快速长出头发!
- Java--File文件操作
- 【12.2新特性】Oracle Sharding分片级别的高可用实现
- Android源码——Logger日志系统
- Xshell 5 注册码
- linux mysql backdoor_Mysql BackDoor
- ABAP 关于 delete adjacent duplicates from的小心得
- 改为国内镜像时jenkins plugin提示: Update information obtained: 不可用 ago;
- L2TP连接尝试失败,因为安全层在初始化与远程计算机的协商时遇到了一个处理错误
- Android设备实时音视频传输有效方案
- android WIFI学习总结
- 产品升级|1-2月合刊:多款重磅产品来袭!
- 2022-2028年全球与中国航空货物安全和检查系统行业市场需求预测分析
热门文章
- 使用Secure Store Service连接数据库
- 智能实验室-全能优化(Guardio) 4.3.0.730
- Ubuntu安装aptitude,来解决软件包依赖关系的问题
- ediplus 复制编辑一列_Editplus 部分使用技巧(一)
- tomcat java.ext.dirs_tomcat classloader 加载class顺序
- 内部比较器:Comparable的定义使用
- 1个app的完整测试用例_APP测试流程
- treeset java api_JAVAAPI学习值TreeSet类
- 【转】nodejs 压缩文件 zip-local
- vue-router 修改或添加新参数