LOJ#541. 「LibreOJ NOIP Round #1」七曜圣贤

    科技2024-11-15  11

    description

    题面很长,这里给出题目链接

    solution

    用队列维护扔掉的红茶,同时若后扔出的红茶比先扔出的红茶编号更小,那么先扔出的红茶不可能成为答案,所以可以用单调队列维护故每次询问的答案只可能是单调队列的队首或者没有出现过的红茶中编号最小的,后者可以 O ( b ) O(b) O(b)暴力计算

    code

    #include<bits/stdc++.h> using namespace std; namespace IO{ int c; unsigned int seed; unsigned int randnum(){ seed^=seed<<13; seed^=seed>>17; seed^=seed<<5; return seed; } inline int read(int &x){scanf("%d",&x);return x;} inline void init_case(int &m,int &a,int &b,int &d,int p[]){ scanf("%d%u%d%d%d%d",&m,&seed,&a,&b,&c,&d); for(int i=1;i<=m;i++){ if(randnum()%c==0)p[i]=-1; else p[i]=randnum()%b; } } inline void update_ans(unsigned int &ans_sum,unsigned int cur_ans,int no){ const static unsigned int mod=998244353; ans_sum^=(long long)no*(no+7)%mod*cur_ans%mod; } } using IO::read; using IO::init_case; using IO::update_ans; deque<unsigned int> dq; queue<unsigned int> q; int w[4000005],ans; //车上有:w 1 //飞出去了:w 2 //没见过:w 0 int main(){ // freopen("knowledge4.in","r",stdin); static int p[2000005]; int T;read(T); int m,a,b,d; while(T--){ unsigned int ans_sum=0,cur_ans=0; init_case(m,a,b,d,p); while(!q.empty()) q.pop(); while(!dq.empty()) dq.pop_back(); memset(w,0,sizeof(w));b=max(a+1,b); if(a!=-1) for(int i=0;i<=a;++i) w[i]=1; ans=a+1; for(int i=1;i<=m;++i){ if(p[i]==-1){ if(q.empty()||d==1) continue; int t=q.front(); w[t]=1;q.pop(); if(!dq.empty()&&t==dq.front())dq.pop_front(); cur_ans=ans;if(!dq.empty())cur_ans=min(dq.front(),cur_ans); }//事件三 else if(!w[p[i]]){ w[p[i]]=1; while(w[ans]) ans++; cur_ans=ans;if(!dq.empty())cur_ans=min(dq.front(),cur_ans); }//事件一 else if(w[p[i]]==1){ if(d==1) continue; w[p[i]]=2;q.push(p[i]); while(!dq.empty()&&dq.back()>p[i]) dq.pop_back();dq.push_back(p[i]); cur_ans=ans;if(!dq.empty())cur_ans=min(dq.front(),cur_ans); }//事件二 else{ if(q.empty()||d==1) continue; int t=q.front(); w[t]=1;q.pop(); if(!dq.empty()&&t==dq.front())dq.pop_front(); cur_ans=ans;if(!dq.empty())cur_ans=min(dq.front(),cur_ans); }//事件三 update_ans(ans_sum,cur_ans,i); } printf("%u\n",ans_sum); } return 0; }
    Processed: 0.085, SQL: 8