QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136862#240. Period SequenceRd_rainydays#100 ✓501ms4040kbC++202.0kb2023-08-09 13:05:352023-08-09 13:05:37

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:05:37]
  • 评测
  • 测评结果:100
  • 用时:501ms
  • 内存:4040kb
  • [2023-08-09 13:05:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(int i=(a),i##_end_=(b);i<i##_end_;++i)
#define ll long long

static const int M=100003;
static const int Mod=1000000007;

int T,n,A[M],Inv[M];
ll AP,BP,B[M];
int main(){

  Inv[0]=Inv[1]=1;
  REP(i,2,M)
    Inv[i]=1ll*(Mod-Mod/i)*Inv[Mod%i]%Mod;

  scanf("%d",&T);
  while(T--){
    scanf("%d",&n);
    scanf("%lld%lld",&AP,&BP);
    REP(i,0,n)scanf("%d",&A[i]);

    ll Ans=0;
/*
    ll Tmp=0;
    REP(i,0,n)B[i]=A[i];
    REP(i,n,BP+1)B[i]=B[i-n]+n;
    REP(i,AP,BP+1)REP(j,AP,BP+1)
      if( B[i]==B[j]){
        Tmp+=B[i]*(min(i,j)-AP+1)*(BP-max(i,j)+1);
        //cout<<i<<','<<j<<','<<B[i]<<','<<B[j]<<endl;
      }
    cout<<Tmp<<endl;
*/
    REP(i,0,n)REP(j,0,n){
      if(!((A[i]-A[j])%n)){
        ll t=(A[i]-A[j])/n;
        ll l=i,r=j,p;
        if(t<0)p=A[l]-t*n,l-=t*n;
        else p=A[r]+t*n,r+=t*n;

        if(l>r)swap(l,r);
        t=llabs(t)*n;
        t=n;
        
        //cerr<<l<<','<<r<<','<<p<<endl;
        if(l<AP){
          ll add=(AP-l+t-1)/t*t;
          l+=add,r+=add,p+=add;
        }

        if(r>BP)continue;
        //cerr<<l<<','<<r<<','<<p<<endl;

        ll m=(BP-r)/t+1;
        ll x=(l-AP+1)%Mod;
        ll y=(BP-r+1)%Mod;
        p%=Mod;
        t%=Mod;

        ll s0=m%Mod;
        ll s1=(m-1)%Mod*(m%Mod)%Mod*Inv[2]%Mod;
        ll s2=(m-1)%Mod*(m%Mod)%Mod*((2*m-1)%Mod)%Mod*Inv[6]%Mod;
        ll s3=s1*s1%Mod;
        //if(t!=8 || l==r)continue;
        //cout<<"***"<<l<<','<<r<<','<<x<<','<<y<<','<<p<<','<<t<<','<<m<<endl;

        (Ans+=s0*(x*y%Mod*p%Mod)%Mod )%=Mod;
        (Ans+=s1*(x*y%Mod*t%Mod)%Mod )%=Mod;
        (Ans+=s1*(y*p%Mod*t%Mod)%Mod )%=Mod;
        (Ans-=s1*(x*p%Mod*t%Mod)%Mod )%=Mod;
        (Ans-=s2*(x*t%Mod*t%Mod)%Mod )%=Mod;
        (Ans+=s2*(y*t%Mod*t%Mod)%Mod )%=Mod;
        (Ans-=s2*(p*t%Mod*t%Mod)%Mod )%=Mod;
        (Ans-=s3*(t*t%Mod*t%Mod)%Mod )%=Mod;
      }
    }
    printf("%lld\n",(Ans+Mod)%Mod);
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 501ms
memory: 4040kb

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