QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#748698#9631. Median ReplacementhewanyingWA 0ms3868kbC++141.7kb2024-11-14 21:07:262024-11-14 21:07:26

Judging History

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

  • [2024-11-14 21:07:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3868kb
  • [2024-11-14 21:07:26]
  • 提交

answer

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

const int N=155,H=1e9+7;
int n,l[N],r[N],tot=1,f[N][3],a[N<<2],len,ans;

int adc(int a,int b){return a+b>=H?a+b-H:a+b;}
int dec(int a,int b){return a<b?a-b+H:a-b;}
int mul(int a,int b){return 1ll*a*b%H;}
void add(int &a,int b){a=adc(a,b);}
void del(int &a,int b){a=dec(a,b);}

int qpow(int a,int b=H-2){
  int res=1;
  while(b){if(b&1) res=mul(res,a);a=mul(a,a),b>>=1;}
  return res;
}

int Len(int l,int r){return max(0,r-l+1);}

int F(int x){
  f[0][0]=1;
  for(int i=1;i<=n;i++){
    f[i][0]=mul(Len(l[i],min(r[i],x-1)),adc(f[i-1][0],f[i-1][2]));
    f[i][1]=mul(Len(max(l[i],x),r[i]),f[i-1][0]);
    f[i][2]=mul(Len(l[i],min(r[i],x-1)),f[i-1][1]);
  }
  int res=tot;
  for(auto i:{0,1,2}) del(res,f[n][i]);
  return res;
}

int Lag(vector<int> &X,vector<int> &Y,int pos){
  int res=0,m=(int)X.size();
  for(int i=0;i<m;i++){
    int cur=Y[i];
    for(int j=0;j<m;j++) if(j!=i) cur=mul(cur,mul(dec(pos,X[j]),qpow(dec(X[i],X[j]))));
    add(res,cur);
  }
  return res;
}

void SOLVE(){
  cin>>n,tot=1,len=ans=0;
  for(int i=1;i<=n;i++) cin>>l[i],a[++len]=l[i]-1;
  for(int i=1;i<=n;i++) cin>>r[i],tot=mul(tot,r[i]-l[i]+1),a[++len]=r[i];
  sort(a+1,a+len+1),len=unique(a+1,a+len+1)-a-1;
  
  for(int i=1;i<len;i++){
    int L=a[i]+1,R=a[i+1];
    if(Len(L,R)<=n+2) for(int x=L;x<=R;x++) add(ans,F(x));
    else{
      vector<int> X(0),Y(0);
      for(int x=L,s=0;x<=L+n+1;x++) add(s,F(x)),X.pb(x),Y.pb(s);
      add(ans,Lag(X,Y,R));
    }
  }
  cout<<ans<<'\n';
}

int main(){
  ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  int _;cin>>_;
  while(_--) SOLVE();
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3868kb

input:

10
5
5 1 4 3 2
14 2 5 3 2
5
4 5 1 2 3
13 7 1 2 3
5
5 2 5 3 1
10 2 12 3 2
5
5 5 3 1 5
57 5 3 1 5
5
2 2 3 3 5
4 5 4 4 5
5
4 5 3 5 3
13 7 3 5 3
5
5 1 4 2 3
14 3 4 2 3
5
1 2 5 4 5
2 8 5 7 5
5
1 1 3 5 1
8 2 3 8 1
5
4 4 4 2 3
5 10 5 2 3

output:

180
170
650
265
134
113
120
296
192
103

result:

wrong answer 5th lines differ - expected: '182', found: '134'