結果

問題 No.2199 lower_bound and upper_bound
ユーザー tatananonanotatananonano
提出日時 2023-01-29 07:49:58
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 9,861 bytes
コンパイル時間 6,497 ms
コンパイル使用メモリ 275,616 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-29 06:32:41
合計ジャッジ時間 11,035 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,avx512f")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <deque>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <set>
#include <map>
#include <ctime>
#include <stack>
#include <functional>
#include <cstdio>
#include <string>
#include <iostream>
#include <limits>
#include <stdexcept>
#include <numeric>
#include <fstream>
#include <chrono>
#include <utility>
#include <cassert>
#include <random>
#include <time.h>
#include <bitset>
using namespace std;
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep0(a) for (ll _ = 0; _ < ll(a); ++_)
#define rep1(i, n) for (ll i = 0; i < ll(n); ++i)
#define rep2(i, s, n) for (ll i = ll(s); i < ll(n); ++i)
#define rep3(i, s, n, d) for(ll i = ll(s); i < ll(n); i+=d)
#define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1,rep0)(__VA_ARGS__)
#define rrep0(a) for (ll _ = (a)-1; _ >= ll(0); -- _)
#define rrep1(i, n) for (ll i = ll(n)-1; i >= 0; i--)
#define rrep2(i, n, t) for (ll i = ll(n)-1; i >= (ll)t; i--)
#define rrep3(i, n, t, d) for (ll i = ll(n)-1; i >= (ll)t; i-=d)
#define drep(...) overload4(__VA_ARGS__,rrep3,rrep2,rrep1,rrep0)(__VA_ARGS__)
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
typedef double D;
typedef pair<ll,ll> P;
typedef map<ll,ll> M;
// /*
#include <atcoder/all>
using namespace atcoder;
//using namespace internal;
using mint =modint998244353;
//using mint =modint1000000007;
//using mint=static_modint<2000000000>;
#define ip(x) atcoder::internal::is_prime_constexpr(x)
istream &operator>>(istream &is, mint &a) { int v; cin >> v; a = v; return is; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.val(); }
auto v_pow(ll n,ll base){vector<mint> v(n,1);rep(i,n-1){v[i+1]*=base*v[i];}return v;}
// */
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class S, class T>
istream &operator>>(istream &is, pair<S, T> &p) { return is >> p.first >> p.second; }
template<class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) { return os << '{' << p.first << ", " << p.second << '}'; }
template<class S, class T, class U>
istream &operator>>(istream &is, tuple<S, T, U> &t) { return is >> get<0>(t) >> get<1>(t) >> get<2>(t); }
template<class S, class T, class U>
ostream &operator<<(ostream &os, const tuple<S, T, U> &t) {return os << '{' << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << '}';}
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
template <typename F>
ll binary_search(F check,ll ok,ll ng) {
/*binary_search(bool_func,okな値,ngな値)*///しっかり区間内に...
assert(check(ok));
while(abs(ok-ng)>1){
auto x=(ng+ok)/2;
tie(ok,ng)=(check(x)?make_pair(x, ng):make_pair(ok, x));
}
return ok;
}
template <typename F>
double binary_search_real(F check,double ok,double ng,ll iter = 100) {
rep(iter) {
double x=(ok+ng)/2;
tie(ok,ng)=(check(x)?make_pair(x,ng):make_pair(ok,x));
}
return (ok+ng)/2;
}
void tatananonano() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout<< fixed << setprecision(10);
}
#define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__)
#define INT(...) int __VA_ARGS__; IN(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;IN(__VA_ARGS__)
#define LDL(...) LD __VA_ARGS__;IN(__VA_ARGS__)
//#define MINT(...) mint __VA_ARGS__;IN(__VA_ARGS__)
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &...tail) {scan(head);IN(tail...);}
#define overload2(_1, _2, _3,name, ...) name
#define out1(x) cout<<x<<'\n'
#define out2(x,y) cout<<x<<" "<<y<<'\n'
#define out3(x,y,z) cout<<x<<" "<<y<<" "<<z<<'\n'
#define out4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<'\n'
#define out(...) overload4(__VA_ARGS__,out4,out3,out2,out1)(__VA_ARGS__)
#define print1(x) cout<<x<<'\n'
#define print2(x,n) cout<<fixed<<setprecision(n)<<x<<endl
#define print3(x,n,empty) cout<<fixed<<setprecision(n)<<x<<" "
#define print(...) overload2(__VA_ARGS__,print3,print2,print1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define MAX(a) *max_element(all(a));
#define MIN(a) *min_element(all(a));
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define len(x) ll(x.size())
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define TFU(s) transform(all(s),begin(s),::toupper);//大文字にする
#define TFL(s) transform(all(s),begin(s),::tolower);//小文字にする
#define replace(s,a,A) replace(s,'a','A')//str(s)のaをAにする
#define ROT(s,i) rotate(s.begin(),s.begin()+i,s.end())//sのi番目から後ろを前にする
#define PQ priority_queue
#define PQD PQ<P,vector<P>,greater<P>>//小さい順
#define PQS PQ<ll,vec,greater<ll>>
#define fi first
#define se second
#define bit(n,k) ((n>>k)&1LL)
#define popcount(n) __builtin_popcountll(n)
template<class T> inline bool chmax(T& a,T b){if(a < b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a > b){a=b;return 1;}return 0;}
bool in_rect(ll i,ll j,ll h,ll w) {return 0 <= i and i < h and 0 <= j and j < w;}
typedef vector<ll> vec;
typedef vector<string> vs;
typedef vector<vec> mat;
const ll mod = 998244353;
//const ll mod = 1000000007;
const auto INF = (1LL<<(60));
template <typename T, typename U>
T ceil(T x, U y) {return (x > 0 ? (x + y - 1) / y : x / y);}
template <typename T, typename U>
T floor(T x, U y) {return (x > 0 ? x / y : (x - y + 1) / y);}







struct Barrett {
  using u32 = unsigned int;
  using i64 = long long;
  using u64 = unsigned long long;
  u32 m;
  u64 im;
  Barrett() : m(), im() {}
  Barrett(int n) : m(n), im(u64(-1) / m + 1) {}
  constexpr inline i64 quo(u64 n) {
    u64 x = u64((__uint128_t(n) * im) >> 64);
    u32 r = n - x * m;
    return m <= r ? x - 1 : x;
  }
  constexpr inline i64 rem(u64 n) {
    u64 x = u64((__uint128_t(n) * im) >> 64);
    u32 r = n - x * m;
    return m <= r ? r + m : r;
  }
  constexpr inline pair<i64, int> quorem(u64 n) {
    u64 x = u64((__uint128_t(n) * im) >> 64);
    u32 r = n - x * m;
    if (m <= r) return {x - 1, r + m};
    return {x, r};
  }
  constexpr inline i64 pow(u64 n, i64 p) {
    u32 a = rem(n), r = m == 1 ? 0 : 1;
    while (p) {
      if (p & 1) r = rem(u64(r) * a);
      a = rem(u64(a) * a);
      p >>= 1;
    }
    return r;
  }
};
struct prime_power_binomial {
  int p, q, M;
  vector<int> fac, ifac, inv;
  int delta;
  Barrett bm, bp;
 
  prime_power_binomial(int _p, int _q) : p(_p), q(_q) {
    assert(1 < p && p <= ((1LL << 30) - 1));
    assert(_q > 0);
    long long m = 1;
    while (_q--) {
      m *= p;
      assert(m <=((1LL << 30) - 1));
    }
    M = m;
    bm = Barrett(M), bp = Barrett(p);
    enumerate();
    delta = (p == 2 && q >= 3) ? 1 : M - 1;
  }
 
  void enumerate() {
    int MX = min<int>(M, 20000000 + 10);
    fac.resize(MX);
    ifac.resize(MX);
    inv.resize(MX);
    fac[0] = ifac[0] = inv[0] = 1;
    fac[1] = ifac[1] = inv[1] = 1;
    for (int i = 2; i < MX; i++) {
      if (i % p == 0) {
        fac[i] = fac[i - 1];
        fac[i + 1] = bm.rem(1LL * fac[i - 1] * (i + 1));
        i++;
      } else {
        fac[i] = bm.rem(1LL * fac[i - 1] * i);
      }
    }
    ifac[MX - 1] = bm.pow(fac[MX - 1], M / p * (p - 1) - 1);
    for (int i = MX - 2; i > 1; --i) {
      if (i % p == 0) {
        ifac[i] = bm.rem(1LL * ifac[i + 1] * (i + 1));
        ifac[i - 1] = ifac[i];
        i--;
      } else {
        ifac[i] = bm.rem(1LL * ifac[i + 1] * (i + 1));
      }
    }
  }
 
  long long Lucas(long long n, long long m) {
    int res = 1;
    while (n) {
      int n0, m0;
      tie(n, n0) = bp.quorem(n);
      tie(m, m0) = bp.quorem(m);
      if (n0 < m0) return 0;
      res = bm.rem(1LL * res * fac[n0]);
      int buf = bm.rem(1LL * ifac[n0 - m0] * ifac[m0]);
      res = bm.rem(1LL * res * buf);
    }
    return res;
  }
 
  long long C(long long n, long long m) {
    if (n < m || n < 0 || m < 0) return 0;
    if (q == 1) return Lucas(n, m);
    long long r = n - m;
    int e0 = 0, eq = 0, i = 0;
    int res = 1;
    while (n) {
      res = bm.rem(1LL * res * fac[bm.rem(n)]);
      res = bm.rem(1LL * res * ifac[bm.rem(m)]);
      res = bm.rem(1LL * res * ifac[bm.rem(r)]);
      n = bp.quo(n);
      m = bp.quo(m);
      r = bp.quo(r);
      int eps = n - m - r;
      e0 += eps;
      if (e0 >= q) return 0;
      if (++i >= q) eq += eps;
    }
    if (eq & 1) res = bm.rem(1LL * res * delta);
    res = bm.rem(1LL * res * bm.pow(p, e0));
    return res;
  }
};
struct binomial_mod {
  int mod;
  vector<int> M;
  vector<prime_power_binomial> cs;
 
  binomial_mod(long long md) : mod(md) {
    assert(1 <= md);
    assert(md <= ((1LL << 30) - 1));
    for (int i = 2; i * i <= md; i++) {
      if (md % i == 0) {
        int j = 0, k = 1;
        while (md % i == 0) md /= i, j++, k *= i;
        M.push_back(k);
        cs.emplace_back(i, j);
        assert(M.back() == cs.back().M);
      }
    }
    if (md != 1) {
      M.push_back(md);
      cs.emplace_back(md, 1);
    }
    assert(M.size() == cs.size());
  }
 
  long long binom(long long n, long long m) {
    if (mod == 1) return 0;
    vector<long long> rem, d;
    for (int i = 0; i < (int)cs.size(); i++) {
      rem.push_back(cs[i].C(n, m));
      d.push_back(M[i]);
    }
    return atcoder::crt(rem, d).first;
  }
};
int main() {
tatananonano();
binomial_mod c(mod);
LL(n,l,u);
cout<<mint(c.binom(2*n+u,n)+c.binom(2*n+l-1,n+u+2)-c.binom(2*n+l-1,n)-c.binom(2*n+u,n+u+2))<<'\n';
}




0