結果
| 問題 |
No.2452 Incline
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2023-09-01 22:04:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 442 ms / 2,000 ms |
| コード長 | 1,040 bytes |
| コンパイル時間 | 2,132 ms |
| コンパイル使用メモリ | 201,896 KB |
| 最終ジャッジ日時 | 2025-02-16 16:39:28 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 |
ソースコード
#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;
}
}
SSRS