結果

問題 No.2452 Incline
ユーザー otoshigo
提出日時 2023-09-01 21:57:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 907 bytes
コンパイル時間 826 ms
コンパイル使用メモリ 75,944 KB
最終ジャッジ日時 2025-02-16 16:35:06
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<atcoder/modint>
using namespace std;
using ll=long long;
using mint=atcoder::modint998244353;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

mint f(ll N,ll M,ll X){
    if(X<0)return 0;
    ll d=M%N;
    mint ans=0;
    mint K=M/N,P=(X/N)*(d+1);
    if(X%N<d)P+=X%N+1;
    else P+=d+1;
    ans+=(K+1)*P;
    mint L=K-1,Q=(X/N)*(N-d-1);
    if(X%N>d)Q+=X%N-d;
    ans+=(L+1)*Q;
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin>>T;
    while(T--){
        ll N,M,L,R;
        cin>>N>>M>>L>>R;
        N--;
        mint ans=f(N,M,R)-f(N,M,L-1);
        cout<<ans.val()<<"\n";
    }
}
0