zoukankan      html  css  js  c++  java
  • Codeforces

    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('
    ');
    }
    
    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
    ",ti,ans);
    }
    
  • 相关阅读:
    有序表查找
    遍历二叉树
    二叉树
    [Oracle]使用InstantClient访问Oracle数据库
    [部署]CentOS yum源
    [部署]CentOS安装PHP环境
    [部署]CentOS安装MariaDB
    [部署]CentOS安装apache
    Metrics.NET源码阅读笔记
    [JavaScript]catch(ex)语句中的ex
  • 原文地址:https://www.cnblogs.com/Yinku/p/11038296.html
Copyright © 2011-2022 走看看