結果
問題 | No.2452 Incline |
ユーザー |
|
提出日時 | 2023-09-01 23:24:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 86 ms / 2,000 ms |
コード長 | 1,101 bytes |
コンパイル時間 | 2,104 ms |
コンパイル使用メモリ | 195,516 KB |
最終ジャッジ日時 | 2025-02-16 17:25:59 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/modint> using namespace std; using mint = atcoder::modint998244353; void solve() { long long N, M, L, R; cin >> N >> M >> L >> R; mint ret = 0; ret += mint(L / (N - 1) + 1) * (R - L + 1); // (0 <= k <= L / (N - 1)) // L / (N - 1) + 1 <= k <= R / (N - 1) ret += mint(R - L + 1) * (R / (N - 1) - L / (N - 1)); if(R - (L / (N - 1) + 1) * (N - 1) >= 0) { mint r1 = (L / (N - 1) + 1) * (N - 1) - L; mint d1 = R / (N - 1) - L / (N - 1); ret -= r1 * d1; ret -= d1 * (d1 - 1) / 2 * (N - 1); } ret += mint((M - R) / (N - 1)) * (R - L + 1); // 1 <= k <= (M - R) / (N - 1) ret += mint(R - L + 1) * ((M - L) / (N - 1) - (M - R) / (N - 1)); if(((M - R) / (N - 1) + 1) * (N - 1) + L <= M) { mint r2 = R + ((M - R) / (N - 1) + 1) * (N - 1) - M; mint d2 = (M - L) / (N - 1) - (M - R) / (N - 1); ret -= r2 * d2; ret -= d2 * (d2 - 1) / 2 * (N - 1); } cout << ret.val() << '\n'; } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int T; cin >> T; while(T--) { solve(); } return 0; }