QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#20636 | #2603. Disbalance | linmuhan# | TL | 29ms | 34968kb | C++20 | 1.1kb | 2022-02-16 21:50:25 | 2022-05-03 10:52:23 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2000010, B = 2000000;
const ll mod = 998244353;
ll qpow (ll a, int b) {
ll ans = 1;
while (b) {
if (b & 1) ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
ll fac[N], ifac[N];
int T, n, k;
ll g (int n, int m) {
if ((n + m) & 1) {
int b = (m - n + 1) / 2;
ll tmp = 1;
tmp = fac[n + b - 1] * fac[n + 2 * b] % mod;
tmp = tmp * ifac[b] % mod * ifac[2 * n + 2 * b - 2] % mod;
return tmp;
} else {
int b = (m - n) / 2;
ll tmp = 1;
tmp = 2 * fac[n + b] % mod * fac[n + 2 * b] % mod;
tmp = tmp * ifac[b] % mod * ifac[2 * n + 2 * b - 1] % mod;
return tmp;
}
}
int main () {
cin >> T;
fac[0] = 1; for (int i=1;i<=B;i++) fac[i] = fac[i - 1] * i % mod;
ifac[B] = qpow (fac[B], mod - 2);
for (int i=B-1;i>=0;i--) ifac[i] = ifac[i + 1] * (i + 1) % mod;
while (T --) {
cin >> n >> k;
ll Ans = 0;
for (int m=n-1;m<=k;m++) {
Ans = (Ans + g (n, m)) % mod;
}
if (n == 1) {
Ans = 0;
for (int m=1;m<=k;m++) Ans += m + 1, Ans %= mod;
}
cout << Ans << endl;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 22ms
memory: 34816kb
input:
8 1 1 1 2 2 1 2 2 3 1 3 2 3 3 4 3
output:
2 5 1 332748120 0 499122177 299473307 598946612
result:
ok 8 numbers
Test #2:
score: 0
Accepted
time: 23ms
memory: 34968kb
input:
20 9 12 2 6 9 14 3 7 1 2 1 2 10 11 6 7 10 13 7 4 1 3 4 4 2 2 1 5 10 9 6 10 7 5 7 4 10 7 4 3
output:
601023541 104577993 588440629 323241035 5 5 537116365 615800088 583321633 0 9 570425345 332748120 20 334869712 974144215 0 0 0 598946612
result:
ok 20 numbers
Test #3:
score: 0
Accepted
time: 11ms
memory: 34812kb
input:
20 7 12 8 12 1 1 1 6 2 11 5 4 6 13 7 13 6 8 1 5 7 13 2 8 3 10 8 9 5 3 1 2 5 6 10 8 4 3 3 3
output:
269558826 522207092 2 27 245743886 926941185 375649298 628061442 401724376 20 628061442 880990276 368615785 683801260 0 5 126761188 0 598946612 299473307
result:
ok 20 numbers
Test #4:
score: 0
Accepted
time: 29ms
memory: 34836kb
input:
20 1 5 2 5 10 12 10 12 3 3 9 11 6 7 1 8 8 8 1 3 9 5 9 9 3 6 2 4 10 13 10 9 3 9 5 7 7 6 6 8
output:
20 532396998 374710197 374710197 299473307 973433586 615800088 44 278918935 9 0 347599278 655989151 532396995 583321633 334869712 867737959 671258108 688183607 401724376
result:
ok 20 numbers
Test #5:
score: 0
Accepted
time: 22ms
memory: 34928kb
input:
20 2 6 8 10 7 4 3 5 9 9 10 6 2 4 9 13 4 3 8 14 10 13 3 11 5 10 2 11 4 9 5 7 6 8 1 6 8 9 6 13
output:
104577993 760178656 0 156866973 347599278 0 532396995 543627802 598946612 180187355 583321633 522191842 831814893 245743886 907494870 671258108 401724376 27 683801260 375649298
result:
ok 20 numbers
Test #6:
score: 0
Accepted
time: 16ms
memory: 34816kb
input:
20 1 2 4 5 5 10 8 11 5 11 8 14 6 9 8 7 4 12 9 9 7 5 7 8 3 6 10 15 1 8 2 4 4 6 3 2 8 6 4 6
output:
5 142606337 831814893 900203882 627046821 180187355 485493133 134960775 7 347599278 0 877826765 655989151 295767061 44 532396995 332748119 499122177 0 332748119
result:
ok 20 numbers
Test #7:
score: 0
Accepted
time: 24ms
memory: 34804kb
input:
20 6 6 2 8 4 10 8 14 9 6 9 6 9 12 3 2 7 6 4 11 7 4 6 5 9 13 4 10 1 9 2 2 7 7 6 10 7 11 6 4
output:
101552997 880990276 691092249 180187355 0 0 601023541 499122177 688183607 614304223 0 308980395 543627802 691092249 54 332748120 661424143 974144215 328279082 0
result:
ok 20 numbers
Test #8:
score: 0
Accepted
time: 23ms
memory: 34784kb
input:
20 4 11 2 11 8 11 7 9 3 3 9 14 4 11 8 14 3 5 1 6 8 12 8 8 3 11 1 5 3 11 3 9 6 4 6 7 6 13 3 9
output:
614304223 245743886 900203882 176961499 299473307 588440629 614304223 180187355 156866973 27 522207092 278918935 522191842 20 522191842 867737959 0 615800088 375649298 867737959
result:
ok 20 numbers
Test #9:
score: 0
Accepted
time: 18ms
memory: 34816kb
input:
20 1 9 5 10 3 10 8 13 4 4 9 9 2 4 7 9 5 12 2 3 4 3 9 7 7 7 1 3 5 8 3 2 9 13 1 1 7 12 6 6
output:
54 831814893 368615785 448034137 570425345 347599278 532396995 176961499 127924645 332748122 598946612 0 661424143 9 489759135 499122177 543627802 2 269558826 101552997
result:
ok 20 numbers
Test #10:
score: 0
Accepted
time: 20ms
memory: 34832kb
input:
20 8 10 3 9 3 7 8 7 2 7 7 7 2 2 7 7 5 3 7 6 9 14 3 2 10 15 5 7 10 10 5 8 5 3 9 14 4 3 10 9
output:
760178656 867737959 323241035 134960775 104577997 661424143 332748120 661424143 0 688183607 588440629 499122177 295767061 671258108 56894028 489759135 0 588440629 598946612 334869712
result:
ok 20 numbers
Test #11:
score: 0
Accepted
time: 20ms
memory: 34904kb
input:
20 2 11 1 8 4 10 2 2 8 12 3 2 6 8 5 8 9 10 9 6 9 7 9 14 3 5 2 9 1 2 6 10 1 6 4 3 4 7 1 7
output:
245743886 44 691092249 332748120 522207092 499122177 401724376 489759135 38188698 0 0 588440629 156866973 880990281 5 974144215 27 598946612 2 35
result:
ok 20 numbers
Test #12:
score: 0
Accepted
time: 14ms
memory: 34816kb
input:
20 4 6 3 9 4 9 10 9 9 5 5 6 3 7 10 7 3 9 9 13 3 11 3 6 8 13 8 6 9 11 10 11 3 11 8 5 9 5 3 4
output:
332748119 867737959 907494870 334869712 0 126761188 323241035 0 867737959 543627802 522191842 655989151 448034137 0 973433586 537116365 522191842 0 0 299473308
result:
ok 20 numbers
Test #13:
score: 0
Accepted
time: 24ms
memory: 34836kb
input:
20 9 7 5 9 9 11 7 13 5 11 8 11 1 7 5 9 3 11 6 6 4 6 9 13 7 13 6 11 2 6 6 13 6 8 5 7 2 6 5 11
output:
0 524662784 973433586 628061442 627046821 900203882 35 524662784 522191842 101552997 332748119 543627802 628061442 897356188 104577993 375649298 401724376 671258108 104577993 627046821
result:
ok 20 numbers
Test #14:
score: 0
Accepted
time: 21ms
memory: 34844kb
input:
20 6 12 5 7 10 13 3 6 3 4 3 5 7 9 1 2 4 5 2 4 4 9 10 6 3 10 5 11 8 6 3 3 2 4 6 13 2 6 8 8
output:
581170194 671258108 583321633 655989151 299473308 156866973 176961499 5 142606337 532396995 907494870 0 368615785 627046821 0 299473307 532396995 375649298 104577993 278918935
result:
ok 20 numbers
Test #15:
score: -100
Time Limit Exceeded
input:
300000 1 5 1 6 1 6 1 6 1 6 1 6 1 6 1 6 1 5 1 6 1 6 1 6 1 6 1 5 1 6 1 6 1 5 1 6 1 6 1 6 1 6 1 6 1 5 1 6 1 6 1 6 1 5 1 6 1 5 1 6 1 6 1 6 1 6 1 5 1 5 1 5 1 5 1 6 1 6 1 6 1 5 1 6 1 6 1 6 1 6 1 6 1 6 1 6 1 6 1 6 1 5 1 6 1 5 1 6 1 6 1 6 1 6 1 5 1 6 1 6 1 6 1 6 1 6 1 6 1 6 1 5 1 6 1 6 1 6 1 6 1 5 1 6 1 5 1...
output:
20 27 27 27 27 27 27 27 20 27 27 27 27 20 27 27 20 27 27 27 27 27 20 27 27 27 20 27 20 27 27 27 27 20 20 20 20 27 27 27 20 27 27 27 27 27 27 27 27 27 20 27 20 27 27 27 27 20 27 27 27 27 27 27 27 20 27 27 27 27 20 27 20 27 20 27 20 20 27 20 20 27 27 27 27 27 20 20 20 27 20 27 27 20 20 27 20 27 27 27 ...