https://nanti.jisuanke.com/t/41285

题干:

As an ACM-ICPC newbie, Aishah is learning data structures in computer science. She has already known that a stack, as a data structure, can serve as a collection of elements with two operations:

  • push, which inserts an element to the collection, and
  • pop, which deletes the most recently inserted element that has not yet deleted.

Now, Aishah hopes a more intelligent stack which can display the maximum element in the stack dynamically. Please write a program to help her accomplish this goal and go through a test with several operations.

Aishah assumes that the stack is empty at first. Your program will output the maximum element in the stack after each operation. If at some point the stack is empty, the output should be zero.

Input

The input contains several test cases, and the first line is a positive integer TTindicating the number of test cases which is up to 5050.

To avoid unconcerned time consuming in reading data, each test case is described by seven integers n (1≤n≤5×106)n (1≤n≤5×106), pp, qq, m (1≤p,q,m≤109)m (1≤p,q,m≤109), SASA, SBSB and SC (104≤SA,SB,SC≤106)SC (104≤SA,SB,SC≤106). The integer nn is the number of operations, and your program is asked to generate all operations by using the following code in C++.

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; } void gen(){ scanf(" for(int i = 1; i <= n; i++){ if(rng61() PUSH(rng61() else POP(); } }

The procedure PUSH(v) used in the code inserts a new element with value vv into the stack and the procedure POP() pops the topmost element in the stack or does nothing if the stack is empty.

Output

For each test case, output a line containing Case #x: y, where x is the test case number starting from 11, and y is equal to ⊕i=1n(i⋅ai)⊕i=1n⁡(i⋅ai) where ⊕⊕ means bitwise xor.

Example

Input

2
4 1 1 4 23333 66666 233333
4 2 1 4 23333 66666 233333

Output

Case #1: 19
Case #2: 1

Note

The first test case in the sample input has 44 operations:

  • POP();
  • POP();
  • PUSH(1);
  • PUSH(4).

The second test case also has 44 operations:

  • PUSH(2);
  • POP();
  • PUSH(1);
  • POP().

题目大意:

刚开始是一个空栈, 每次可以在其中加入元素,并且要求出此时栈中元素的最大值。对于每个样例只需要输出一个数:

解题报告:

对于push操作,读入一个数x,每次加入sk.top()和x的较大值,这样保证栈顶元素一定是最大值。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
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;
}ll gen() {stack<ll> sk;ll res = 0;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 tmp = rng61() %m + 1;if(sk.empty()) sk.push(tmp);else sk.push(max(tmp,sk.top()));}else if(sk.size()) sk.pop();if(sk.size()) res ^= i*sk.top();else res ^= 0;}return res;
}
int main()
{int t,iCase=0;cin>>t;while(t--) {printf("Case #%d: %lld\n",++iCase,gen());}return 0 ;
}

【2018icpc宁夏邀请赛现场赛】【Gym - 102222A】Maximum Element In A Stack(动态的栈中查找最大元素)相关推荐

  1. 【2018icpc宁夏邀请赛现场赛】【Gym - 102222H】Fight Against Monsters(贪心排序)

    题干: It is my great honour to introduce myself to you here. My name is Aloysius Benjy Cobweb Dartagna ...

  2. 【2018icpc宁夏邀请赛现场赛】【Gym - 102222F】Moving On(Floyd变形,思维,离线处理)

    https://nanti.jisuanke.com/t/41290 题干: Firdaws and Fatinah are living in a country with nn cities, n ...

  3. Maximum Element In A Stack 数据结构

    Maximum Element In A Stack 时间限制: 10 Sec  内存限制: 128 MB 题目描述 As an ACM-ICPC newbie,Aishah is learning ...

  4. 【2019南昌邀请赛现场赛 - G】Winner(建图,tarjan缩点 或 贪心)

    题目大意: n个人参加竞技比赛.比赛由三种模式a,b,c,每个人在每种模式下有对应的权值a[i]b[i]c[i].举行n−1场比赛,每场比赛主办方可以选择两个人决斗,能力值低的人淘汰.这样保证n-1场 ...

  5. 【2019南昌邀请赛现场赛 - J】Prefix(STLmap,思维)

    题干: yah has n strings <s1​,⋯,sn​>, and he generates a sequence P by two steps: P=<s1​,⋯,sn​ ...

  6. 华中邀请赛现场赛F题 Seats

    题目链接:http://acm.whu.edu.cn/land/problem/detail?problem_id=1552 解题报告:题目意思应该很清楚,就是有n个人,分别属于7个班级,然后他们坐成 ...

  7. 【2019南昌邀请赛现场赛 - G】Winner(思维、图论+缩点)

    题目链接: https://nanti.jisuanke.com/t/40259" Ichuan really likes to play games, so he organized a ...

  8. 2018宁夏邀请赛网赛 G.Trouble of Tyrant(单调栈)

    题意: 有n个点,2n-3条边的图.点 1 到每个点有一条边,编号相邻的两个点有一条边.q次询问,每次询问一个增量d,问图中每条边都增加 d 后,1 到 n 的最短路是多少.增量独立,不累加. 1 & ...

  9. ICPC 南昌现场赛 K:Tree(dsu on tree + 动态开点线段树)

    Tree 让我们找满足一下五个条件的(x,y(x, y(x,y)点对有多少: x≠yx \neq yx​=y xxx不是yyy的祖先 yyy不是xxx的祖先 dis(x,y)≤kdis(x, y)\ ...

最新文章

  1. Drop Down ComboBox
  2. PHP中文乱码的常见解决方法总结
  3. 记一次灵活的模型训练生成的pth转onnx文件失败
  4. (三)标记图像以进行AI模型训练
  5. 强大的网页性能测试工具--Speed Tracer
  6. java 调用c 的dll,java如何调用C的dll
  7. 基于 pureXML 技术的数据库表结构扩展
  8. 手机OTG是什么功能,怎样使用?
  9. BZOJ4340 : BJOI2015 隐身术
  10. unity实现简单的地图编辑器,实现跑酷地图编辑器 2d地图编辑器,导出地图json数据,导入地图json数据
  11. 微信发红包测试用例设计
  12. DEM数据获取、数据镶嵌、掩膜提取
  13. Python爬虫实战--58同城二手商品爬虫
  14. Activity的生命周期及Intent
  15. 怎么看oracle定时作业,Oracle 定时作业Job详解
  16. P2161 [SHOI2009]会场预约[线段树/树状数组+二分/STL]
  17. 推荐一款基于Vue的开源智慧物业解决方案项目源码
  18. MATLAB在线测试
  19. 斗地主练习(按照斗地主的规则,完成洗牌发牌的动作。)
  20. Python + Paramiko实现sftp文件上传下载

热门文章

  1. linq to json for sl
  2. 美国团购网站Groupon的盈利模式
  3. 310. Minimum Height Trees
  4. 杜克大学计算机硕士要几年,2017杜克大学春季不招计算机专业的硕士?
  5. zemax模拟ld_Zemax光学设计实例(83)在非序列模式下LD阵列的光束整形
  6. dart 乘方运算符_Dart系列-运算符
  7. gtest测试框架使用详解_测试框架TestNG使用介绍
  8. Codeforces Round #719 (A-C)
  9. python如何对一个属性或方法进行封装_python 类、对象、方法、属性
  10. CATIA中使用约束时提示“创建的约束是临时的。若希望使他成为永久约束,则需要在单击确定按钮之前激活约束开关。”