結果

問題 No.2176 LRM Question 1
ユーザー Dev KudawlaDev Kudawla
提出日時 2023-01-07 22:46:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 6,364 bytes
コンパイル時間 3,994 ms
コンパイル使用メモリ 232,252 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-08 18:00:20
合計ジャッジ時間 4,346 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 121 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 5 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 104 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 123 ms
5,376 KB
testcase_15 AC 96 ms
5,376 KB
testcase_16 AC 78 ms
5,376 KB
testcase_17 AC 5 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 50 ms
5,376 KB
testcase_22 AC 8 ms
5,376 KB
testcase_23 AC 44 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// AUTHOR->DEV KUDAWLA
//-----------------------------------------
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order(it return an iterator), order_of_key
#define ll long long
#define in cin >>
#define out(a) cout << a << " "
#define ot cout <<
#define vt(T) vector<T>
#define vl vector<long long>
#define flp(a) for (auto &i : a)
#define endl cout << "\n";
#define pb push_back
#define db pop_back
#define rt return
#define even(a) a % 2 == 0
#define n_digit(n) (int)log10(n) + 1
#define msb(n) (int)(log2(n)) + 1
// it is 1 based
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define lt(x) x.size()
#define ter(a, b, c) a ? b : c
#define yn(a) a ? ot "YES" : ot "NO"
#define ff first
#define ss second
#define str string
#define tbits(x) __builtin_popcountll(x)
#define LOCAL_COMPILER
#ifdef LOCAL_COMPILER
#define dbg(x)        \
   cerr << #x << " "; \
   cerr << x << "\n";
#endif
#ifndef LOCAL_COMPILER
#define dbg(x)
#endif
//-----------------------------------------
template <class T>
void vin(T &v)
{
   flp(v) { in i; }
}
template <class T>
void vin(set<T> &s, ll n)
{
   for (int i = 0; i < n; i++)
   {
      T d;
      in d;
      s.insert(d);
   }
}
template <class T>
void vin(multiset<T> &s, ll n)
{
   for (int i = 0; i < n; i++)
   {
      T d;
      in d;
      s.insert(d);
   }
}
template <class T1, class T2>
void vin(map<T1, T2> &m, ll n)
{
   for (int i = 0; i < n; i++)
   {
      T1 a;
      T2 b;
      cin >> a;
      cin >> b;
      m[a] = b;
   }
}
template <class T>
void vin(map<T, ll> &m, ll n)
{
   for (int i = 0; i < n; i++)
   {
      T a;
      cin >> a;
      m[a]++;
   }
}
template <class T>
void vout(T &v)
{
   for (int i = 0; i < lt(v); i++)
   {
      ot(v[i]);
      if (i != lt(v) - 1)
         ot(" ");
   }
}
inline ll power2(ll n)
{
   ll answer = 0;
   if (n != 0)
      answer = msb(((ll)n) ^ ((ll)(n - 1))) - 1;
   return answer;
}
//-----------------------------------------
const ll N = 1e+9 + 7;
const ll N2 = 998244353;
const long double epsilon = 1e-9;
//-----------------------------------------
// modulo arithmetic
ll expo(ll a, ll b, ll mod)
{
   ll res = 1;
   while (b > 0)
   {
      if (b & 1)
         res = (res * a) % mod;
      a = (a * a) % mod;
      b = b >> 1;
   }
   return res;
}
ll mminvprime(ll a, ll b) { return expo(a, b - 2, b); }
ll mod_add(ll a, ll b, ll m)
{
   a = a % m;
   b = b % m;
   return (((a + b) % m) + m) % m;
}
ll mod_mul(ll a, ll b, ll m)
{
   a = a % m;
   b = b % m;
   return (((a * b) % m) + m) % m;
}
ll mod_sub(ll a, ll b, ll m)
{
   a = a % m;
   b = b % m;
   return (((a - b) % m) + m) % m;
}
ll mod_div(ll a, ll b, ll m)
{
   a = a % m;
   b = b % m;
   return (mod_mul(a, mminvprime(b, m), m) + m) % m;
} // only for prime m
ll ncr(ll n, ll r, ll mod = N)
{
   ll answer = 0;
   if (n >= r)
   {
      ll a = 1;
      for (ll i = n; i >= n - r + 1; i--)
         a = mod_mul(a, i, mod);
      ll b = 1;
      for (ll i = 1; i <= r; i++)
         b = mod_mul(b, i, mod);
      b = mminvprime(b, mod);
      a = mod_mul(a, b, mod);
      answer = a;
   }
   return answer;
}
ll factorial(ll n, ll mod = N)
{
   ll answer = 1;
   for (int i = 2; i <= n; i++)
      answer = mod_mul(answer, i, mod);
   return answer;
}
ll npr(ll n, ll r, ll mod = N)
{
   ll answer = ncr(n, r, N) * factorial(r, N);
   answer %= N;
   return answer;
}
//-----------------------------------------
// KMP search
void computeLPSArray(string pat, ll M, ll lps[])
{
   ll len = 0;
   ll i = 1;
   lps[0] = 0;
   while (i < M)
   {
      if (pat[i] == pat[len])
      {
         len++;
         lps[i] = len;
         i++;
      }
      else
      {
         if (len != 0)
            len = lps[len - 1];
         else
         {
            lps[i] = len;
            i++;
         }
      }
   }
}
ll KMPSearch(string pat, string txt)
{
   ll M = pat.length();
   ll N = txt.length();
   ll lps[M];
   ll j = 0;
   computeLPSArray(pat, M, lps);
   ll i = 0;
   ll res = 0;
   ll next_i = 0;
   while (i < N)
   {
      if (pat[j] == txt[i])
         i++, j++;
      if (j == M)
      {
         j = lps[j - 1];
         res++;
      }
      else if (i < N && pat[j] != txt[i])
      {
         if (j != 0)
            j = lps[j - 1];
         else
            i = i + 1;
      }
   }
   return res;
} // O(M+N)
map<ll, ll> prime_factors(ll n)
{
   map<ll, ll> answer;
   ll a = n;
   for (ll i = 2; i * i <= a; i++)
      while (a % i == 0)
         answer[i]++, a /= i;
   if (a > 1)
      answer[a]++;
   return answer;
}
//-----------------------------------------
bool cmp(ll a, ll b) { rt a > b; }
bool (*function_ptr)(ll a, ll b) = cmp;
// this is a function pointer
//-----------------------------------------
const ll n_sieve = (1e7 + 9) + 1; // O(Nlog(log(N)))
vector<bool> prime_sieve(n_sieve, true);
void initialise_sieve(vector<bool> &prime_sieve)
{
   prime_sieve[0] = false;
   prime_sieve[1] = false;
   for (ll i = 2; i < lt(prime_sieve); i++)
      if (prime_sieve[i] == true)
         for (ll j = 2; j * i < lt(prime_sieve); j++)
            prime_sieve[j * i] = false;
}
//-----------------------------------------
// code starts here
//------------------------------------
void solve()
{
   // always use 1LL for bit
   // ---------------------------------------
   // ll T; //->test cases
   // cin >> T;
   // while (T--)
   // {
   //    endl;
   //    // code end here->
   // }
   ll l, r, m;
   cin >> l >> r >> m;
   if (l >= m)
   {
      ot 0;
      return;
   }
   r = min(m - 1, r);
   ll f = 1;
   ll p = 1;
   for (ll i = 2; i < l; i++)
   {
      f = mod_mul(f, i, m);
      p = mod_mul(p, f, m);
   }
   ll answer = 0;
   for (ll i = l; i <= r; i++)
   {
      f = mod_mul(f, i, m);
      p = mod_mul(p, f, m);
      answer = mod_add(answer, p, m);
   }
   ot answer;
}
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   // -------------------------------------------
   // initialise_sieve(prime_sieve);
   //----------------------------------------
   solve();
   //----------------------------------------
   return 0;
}
//-----------------------------------------
0