結果

問題 No.2452 Incline
ユーザー eQeeQe
提出日時 2023-09-01 23:02:16
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 6,388 bytes
コンパイル時間 4,168 ms
コンパイル使用メモリ 154,016 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-01 23:02:22
合計ジャッジ時間 6,256 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#if defined(ATCODER)==defined(ONLINE_JUDGE)
#include<atcoder/all>
#endif
namespace my{void main();}
int main(){my::main();}
namespace my{
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define RD(T,...) T __VA_ARGS__;li(__VA_ARGS__)
#define LL(...) RD(ll,__VA_ARGS__)
#define JO(a,b) a##b
#define jo(a,b) JO(a,b)
#define usymbol(a) jo(a,__LINE__)
#define FE(v,e,...) for(au&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):v)
#define FO(n) for(ll usymbol(i)=n;usymbol(i)-->0;)
#define FOR(i,...) for(au[i,i##O,i##E]=rng(0,__VA_ARGS__);i<i##O;i+=i##E)
#define fee(v,...) FE(v,__VA_ARGS__)
#define foo(i,...) FO##__VA_OPT__(R)(i __VA_OPT__(,__VA_ARGS__))
#define of(i,...) for(au[i,i##O,i##E]=rng(1,__VA_ARGS__);i>=i##O;i-=i##E)
#define I template
#define J class
#define au auto
#define rr return
using namespace std;
using vo=void;using bo=bool;
vo solve();
I<J A,J B>constexpr bo same=is_same_v<A,B>;
using is=istream;using os=ostream;
using dd=long double;using ll=long long;using ull=unsigned long long;
using lll=__int128_t;using ulll=__uint128_t;using str=string;
os&operator<<(os&o,const ulll&x){rr(x<10?o:o<<x/10)<<ll(x%10);}
os&operator<<(os&o,const lll&x){rr o<<str(x<0,'-')<<ulll(x>0?x:-x);}
constexpr dd ee=1e-12;
constexpr ll oo=3e18;
constexpr ll dx[]{-1,0,1,0,-1,1,1,-1},dy[]{0,-1,0,1,-1,-1,1,1};
constexpr char sp=32;
constexpr char nl=10;
au rng(bo s,ll a,ll b=oo,ll c=1){if(b==oo)b=a,(s?b:a)=0;rr tuple{a-s,b,c};}
I<J T>ll len(const T&a){rr a.size();}

I<J A,J B=A>struct cp{
  A a={};B b={};
  cp(){}
  cp(A a,B b):a(a),b(b){}
  cp(pair<A,B>p):a(p.first),b(p.second){}
  bo operator==(const cp&c)const{rr a==c.a&&b==c.b;}
  bo operator<(const cp&c)const{rr a!=c.a?a<c.a:b<c.b;}
  bo operator>(const cp&c)const{rr a!=c.a?a>c.a:b>c.b;}

  friend is&operator>>(is&i,cp&c){rr i>>c.a>>c.b;}
  friend os&operator<<(os&o,const cp&c){rr o<<c.a<<sp<<c.b;}
};using cl=cp<ll>;
I<J A,J B=A,J C=A>struct tr{
  A a={};B b={};C c={};
  tr(){}
  tr(A a,B b,C c):a(a),b(b),c(c){}
  bo operator==(const tr&t)const{rr a==t.a&&b==t.b&&c==t.c;}

  au operator<(const tr&t)const{rr a!=t.a?a<t.a:b!=t.b?b<t.b:c<t.c;}
  friend is&operator>>(is&i,tr&t){rr i>>t.a>>t.b>>t.c;}
  friend os&operator<<(os&o,const tr&t){rr o<<t.a<<sp<<t.b<<sp<<t.c;}
};using tl=tr<ll>;

I<J T,size_t n>using ar=array<T,n>;
I<J T,size_t n>os&operator<<(os&o,const ar<T,n>&a){foo(i,n)o<<a[i]<<str(i!=n-1,sp);rr o;}
I<J T,J U=T>using map=std::map<T,U>;
I<J T,J U>os&operator<<(os&o,const map<T,U>&m){fee(m,e)o<<e.first<<sp<<e.second<<nl;rr o;}
I<J T,J U=T>using umap=unordered_map<T,U>;
I<J T,J U>os&operator<<(os&o,const umap<T,U>&m){fee(m,e)o<<e.first<<sp<<e.second<<nl;rr o;}
I<size_t n>using bset=bitset<n>;
I<size_t n>os&operator<<(os&o,const bset<n>&b){foo(i,n)o<<b[i];rr o;}

I<J...A>os&operator<<(os&o,const tuple<A...>&t){apply([&](const au&...a){ll i=sizeof...(a);(((o<<a<<str(--i>0,sp))),...);},t);rr o;}

I<J T,J F>struct prique:priority_queue<T,vector<T>,F>{
  prique(const initializer_list<T>&a={}){fee(a,e)this->emplace(e);}
  prique(const vector<T>&a){fee(a,e)this->emplace(e);}
  friend T bg(prique&q){rr q.top();}
  friend T pot(prique&q){T r=q.top();q.pop();rr r;}
  friend os&operator<<(os&o,prique q){while(len(q))o<<pot(q)<<str(len(q)>0,sp);rr o;}
};
I<J T>using qmax=prique<T,less<>>;
I<J T>using qmin=prique<T,greater<>>;

I<J V>struct ve;
I<J V>constexpr bo isv=0;
I<J V>constexpr bo isv<ve<V>> =1;
I<J V>constexpr bo isv<vector<V>> =1;
I<J V>au rawv(V){if constexpr(isv<V>)rr rawv(V(1)[0]);else rr V();}

I<J V>struct ve:vector<V>{
  using vector<V>::vector;
  using T=decltype(rawv(V()));
  I<J U>ve(const vector<U>&v={}){static_assert(isv<V> ==isv<U>);fee(v,e)this->eb(e);}

  ve&operator+=(const ve&u){au&v=*this;foo(i,len(v))v[i]+=u[i];rr v;}ve operator+(const ve&u)const{rr ve(*this)+=u;}
  ve&operator-=(const ve&u){au&v=*this;foo(i,len(v))v[i]-=u[i];rr v;}ve operator-(const ve&u)const{rr ve(*this)-=u;}
  ve&operator^=(const ve&u){fee(u,e)this->eb(e);rr*this;}ve operator^(const ve&u)const{rr ve(*this)^=u;}
  ve&operator+=(const T&x){au&v=*this;fee(v,e)e+=x;rr v;}ve operator+(const T&x)const{rr ve(*this)+=x;}
  ve&operator-=(const T&x){au&v=*this;fee(v,e)e-=x;rr v;}ve operator-(const T&x)const{rr ve(*this)-=x;}
  ve&operator*=(const T&x){au&v=*this;fee(v,e)e*=x;rr v;}ve operator*(const T&x)const{rr ve(*this)*=x;}
  ve&operator++(){rr*this+=1;}
  ve&operator--(){rr*this-=1;}
  ve operator-()const{rr ve(*this)*=-1;}
  I<size_t n>au&operator+=(const bset<n>&a){foo(i,n)(*this)[i]+=a[i];rr*this;}
  I<size_t n>au&operator-=(const bset<n>&a){foo(i,n)(*this)[i]-=a[i];rr*this;}

  au lower_bound(const V&x)const{rr std::lower_bound(all(*this),x);}
  au upper_bound(const V&x)const{rr std::upper_bound(all(*this),x);}

  friend is&operator>>(is&i,ve&v){fee(v,e)i>>e;rr i;}
  friend os&operator<<(os&o,const ve&v){fee(v,e)o<<e<<str(&e!=&v.back(),isv<V>?nl:sp);rr o;}
};
I<J T=ll,size_t n,size_t i=0>au vec(const ll(&s)[n],T x={}){if constexpr(n==i+1)rr ve<T>(s[i],x);else{au X=vec<T,n,i+1>(s,x);rr ve<decltype(X)>(s[i],X);}}
I<ll n,J...A>vo setsize(const ll(&l)[n],A&...a){((a=vec(l,rawv(a))),...);}
I<J T>using vve=ve<ve<T>>;using vl=ve<ll>;using vvl=vve<ll>;
using gl=vve<ll>;using ge=vve<cl>;

vo io(){cin.tie(0)->sync_with_stdio(0);cout<<fixed<<setprecision(15);cerr<<nl;}
I<J...A>vo li(A&...a){(cin>>...>>a);}
I<char c=sp,J...A>vo pp(const A&...a){ll i=sizeof...(a);((cout<<a<<str(--i>0,c)),...);cout<<nl;}

I<J F>struct rec:F{rec(F&&f):F(std::forward<F>(f)){}I<J...A>decltype(au)operator()(A&&...a)const{rr F::operator()(*this,std::forward<A>(a)...);}};

lll floor_sum(lll n, lll m, lll a, lll b) {
    lll ans = 0;
    if (a >= m) {
        ans += (n - 1) * n * (a / m) / 2;
        a %= m;
    }
    if (b >= m) {
        ans += n * (b / m);
        b %= m;
    }

    lll y_max = (a * n + b) / m, x_max = (y_max * m - b);
    if (y_max == 0) return ans;
    ans += (n - (x_max + a - 1) / a) * y_max;
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a);
    return ans;
}

using namespace atcoder;
using ml=modint998244353;
auto&operator<<(std::ostream&o,const ml&x){return o<<x.val();}
auto&operator>>(std::istream&i,ml&x){long long t;i>>t;x=t;return i;}

vo main(){io();ll T=1;li(T);foo(T)solve();}
vo solve(){
  LL(N,M,L,R);R++;

  ml ans=0;
  ans+=R-L;
  ans+=floor_sum(R-L,N-1,1,L);
  ans+=floor_sum(R-L,N-1,1,M-R+1);
  pp(ans.val());
}}
0