QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#756993#9631. Median ReplacementdsakhdkasWA 0ms3672kbC++143.3kb2024-11-16 23:20:122024-11-16 23:20:13

Judging History

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

  • [2024-11-16 23:20:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3672kb
  • [2024-11-16 23:20:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int Mod=1e9+7,N=160;
int L[155],R[155];
int a[310],n;
int sum;
int f[155][3];
int ans=0;
int c[160];
int inv[500];
int ksm(int aa,int bb)
{
    int res=1;
    for (;bb;bb>>=1) {
        if (bb&1) res=1LL*res*aa%Mod;
        aa=1LL*aa*aa%Mod;
    }
    return res;
}
int Calc(int l,int r)
{
    int res=0;
    for (int i=1;i<=n+2;i++) {
        int s=c[i];
        for (int j=1;j<=n+2;j++)
          if (j!=i) s=1LL*s*(r-(l+j-1))*inv[i-j+N]%Mod;
        res=(res+s)%Mod;
    }
    return res;
}
void Solve(int l,int r)
{
    if (r-l+1<=n+2) {
        for (int x=l;x<=r;x++) {
            f[0][0]=1;f[0][1]=0;f[0][2]=0;
            for (int i=1;i<=n;i++) {
                f[i][0]=f[i][1]=f[i][2]=0;
                if (L[i]>x) {
                    f[i][2]=1LL*f[i-1][0]*(R[i]-L[i]+1)%Mod;
                }
                else if (R[i]<x) {
                    f[i][0]=1LL*(f[i-1][0]+f[i-1][1])%Mod*(R[i]-L[i]+1)%Mod;
                    f[i][1]=1LL*f[i-1][2]*(R[i]-L[i]+1)%Mod;
                }
                else {
                    f[i][0]=1LL*(f[i-1][0]+f[i-1][1])%Mod*(x-L[i])%Mod;
                    f[i][1]=1LL*f[i-1][2]*(x-L[i])%Mod;
                    f[i][2]=1LL*f[i-1][0]*(R[i]-x+1)%Mod;
                }
            }
            ans=(ans+sum)%Mod;
            ans=(ans-f[n][0])%Mod;
            ans=(ans-f[n][1])%Mod;
            ans=(ans-f[n][2])%Mod;
            ans=(ans+Mod)%Mod;
        }
    }
    else {
        for (int x=l;x<=l+n+1;x++) {
            f[0][0]=1;f[0][1]=0;f[0][2]=0;
            for (int i=1;i<=n;i++) {
                f[i][0]=f[i][1]=f[i][2]=0;
                if (L[i]>x) {
                    f[i][2]=1LL*f[i-1][0]*(R[i]-L[i]+1)%Mod;
                }
                else if (R[i]<x) {
                    f[i][0]=1LL*(f[i-1][0]+f[i-1][1])%Mod*(R[i]-L[i]+1)%Mod;
                    f[i][1]=1LL*f[i-1][2]*(R[i]-L[i]+1)%Mod;
                }
                else {
                    f[i][0]=1LL*(f[i-1][0]+f[i-1][1])%Mod*(x-L[i])%Mod;
                    f[i][1]=1LL*f[i-1][2]*(x-L[i])%Mod;
                    f[i][2]=1LL*f[i-1][0]*(R[i]-x+1)%Mod;
                }
            }
            int res=sum;
            res=(res-f[n][0])%Mod;
            res=(res-f[n][1])%Mod;
            res=(res-f[n][2])%Mod;
            res=(res+Mod)%Mod;
            c[x-l+1]=(c[x-l]+res)%Mod;
        }
    ans=(ans+Calc(l,r))%Mod;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin>>T;
    for (int i=-N;i<=N;i++) inv[i+N]=ksm((i+Mod)%Mod,Mod-2);
    while (T--) {
        cin>>n;
        int num=0;
        a[++num]=1;
        for (int i=1;i<=n;i++) {
            cin>>L[i];
            a[++num]=L[i];
        }
        for (int i=1;i<=n;i++) {
            cin>>R[i];
            a[++num]=R[i];
        }
        sort(a+1,a+num+1);
        int tot=0;
        for (int i=1;i<=num;i++)
          if (a[i]!=a[tot]) a[++tot]=a[i];
        sum=1;
        for (int i=1;i<=n;i++) sum=1LL*sum*(R[i]-L[i]+1)%Mod;
        ans=0;
        for (int i=1;i<tot;i++)
          Solve(a[i],a[i+1]-1);
        Solve(a[tot],a[tot]);
        cout<<ans<<'\n';
    }
    return 0;
}
/*
1
5
5 1 4 3 2
14 2 5 3 2
*/

详细

Test #1:

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

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
80979394
182
173
120
296
192
131

result:

wrong answer 4th lines differ - expected: '265', found: '80979394'