2019icpc Yinchuan network game -A Maximum (thinking)

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

Meaning of the questions: to maintain a stack, stack and pop operations support, and calculate the maximum stack after each operation, to get the final result.

Ideas:

  Fights out fast, and I calmly in school play, did not know the title of this competition is to Yinchuan 2018 Invitational title copied from the QAQ, the organizers really Niubi. .

  This problem really is, and I hxc take turns solving the problem, the pit was miserable, always thought that use data structures to do, did not think the points go up. Thinking questions, each stack to ensure maximum stack elements. If the current stack of elements x, y is the current top of the stack, if x> = y, this is no problem, on the line directly to the stack; if x <y, y we directly corresponds Alternatively x, then the stack i.e. can.

  Learn, this had a lot of people, do not want complicated, how simple how to.

AC Code:

#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
using namespace std;

const int maxn=5e6+5;
typedef unsigned int UI;
int T,cas,top;
UI stk[maxn];
long long ans;

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("%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){
            stk[++top]=rng61()%m+1;
            stk[top]=max(stk[top-1],stk[top]);
        }
        else
            if(top>0) --top;
        ans^=1LL*i*stk[top];
    }
}

int main(){
    scanf("%d",&T);
    while(T--){
        ans=0;
        top=0;
        gen();
        printf("Case #%d: %lld\n",++cas,ans);
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/FrankChen831X/p/11440426.html
Recommended