QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#737236#9631. Median ReplacementWedonotLikeStudyingWA 1ms3776kbC++232.3kb2024-11-12 15:09:332024-11-12 15:09:33

Judging History

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

  • [2024-11-12 15:09:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3776kb
  • [2024-11-12 15:09:33]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(a,b,c) for(int a=(b);a<=(c);a++)
#define per(a,b,c) for(int a=(b);a>=(c);a--)
#define mem(a,b) memset(a,b,sizeof(a))
#define vi vector<int>
#define pb push_back
using namespace std;

template<class T>inline void read(T &x) {
    T f=1; x=0; char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    x*=f;
}

const int p=1e9+7;
inline int ksm(int a,int b) { int ans=1; for(;b;b>>=1,a=1ll*a*a%p) if(b&1) ans=1ll*a*ans%p; return ans; }
inline int inc(int x,int y) { if((x+=y)>=p) x-=p; return x; }
inline int dec(int x,int y) { if((x-=y)<0) x+=p; return x; }
inline void Inc(int &x,int y) { x=inc(x,y); }
inline void Dec(int &x,int y) { x=dec(x,y); }

int n,l[305],r[305],ans,l1,l2,f[155][2][2][2],le[305],pos[3005],m,sz,ct[305],xs[305],cx[305],cy[305],ccl,cnt;

inline int DP(int va) {
    mem(f,0);
    f[0][0][0][0]=1;
    rep(i,1,n) rep(j,0,1) rep(k,0,1) rep(al,0,1) {
        if(va<=r[i]) {
            if(va>l[i]) Inc(f[i][k][0][al],1ll*f[i-1][j][k][al]*va-l[i]%p);
            Inc(f[i][k][1][al|j|k],1ll*f[i-1][j][k][al]*(1+r[i]-max(l[i],va))%p);
        }
        else {
            Inc(f[i][k][0][al],1ll*le[i]*f[i-1][j][k][al]%p);
        }
    }
    int tmp=0;
    rep(i,0,1) rep(j,0,1) Inc(tmp,f[n][i][j][1]);
    cnt++;
    return tmp;
}

inline void solve() {
    m=0;
    read(n);
    rep(i,1,n) read(l[i]),pos[++m]=l[i]-1;
    rep(i,1,n) read(r[i]),pos[++m]=r[i];
    rep(i,1,n) le[i]=r[i]-l[i]+1;
    pos[++m]=0;
    ans=0;
    sort(pos+1,pos+m+1);
    sz=unique(pos+1,pos+m+1)-pos-1;
    rep(asd_a,1,sz-1) {
        int L=pos[asd_a]+1,R=pos[asd_a+1];
        if((R-L+1)<=n) {
            rep(i,L,R) Inc(ans,DP(i));
        }
        else {
            ccl=0;
            rep(i,L,L+n+1) cx[++ccl]=i,cy[ccl]=DP(i);
            rep(i,2,ccl) Inc(cy[i],cy[i-1]);
            rep(i,1,ccl) {
                int tmp=cy[i],fk=1;
                rep(j,1,ccl) if(i!=j) {
                    tmp=1ll*tmp*dec(R,cx[j])%p;
                    fk=1ll*fk*dec(cx[i],cx[j])%p;
                }
                Inc(ans,1ll*tmp*ksm(fk,p-2)%p);
            }
        }
    }
    printf("%d\n",ans);
}

int main() {
    int T; read(T);
    while(T--)
    solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3776kb

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:

294966716
-510
-2186
-705033514
-2084
-519
294966852
-252
-288
-1489

result:

wrong answer 1st lines differ - expected: '180', found: '294966716'