結果

問題 No.2452 Incline
ユーザー ochiaigawaochiaigawa
提出日時 2023-09-01 23:24:50
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,101 bytes
コンパイル時間 2,077 ms
コンパイル使用メモリ 196,316 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-01-03 12:27:32
合計ジャッジ時間 4,048 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0