不会用随机数生成器……

P3793 由乃救爷爷

czy0323 @ 2022-09-15 00:03:40

我的四毛子正确性已经验证过了,交了st表模板题是AC的,但是连样例都过不去,我怀疑是随机数生成器的问题,有没有大佬解答一下?

#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
const ll MAXN=7e6+5,MAXNLOG=25,INF=0;
ll n,m,s,len,cntpiece;
unsigned long long ans;
ll a[MAXN];
ll front[MAXN],tail[MAXN];
ll st[MAXN][MAXNLOG];

namespace GenHelper
{
    unsigned z1,z2,z3,z4,b;
    unsigned rand_()
    {
        b=((z1<<6)^z1)>>13;
        z1=((z1&4294967294U)<<18)^b;
        b=((z2<<2)^z2)>>27;
        z2=((z2&4294967288U)<<2)^b;
        b=((z3<<13)^z3)>>21;
        z3=((z3&4294967280U)<<7)^b;
        b=((z4<<3)^z4)>>12;
        z4=((z4&4294967168U)<<13)^b;
        return (z1^z2^z3^z4);
    }
}

void srand(unsigned x){
    using namespace GenHelper;
    z1=x; z2=(~x)^0x233333333U; z3=x^0x1234598766U; z4=(~x)+51;
}

inline int read(){
    using namespace GenHelper;
    int a=rand_()&32767;
    int b=rand_()&32767;
    return a*32768+b;
}

inline void init(){
    ll cnt=0,Max=-INF;
    for(ll i=1;i<=n;i++){
        if( cnt==len ){
            st[++cntpiece][0]=Max;
            cnt=0,Max=-INF;
        }
        Max=max(Max,a[i]);
        front[i]=Max;
        cnt++;
    }
    st[++cntpiece][0]=Max;
    cnt=0,Max=-INF;
    for(ll i=1;i<=cntpiece;i++){
        ll one=min(n,i*len),Max=-INF;
        for(ll j=one;j>=i*len-len+1;j--){
            Max=max(Max,a[j]);
            tail[j]=Max;
        }
    }
    for(ll j=1; (1<<j)<=cntpiece; j++)
        for(ll i=1; i+(1<<j)-1<=cntpiece; i++)
            st[i][j]=max(st[i][j-1],st[i+(1<<(j-1))][j-1]);
}

int main(){
    scanf("%lld%lld%lld",&n,&m,&s);
    srand(s);
    len=log2(n)+rand()%3;
    for(ll i=1;i<=n;i++)
        a[i]=read();
    init();
    for(ll i=1;i<=m;i++){
        ll l=read()%n+1,r=read()%n+1,Max=-INF;
        if( l>r )
            continue;
        ll lpiece=ceil(l*1.0/len),rpiece=ceil(r*1.0/len);
        if( lpiece==rpiece ){
            for(ll j=l;j<=r;j++)
                Max=max(Max,a[j]);
            ans+=Max;
            continue;
        }
        lpiece++,rpiece--;
        if( lpiece<=rpiece ){
            ll k=log2(rpiece-lpiece+1);
            Max=max(st[lpiece][k],st[rpiece-(1<<k)+1][k]);
        }
        ans+=max(max(tail[l],front[r]),Max);
    }
    printf("%lld",ans);
}

by vdfes @ 2022-09-15 00:20:10

@czy0323 l>r continue???


by cyffff @ 2022-09-15 06:49:30

if(l>r) swap(l,r);


by czy0323 @ 2022-09-15 07:30:57

@hjy192939 原来题目是这个意思吗qwq


by czy0323 @ 2022-09-15 07:45:21

@cyffff 谢谢dalao,已经AC了


|