QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#771580#9631. Median ReplacementccpyWA 432ms3732kbC++202.0kb2024-11-22 14:22:142024-11-22 14:22:20

Judging History

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

  • [2024-11-22 14:22:20]
  • 评测
  • 测评结果:WA
  • 用时:432ms
  • 内存:3732kb
  • [2024-11-22 14:22:14]
  • 提交

answer

#include<bits/stdc++.h>
#define MAX 2005
#define ll long long
using namespace std;
const ll mod=1e9+7;
ll qm(ll x){
    if(x>=mod) x-=mod;
    return x;
}
ll fpow(ll a,ll b){
	ll r=1;
	while(b){
		if(b&1) r=r*a%mod;
		a=a*a%mod; b>>=1;
	} return r;
}
ll inv(ll x){ return fpow(x,mod-2); }
ll x[MAX],y[MAX],len;
ll lglr(ll k){
    ll r=0;
    for(int i=1;i<=len;i++){
		ll top=1,bot=1;
		for(int j=1;j<=len;j++){
			if(j==i) continue;
			top=top*qm(k-x[j]+mod)%mod;
		}
		for(int j=1;j<=len;j++){
			if(j==i) continue;
			bot=bot*qm(x[i]-x[j]+mod)%mod;
		}
		top=top*inv(bot)%mod;
		r=qm(r+top*y[i]%mod);
	}return r;
}
ll n,k;
struct node{
    int l,r;
}p[MAX];
ll c[MAX],cc;
ll get(ll mid){
    ll r=0;
    ll f00=1,f01=0,f10=0;
    for(int i=1;i<=n;i++){
        ll t1=max(p[i].r-mid+1,0ll),t0=max(mid-p[i].l,0ll);
        if(mid<p[i].l) t1=p[i].r-p[i].l+1;
        if(mid>p[i].r) t0=p[i].r-p[i].l+1;
        t0%=mod;t1%=mod;

        r=qm(r*qm(t0+t1)%mod+qm(f10+f01)*t1%mod);
        ll g00=qm(f10+f00)*t0%mod;
        ll g01=f00*t1%mod;
        ll g10=f01*t0%mod;
        f00=g00;f01=g01;f10=g10;
    }return r;
}
ll sol(int L,int R){
    ll r=0;
    if(R-L+1<=n+1){
        for(int i=L;i<=R;i++)
            r=qm(r+get(i));
    }else{
        ll sm=0;len=n+1;
        for(int i=L;i<=L+n+1;i++){
            sm=qm(sm+get(i));
            x[i-L+1]=i;y[i-L+1]=sm;
        }return lglr(R);
    }
    return r;
}
void calc(){
    cin>>n;cc=0;
    for(int i=1;i<=n;i++){
        cin>>p[i].l;c[++cc]=p[i].l;
    }c[++cc]=1;
    for(int i=1;i<=n;i++){
        cin>>p[i].r;
        c[++cc]=p[i].r+1;
    }
    sort(c+1,c+1+cc);
    cc=unique(c+1,c+1+cc)-c-1;
    ll ans=0;
    for(int i=1;i<cc;i++)
        ans=qm(sol(c[i],c[i+1]-1)+ans);
    //for(int i=1;i<=c[cc];i++) cout<<get(i)<<" ";
    //cout<<endl;
    cout<<ans<<"\n";
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;cin>>t;
    while(t--) calc();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

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

result:

ok 10 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3732kb

input:

10
5
1 2 2 5 3
6 4 2 6 3
5
4 4 1 4 3
6 7 2 5 3
5
5 3 4 2 4
5 7 5 2 6
5
1 5 3 5 2
7 7 3 5 2
5
1 3 3 2 2
10 5 3 2 2
5
4 4 4 5 3
4 11 9 5 3
5
5 3 2 1 3
13 5 2 1 5
5
5 4 1 2 5
10 6 1 2 5
5
3 5 3 4 2
5 9 3 5 2
5
1 1 3 2 1
7 3 3 3 1

output:

120
230
144
110
110
289
324
89
140
122

result:

ok 10 lines

Test #3:

score: 0
Accepted
time: 1ms
memory: 3596kb

input:

10
5
3 1 3 4 4
9 1 3 10 4
5
1 1 3 1 1
9 1 3 3 1
5
5 1 2 3 1
74 1 2 3 1
5
2 5 5 3 4
5 6 8 3 4
5
2 1 3 4 5
2 4 6 4 5
5
2 4 2 1 3
2 11 3 2 3
5
1 5 4 4 2
1 14 6 6 2
5
4 1 3 5 1
9 2 4 5 1
5
4 1 2 4 4
6 1 6 4 4
5
3 2 5 3 5
8 8 5 3 5

output:

196
76
140
172
72
80
486
84
65
224

result:

ok 10 lines

Test #4:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

10
5
676437428 903889545 700650370 965758082 146716866
676437431 903889567 700650370 965758082 146716866
5
517457740 64600397 388618400 783268973 388618400
517457797 64600397 388618400 783268973 388618400
5
971452763 106948541 259878781 537741075 9504353
971452780 106948544 259878781 537741075 95043...

output:

157838571
539867046
711272106
123881231
497944943
9791579
539012259
963879245
315607794
495624077

result:

ok 10 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

10
5
462008700 417744555 925098328 70231697 547596413
462008735 417744555 925098328 70231697 547596413
5
294230630 403894618 294230635 403894620 403894617
294230638 403894620 294230635 403894620 403894617
5
757647830 757647826 757647828 184694646 161891480
757647839 757647827 757647830 184694646 161...

output:

713470735
905154643
458869425
477055327
633375786
349097981
980046476
478461437
573246310
810688575

result:

ok 10 lines

Test #6:

score: 0
Accepted
time: 2ms
memory: 3672kb

input:

10
150
7 1 8 8 2 3 8 2 1 3 2 10 9 7 3 9 4 5 4 5 10 7 9 9 9 3 4 7 10 8 5 3 5 1 8 4 1 2 7 9 10 9 1 7 4 7 6 8 7 6 6 7 4 5 10 8 7 10 2 8 1 4 9 2 9 3 9 6 2 2 7 7 10 8 4 10 4 1 7 3 3 5 4 3 9 7 4 1 8 1 4 4 2 7 5 4 9 6 5 8 6 4 8 7 4 6 8 8 2 9 8 3 10 9 2 4 6 10 2 8 9 1 6 6 7 8 8 7 8 8 8 3 4 6 3 8 10 10 10 3 ...

output:

8640
8000
9600
8100
9360
9900
9600
9960
9300
5560

result:

ok 10 lines

Test #7:

score: 0
Accepted
time: 1ms
memory: 3672kb

input:

10
150
5 4 2 6 6 9 4 8 4 9 2 5 4 7 5 4 2 1 10 10 6 5 10 2 5 8 4 2 10 4 10 8 4 1 4 1 6 3 2 4 1 10 10 1 9 7 7 4 7 6 9 2 4 5 2 6 2 9 10 6 6 8 7 7 1 9 1 7 5 3 4 9 5 2 3 2 10 2 9 3 1 3 7 9 8 3 7 2 2 8 8 5 2 4 8 4 10 10 2 1 10 8 10 3 7 1 6 9 9 7 8 1 9 3 7 6 4 9 1 2 7 8 4 8 6 7 4 2 7 3 9 5 6 6 1 1 9 6 3 6 ...

output:

5760
9600
6580
7680
5280
7200
8640
8000
5400
5040

result:

ok 10 lines

Test #8:

score: 0
Accepted
time: 1ms
memory: 3652kb

input:

10
150
1 1 7 5 2 6 5 9 10 2 5 9 10 10 9 5 2 2 8 7 2 10 9 5 10 4 4 10 3 1 3 8 5 8 3 5 9 4 2 1 4 1 3 2 5 4 4 7 10 2 7 10 9 9 1 1 2 4 7 2 1 4 2 4 5 1 6 6 6 5 10 3 7 5 7 7 7 4 3 3 3 5 3 9 9 8 5 7 5 5 1 5 1 5 7 2 1 8 7 7 7 3 8 6 7 8 4 5 10 7 5 7 4 8 7 2 6 6 7 6 2 1 6 6 8 9 3 9 2 7 9 1 2 1 7 7 4 3 3 1 4 3...

output:

8800
8100
5040
5580
9600
7200
6400
5184
7560
8640

result:

ok 10 lines

Test #9:

score: 0
Accepted
time: 425ms
memory: 3700kb

input:

10
150
390717977 225426217 217154512 811659013 811659022 811659006 811659019 811658998 380139276 562680969 391897894 391897902 610662417 702576570 778349151 778349150 144611847 144611847 888681165 952726258 635003873 635003864 365476184 353032583 492888825 492888833 451690481 492888832 492888828 781...

output:

444384507
582048587
4116309
958927956
240831257
919504659
253033294
811573108
93791855
55056035

result:

ok 10 lines

Test #10:

score: 0
Accepted
time: 432ms
memory: 3696kb

input:

10
150
639295555 548367354 795034024 795034022 966256461 795034026 795034019 795034024 795034024 236525600 236525591 236525601 702472531 628995729 702472534 409845953 409845958 430611099 965171120 216366412 173295815 311261799 311261793 113953747 830664527 290505090 830664533 273223393 617764565 273...

output:

937895614
451483826
722427169
185150800
218102505
102966546
445812982
11748745
363947119
423405610

result:

ok 10 lines

Test #11:

score: -100
Wrong Answer
time: 0ms
memory: 3608kb

input:

10
3
544728022 153689801 431863569
962200031 220484001 642878600
3
421093150 239667044 200668081
921717358 939761114 474185560
3
517484553 194763387 57955343
815612679 384192788 271266363
3
214367561 759072795 528460561
303043703 861920493 583504876
3
143012658 242807202 110332706
980720465 65744848...

output:

293616219
355145119
362851773
192424288
166524384
599848071
444732014
160484153
2182519
70392946

result:

wrong answer 2nd lines differ - expected: '48585431', found: '355145119'