QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771557 | #9631. Median Replacement | ccpy | WA | 0ms | 3672kb | C++20 | 1.8kb | 2024-11-22 14:10:55 | 2024-11-22 14:10:55 |
Judging History
answer
#include<bits/stdc++.h>
#define MAX 2005
#define ll long long
using namespace std;
const ll mod=998244353;
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 f0=1,f1=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+f1*t1%mod);
ll g0=qm(f0+f1)*t0%mod;
ll g1=f0*t1%mod;
f0=g0,f1=g1;
}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);
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: 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:
120 170 288 265 176 170 70 274 192 130
result:
wrong answer 1st lines differ - expected: '180', found: '120'