https://codeforc.es/gym/102222/problem/F

注意到其实用unsigned long long不会溢出。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; inline int read() {
int x=0;
int f=0;
char c;
do {
c=getchar();
if(c=='-')
f=1;
} while(c<'0'||c>'9');
do {
x=(x<<3)+(x<<1)+c-'0';
c=getchar();
} while(c>='0'&&c<='9');
return f?-x:x;
} inline void _write(int x) {
if(x>9)
_write(x/10);
putchar(x%10+'0');
} inline void write(int x) {
if(x<0) {
putchar('-');
x=-x;
}
_write(x);
putchar('\n');
} void TestCase(int ti); int main() {
#ifdef Yinku
freopen("Yinku.in","r",stdin);
//freopen("Yinku.out","w",stdout);
#endif // Yinku
int T=read();
for(int ti=1; ti<=T; ti++)
TestCase(ti);
} /*--- ---*/ 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;
//cout<<"GEN "<<SC<<endl;
return SC;
} unsigned long long ans; struct Stack{
stack<unsigned int> v;
stack<unsigned int> maxv;
void PUSH(unsigned int val){
//cout<<"PUSH "<<val<<endl;
if(v.size()==0){
v.push(val);
maxv.push(val);
}
else{
v.push(val);
maxv.push(max(maxv.top(),val));
}
} void POP(){
//cout<<"POP"<<endl;
if(v.size()==0){
;
}
else{
v.pop();
maxv.pop();
}
} void CLEAR(){
while(v.size()){
v.pop();
maxv.pop();
}
} unsigned int MAX(){
if(v.size()==0){
return 0;
}
else{
return maxv.top();
}
}
}st; void gen() {
st.CLEAR(); ans=0;
scanf("%d%d%d%d",&n,&p,&q,&m);
scanf("%u%u%u",&SA,&SB,&SC);
//cout<<SA<<SB<<SC<<endl;
for(int i = 1; i <= n; i++) {
if(rng61()%(p+q)<p)
st.PUSH(rng61()%m+1);
else
st.POP();
ans^=1ll*i*st.MAX();
}
} void TestCase(int ti) {
gen();
printf("Case #%d: %llu\n",ti,ans);
}

Codeforces - 102222A - Maximum Element In A Stack - 模拟的更多相关文章

  1. Codeforces 889C Maximum Element(DP + 计数)

    题目链接  Maximum Element 题意  现在有这一段求序列中最大值的程度片段: (假定序列是一个1-n的排列) int fast_max(int n, int a[]) { int ans ...

  2. Maximum Element In A Stack Gym - 102222A【思维+栈】

    2018-2019 ACM-ICPC, China Multi-Provincial Collegiate Programming Contest https://vjudge.net/problem ...

  3. The 2018 ACM-ICPC Chinese Collegiate Programming Contest Maximum Element In A Stack

    //利用二维数组模拟 #include <iostream> #include <cstdio> #include <cstring> #include <s ...

  4. Codeforces 886E Maximum Element 组合数学 + dp

    我们定义dp[ i ]表示长度为 i 的序列, 最后没有一个==k的时候返回的方案数, 也就是最后强制返回 i 的方案数. 我们能得到dp方程   dp[ i ] = sum(dp[ i - j - ...

  5. [单调栈] 2018-2019 ACM-ICPC, China Multi-Provincial Collegiate Programming Contest-Maximum Element In A Stack

    题目:https://codeforces.com/gym/102222/problem/A Maximum Element In A Stack time limit per test 10.0 s ...

  6. 2018ACM-ICPC宁夏邀请赛 A-Maximum Element In A Stack(栈内最大值)

    Maximum Element In A Stack 20.91% 10000ms 262144K   As an ACM-ICPC newbie, Aishah is learning data s ...

  7. 【CodeForces】889 C. Maximum Element 排列组合+动态规划

    [题目]C. Maximum Element [题意]给定n和k,定义一个排列是好的当且仅当存在一个位置i,满足对于所有的j=[1,i-1]&&[i+1,i+k]有a[i]>a[ ...

  8. Codeforces 484B Maximum Value(高效+二分)

    题目链接:Codeforces 484B Maximum Value 题目大意:给定一个序列,找到连个数ai和aj,ai%aj尽量大,而且ai≥aj 解题思路:类似于素数筛选法的方式,每次枚举aj,然 ...

  9. 【CF886E】Maximum Element DP

    [CF886E]Maximum Element 题意:小P有一个1-n的序列,他想找到整个序列中最大值的出现位置,但是他觉得O(n)扫一遍太慢了,所以它采用了如下方法: 1.逐个遍历每个元素,如果这个 ...

随机推荐

  1. Source not found The source attachment does not contain the source for the file MethodBeforeAdvice.class

  2. 从request中读数据流

    ServletInputStream servletInputStream = reqeust.getInputStream(); int len=0; int size=reqeust.getCon ...

  3. c# ListBox

    1. ListBox用法(http://www.cnblogs.com/chinahbzm/articles/3577285.html) 2. ListBox使用(http://www.cnblogs ...

  4. Saiku_00_资源帖

    一.精选 1.李秋 随笔分类 - pentaho 二.概述 1.Saiku + Kylin 多维分析平台探索 三.Saiku+Kylin 1.使用Saiku+Kylin构建多维分析OLAP平台 2.使 ...

  5. 使用SQL脚本创建数据库,操作主键、外键与各种约束(MS SQL Server)

    在实际开发中,可能很少人会手写sql脚本来操作数据库的种种.特别是微软的MS SQL Server数据库,它的SQL Server Management Studio对数据库的图形化操作极致简便,从而 ...

  6. 2018.5.8 Project review

    1 .product introduced A. Function requirement (customer) The product function is control the 1KW and ...

  7. codeforces 652A A. Gabriel and Caterpillar(水题)

    题目链接: A. Gabriel and Caterpillar time limit per test 1 second memory limit per test 256 megabytes in ...

  8. stl_list.h

    stl_list.h // Filename: stl_list.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: http://b ...

  9. tensorflow中常量(constant)、变量(Variable)、占位符(placeholder)和张量类型转换reshape()

    常量 constant tf.constant()函数定义: def constant(value, dtype=None, shape=None, name="Const", v ...

  10. redis多机集群部署文档

    redis多机集群部署文档(centos6.2) (要让集群正常工作至少需要3个主节点,在这里我们要创建6个redis节点,其中三个为主节点,三个为从节点,对应的redis节点的ip和端口对应关系如下 ...