Codeforces - 102222A - Maximum Element In A Stack - 模拟

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);
}

转载于:https://www.cnblogs.com/Yinku/p/11038296.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值