QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136866#240. Period Sequencenameless_story#100 ✓561ms3452kbC++202.1kb2023-08-09 13:16:402023-08-09 13:16:42

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-09 13:16:42]
  • 评测
  • 测评结果:100
  • 用时:561ms
  • 内存:3452kb
  • [2023-08-09 13:16:40]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

const LL mod=1e9+7,I6=(mod+1)/6,I4=(mod+1)/4,I2=(mod+1)/2;
void upd(LL &x,LL y){x=(x+y)%mod;}
LL sqr(LL x){
    x%=mod;
    return x*x%mod;
}
LL S1(LL x){
    x%=mod;
    return x*(x+1)%mod*I2%mod;
}
LL S2(LL x){
    x%=mod;
    return x*(x+1)%mod*(x*2+1)%mod*I6%mod;
}
LL S3(LL x){
    x%=mod;
    return x*x%mod*(x+1)%mod*(x+1)%mod*I4%mod;
}
LL S0(LL l,LL r){
    return (r-l+1)%mod;
}
LL S1(LL l,LL r){
    return (S1(r)-(l==0?0:S1(l-1)))%mod;
}
LL S2(LL l,LL r){
    return (S2(r)-(l==0?0:S2(l-1)))%mod;
}
LL S3(LL l,LL r){
    return (S3(r)-(l==0?0:S3(l-1)))%mod;
}
void solve(){
    LL n,a,b; cin>>n>>a>>b;
    vector s(n,0ll);
    for (LL &x:s) cin>>x;
    LL ans=0;
    for (LL i=0;i<n;++i){
        for (LL j=0;j<n;++j){
            if ((s[i]-s[j])%n!=0) continue;
            LL k=(s[i]-s[j])/n;
            if (b<i||b<j) continue;
            LL r1=(b-i)/n,l1=(a-i+n-1)/n;
            LL r2=(b-j)/n,l2=(a-j+n-1)/n;
            l2-=k; r2-=k;
            LL l=max(l1,l2),r=min(r1,r2);
            if (l>r) continue;
            LL s0=S0(l,r);
            LL s1=S1(l,r);
            LL s2=S2(l,r);
            LL s3=S3(l,r);
            LL A,B,C;
            if (i<=j+k*n) A=s[i],B=(i-a+1)%mod,C=-(b-j-n*k+1)%mod;
            else A=s[i],B=(j+k*n-a+1)%mod,C=-(b-i+1)%mod;
            upd(ans,A*B%mod*C%mod*s0);
            upd(ans,(A*B%mod+B*C%mod+C*A)%mod*n%mod*s1);
            upd(ans,(A+B+C)%mod*n%mod*n%mod*s2);
            upd(ans,n*n%mod*n%mod*s3);
            // for (LL t=l;t<=r;++t){
            //     if (i<=j+k*n) upd(ans,(s[i]+t*n)*(i+t*n-a+1)*(b-j-(t+k)*n+1));
            //     else upd(ans,(s[i]+t*n)*(j+(t+k)*n-a+1)*(b-i-t*n+1));
            //     // cerr<<s[i]+t*n<<' '<<s[j]+(t+k)*n<<' '<<(i+t*n)<<' '<<(j+(t+k)*n)<<' '<<(i+t*n-a+1)<<' '<<(b-j-(t+k)*n+1)<<endl;
            // }
        }
    }
    ans*=-1;
    upd(ans,mod);
    cout<<ans<<'\n';
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    LL T; cin>>T;
    while (T--) solve();
}

详细

Test #1:

score: 100
Accepted
time: 561ms
memory: 3452kb

input:

430
6 914575 1823342
2 14 26 32 80 98
6 968417 1985938
1 59 28 25 79 60
4 153020 1466079
71 34 10 2
10 996221 1688188
22 42 59 69 92 72 52 52 82 72
6 142341 1628756
91 19 55 43 49 79
2 860345 1156551
74 40
9 276848 1604010
76 12 40 30 83 20 58 97 76
5 886718 1121954
92 57 47 32 42
10 602581 1020483
...

output:

859394676
559509681
787220196
693198410
563990423
919827834
799518457
61584895
313931966
663921331
760107172
283514211
582538287
52316335
811913179
28918969
768328262
95583791
489827987
612318061
362003880
544647001
965717551
928791871
620709166
551257293
115499760
586947052
849302014
299179050
4607...

result:

ok 430 lines