QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#744411 | #9631. Median Replacement | Nightsky | WA | 2ms | 3928kb | C++14 | 2.6kb | 2024-11-13 21:50:19 | 2024-11-13 21:50:19 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 505;
const int MOD = 1e9 + 7;
ll L[MAXN],R[MAXN],x[MAXN],X[MAXN],Y[MAXN],f[MAXN][2][2];
int n;
ll qpw(ll x,ll b)
{
ll ans = 1;
while(b)
{
if(b&1) ans = ans * x %MOD;
x = x * x % MOD;
b >>= 1;
}
return ans;
}
ll Lag(ll *X,ll *Y,ll o,int n)
{
ll ans=0;
for(int i = 1; i <= n; ++i)
{
ll fz = 1,fm = 1;
for(int j = 1; j <= n; ++j)
{
if(i==j) continue;
fz = fz * (o - X[j]) % MOD;
fm = fm * (X[i] - X[j]) % MOD;
}
if(fz < 0) fz += MOD;
if(fm < 0) fm += MOD;
ans = (ans + fz * qpw(fm,MOD-2) % MOD * Y[i] % MOD) %MOD;
}
return ans;
}
ll DP(ll x)
{
ll sum = 1;
f[0][0][0]=1;
for(int i = 1; i <= n; ++i)
{
sum = sum * (R[i] - L[i] + 1) % MOD;
f[i][0][0] = (f[i-1][1][0] + f[i-1][0][0]) * (x > L[i]?min(R[i]+1,x) - L[i] :0) % MOD;
f[i][1][0] = f[i-1][0][1] * (x > L[i]?min(x,R[i]+1) - L[i]:0) % MOD;
f[i][0][1] = f[i-1][0][0] * (x <= R[i]?R[i] - max(x,L[i]) + 1:0) % MOD;
}
return ((sum - f[n][0][0] - f[n][0][1] - f[n][1][0]) % MOD + MOD) % MOD;
}
int main()
{
int T;scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i = 1; i <= n; ++i) scanf("%lld",&L[i]);
for(int i = 1; i <= n; ++i) scanf("%lld",&R[i]);
for(int i = 1; i <= n; ++i)
{
x[i] = L[i];
x[i + n] = R[i];
}
int tot = 2 * n;
x[++tot] = 1;x[++tot] = 1e9+1;
sort(x+1,x+1+tot);
tot = unique(x+1,x+1+tot) - x - 1;
// cout<<"x:"<<endl;
// for(int i = 1; i <= tot; ++i) cout<<x[i]<<" ";
// cout<<endl;
// cout<<"DP:"<<endl;
// cout<<DP(1)<<" "<<DP(2)<<" "<<DP(3)<<endl;
ll ans = 0;
for(int i = 1; i <= tot; ++i)
{
int j = min(i + 200ll,x[i+1]);
for(int k = x[i]; k < j; ++k)
{
X[k - x[i] + 1] = k;
Y[k - x[i] + 1] = DP(k);
}
if(j < x[i+1])
{
for(int k = x[i]; k < j; ++k)
Y[k - x[i] + 1] = (Y[k - x[i] + 1] + Y[k - x[i]]) % MOD;
ans = (ans + Lag(X,Y,j - 1,j - i));
}
else
{
for(int k = x[i]; k < j; ++k)
ans = (ans + Y[k - x[i] + 1]) % MOD;
}
}
printf("%lld\n",ans);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3824kb
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: 2ms
memory: 3928kb
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: -100
Wrong Answer
time: 2ms
memory: 3868kb
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 223
result:
wrong answer 10th lines differ - expected: '224', found: '223'