Submission #34955958
Source Code Expand
use proconio::input;
fn arithmetic_series(a: u128, n: u128, d: u128) -> u128 {
if n == 0 {
return 0;
}
let last = a + (n - 1) * d;
(a + last) * n / 2
}
const M: u128 = 998244353;
fn f(_n: u128, m: u128, a: u128, b: u128, c: u128, d: u128) -> u128 {
if a > b {
return 0;
}
let x = if (a + c) % 2 == 0 {
(a - 1) * m + c
} else {
(a - 1) * m + (c + 1)
};
let width = match ((a + c) % 2, (a + d) % 2) {
(0, 0) => (d - c) / 2 + 1,
(0, 1) => (d - c) / 2 + 1,
(1, 0) => (d - c) / 2 + 1,
(1, 1) => (d - c) / 2,
_ => unreachable!(),
};
let s0 = arithmetic_series(x, width, 2);
let height = (b - a) / 2 + 1;
let t = arithmetic_series(0, height, m * 2);
(s0 * height % M + t * width % M) % M
}
fn solve(n: u128, m: u128, a: u128, b: u128, c: u128, d: u128) {
let ans = f(n, m, a, b, c, d) + f(n, m, a + 1, b, c, d);
println!("{}", ans % M);
}
fn main() {
input! {
n: u128,
m: u128,
q: usize,
};
for _ in 0..q {
input! {
a: u128,
b: u128,
c: u128,
d: u128,
};
solve(n, m, a, b, c, d);
}
}
Submission Info
Submission Time |
|
Task |
F - Numbered Checker |
User |
ikd |
Language |
Rust (1.42.0) |
Score |
500 |
Code Size |
1297 Byte |
Status |
AC |
Exec Time |
757 ms |
Memory |
10148 KiB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
All |
sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_01.txt |
AC |
6 ms |
2080 KiB |
sample_02.txt |
AC |
1 ms |
2028 KiB |
sample_03.txt |
AC |
1 ms |
2132 KiB |
test_01.txt |
AC |
1 ms |
2012 KiB |
test_02.txt |
AC |
3 ms |
1976 KiB |
test_03.txt |
AC |
301 ms |
3908 KiB |
test_04.txt |
AC |
339 ms |
4160 KiB |
test_05.txt |
AC |
541 ms |
9660 KiB |
test_06.txt |
AC |
564 ms |
10088 KiB |
test_07.txt |
AC |
549 ms |
10028 KiB |
test_08.txt |
AC |
757 ms |
10072 KiB |
test_09.txt |
AC |
542 ms |
9636 KiB |
test_10.txt |
AC |
565 ms |
10044 KiB |
test_11.txt |
AC |
539 ms |
9664 KiB |
test_12.txt |
AC |
557 ms |
10048 KiB |
test_13.txt |
AC |
552 ms |
10060 KiB |
test_14.txt |
AC |
540 ms |
9776 KiB |
test_15.txt |
AC |
539 ms |
9580 KiB |
test_16.txt |
AC |
531 ms |
9588 KiB |
test_17.txt |
AC |
555 ms |
9948 KiB |
test_18.txt |
AC |
559 ms |
9988 KiB |
test_19.txt |
AC |
542 ms |
9980 KiB |
test_20.txt |
AC |
558 ms |
10040 KiB |
test_21.txt |
AC |
567 ms |
10104 KiB |
test_22.txt |
AC |
531 ms |
9652 KiB |
test_23.txt |
AC |
561 ms |
9988 KiB |
test_24.txt |
AC |
560 ms |
10116 KiB |
test_25.txt |
AC |
543 ms |
10016 KiB |
test_26.txt |
AC |
533 ms |
9628 KiB |
test_27.txt |
AC |
561 ms |
10096 KiB |
test_28.txt |
AC |
539 ms |
9908 KiB |
test_29.txt |
AC |
573 ms |
10104 KiB |
test_30.txt |
AC |
572 ms |
9676 KiB |
test_31.txt |
AC |
558 ms |
10044 KiB |
test_32.txt |
AC |
568 ms |
10116 KiB |
test_33.txt |
AC |
570 ms |
9704 KiB |
test_34.txt |
AC |
558 ms |
10132 KiB |
test_35.txt |
AC |
567 ms |
10148 KiB |
test_36.txt |
AC |
578 ms |
9692 KiB |
test_37.txt |
AC |
561 ms |
10140 KiB |
test_38.txt |
AC |
570 ms |
10104 KiB |
test_39.txt |
AC |
570 ms |
9692 KiB |
test_40.txt |
AC |
562 ms |
10120 KiB |