結果

問題 No.2452 Incline
ユーザー SSRSSSRS
提出日時 2023-09-01 22:04:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 400 ms / 2,000 ms
コード長 1,040 bytes
コンパイル時間 2,255 ms
コンパイル使用メモリ 206,796 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-01 22:04:25
合計ジャッジ時間 5,750 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 400 ms
4,376 KB
testcase_04 AC 344 ms
4,376 KB
testcase_05 AC 328 ms
4,376 KB
testcase_06 AC 336 ms
4,380 KB
testcase_07 AC 322 ms
4,380 KB
testcase_08 AC 261 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main(){
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    long long N, M, L, R;
    cin >> N >> M >> L >> R;
    M++;
    R++;
    vector<long long> x = {0, N - 1, M % (N - 1), L % (N - 1), R % (N - 1)};
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(), x.end()), x.end());
    int cnt = x.size() - 1;
    vector<long long> A(cnt + 1, 0);
    A[0] += M / (N - 1) + 1;
    A[lower_bound(x.begin(), x.end(), M % (N - 1)) - x.begin()]--;
    vector<long long> B(cnt + 1, 0);
    B[0] += R / (N - 1) + 1;
    B[lower_bound(x.begin(), x.end(), R % (N - 1)) - x.begin()]--;
    B[0] -= L / (N - 1) + 1;
    B[lower_bound(x.begin(), x.end(), L % (N - 1)) - x.begin()]++;
    for (int j = 0; j < cnt; j++){
      A[j + 1] += A[j];
      B[j + 1] += B[j];
    }
    long long ans = 0;
    for (int j = 0; j < cnt; j++){
      ans += (A[j] % MOD) * (B[j] % MOD) % MOD * ((x[j + 1] - x[j]) % MOD);
      ans %= MOD;
    }
    cout << ans << endl;
  }
}
0