QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#136794 | #240. Period Sequence | Delay_for_five_minutes# | 100 ✓ | 438ms | 3560kb | C++20 | 2.6kb | 2023-08-09 11:40:57 | 2023-08-09 11:41:00 |
Judging History
answer
#include<bits/stdc++.h>
const int mod = 1000000007;
const int inv6 = 166666668;
const int inv2 = 500000004;
int n;
long long a,b;
int s[2005];
long long sum0(long long l, long long r) {
return (r - l + 1)%mod;
}
long long sum1(long long R) {
if (R < 0) return 0;
R %= mod;
return 1ll * R * (R + 1) %mod * inv2 % mod;
}
long long sum1(long long l, long long r) {
return ( sum1(r) - sum1(l - 1) + mod ) %mod;
}
long long sum2(long long R) {
if (R < 0) return 0;
R %= mod;
return R * (R + 1) %mod * (2 * R + 1) %mod * inv6 % mod;
}
long long sum2(long long l, long long r) {
return ( sum2(r) - sum2(l - 1) + mod ) %mod;
}
long long sum3(long long R) {
if (R < 0) return 0;
return sum1(R) * sum1(R) % mod;
}
long long sum3(long long l, long long r) {
return ( sum3(r) - sum3(l - 1) + mod ) %mod;
}
long long solve(int i,int j) {
long long l1 = (a - i + n - 1) / n;
long long r1 = (b - i) / n;
long long l2 = (a - j + n - 1) / n;
long long r2 = (b - j) / n;
if (l1 < 0) l1 = 0;
if (l2 < 0) l2 = 0;
if (j + n * r2 > b) r2 --;
if (i + n * r1 > b) r1 --;
int t = ( s[j] - s[i] ) / n;
r2 += t;
l2 += t;
long long r = std::min(r1,r2), l = std::max(l1,l2);
if (l > r) return 0;
// printf("%d,%d [%d,%d]\n",i,j,l,r);
long long C1 = (b - i + 1 + mod) % mod;;
long long C2 = ((j - t * n - a + 1) % mod + mod) % mod;
long long A = (mod - 1ll*n*n*n%mod);
long long B = 1ll * n * n * (-C2 + C1 - s[i] + 2 * mod) % mod;
long long C = 1ll * n * ((C1 * C2 - s[i] * C2 + s[i] * C1) % mod + mod )% mod;
long long D = 1ll * s[i] * C1 % mod * C2 % mod;
long long ans = 0;
ans += A * sum3(l,r) %mod;
ans += B * sum2(l,r) %mod;
ans += C * sum1(l,r) %mod;
ans += D * sum0(l,r) %mod;
// printf("[%d,%d]%lld\n",i,j,ans);
return ans % mod;
}
void solve() {
std::cin >> n >> a >> b;
for(int i=0;i<n;i++) {
std::cin >> s[i];
}
int ans = 0;
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) if ((s[j] - s[i]) % n == 0){
if (s[j] > s[i]) {
ans+=solve(i,j);
}
else if (s[i] > s[j]) {
ans+=solve(j,i);
}
else {
ans+=solve(std::max(i,j),std::min(i,j));
}
ans%=mod;
}
}
printf("%d\n",ans);
}
int main() {
// freopen("in.txt","r",stdin);
// freopen("out2.txt","w",stdout);
std::ios::sync_with_stdio(0);std::cin.tie(0);
int T;
std::cin >> T;
while(T--) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 438ms
memory: 3560kb
input:
430 6 914575 1823342 2 14 26 32 80 98 6 968417 1985938 1 59 28 25 79 60 4 153020 1466079 71 34 10 2 10 996221 1688188 22 42 59 69 92 72 52 52 82 72 6 142341 1628756 91 19 55 43 49 79 2 860345 1156551 74 40 9 276848 1604010 76 12 40 30 83 20 58 97 76 5 886718 1121954 92 57 47 32 42 10 602581 1020483 ...
output:
859394676 559509681 787220196 693198410 563990423 919827834 799518457 61584895 313931966 663921331 760107172 283514211 582538287 52316335 811913179 28918969 768328262 95583791 489827987 612318061 362003880 544647001 965717551 928791871 620709166 551257293 115499760 586947052 849302014 299179050 4607...
result:
ok 430 lines