QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#185472#4908. 完全表示hos_lyric#25 20ms7016kbC++145.7kb2023-09-22 08:48:562024-07-04 02:45:43

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 02:45:43]
  • 评测
  • 测评结果:25
  • 用时:20ms
  • 内存:7016kb
  • [2023-09-22 08:48:56]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")

////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

constexpr unsigned MO = 164511353;
using Mint = ModInt<MO>;

constexpr int LIM_INV = 200'010;
Mint inv[LIM_INV], fac[LIM_INV], invFac[LIM_INV];

void prepare() {
  inv[1] = 1;
  for (int i = 2; i < LIM_INV; ++i) {
    inv[i] = -((Mint::M / i) * inv[Mint::M % i]);
  }
  fac[0] = invFac[0] = 1;
  for (int i = 1; i < LIM_INV; ++i) {
    fac[i] = fac[i - 1] * i;
    invFac[i] = invFac[i - 1] * inv[i];
  }
}
Mint binom(Int n, Int k) {
  if (n < 0) {
    if (k >= 0) {
      return ((k & 1) ? -1 : +1) * binom(-n + k - 1, k);
    } else if (n - k >= 0) {
      return (((n - k) & 1) ? -1 : +1) * binom(-k - 1, n - k);
    } else {
      return 0;
    }
  } else {
    if (0 <= k && k <= n) {
      assert(n < LIM_INV);
      return fac[n] * invFac[k] * invFac[n - k];
    } else {
      return 0;
    }
  }
}


int N, Q, M;
int T;


namespace field_m0 {
vector<Mint> QQ, QQ2;
int ord;
vector<Mint> fs;
Mint qbinom(int n, int k) {
  const int nq = n / ord, nr = n % ord;
  const int kq = k / ord, kr = k % ord;
  if (kr > nr) return 0;
  return binom(nq, kq) * (fs[nr] / (fs[kr] * fs[nr - kr]));
}

Mint run() {
  QQ.resize(N + 1);
  QQ2.resize(N + 1);
  QQ[0] = 1;
  QQ2[0] = 1;
  for (int i = 1; i <= N; ++i) {
    QQ[i] = QQ[i - 1] * Q;
    QQ2[i] = QQ2[i - 1] * QQ[i - 1];
  }
  ord = N + 1;
  for (int i = 1; i <= N; ++i) {
    if (QQ[i] == 1) {
      ord = i;
      break;
    }
  }
cerr<<"ord = "<<ord<<endl;
  fs.resize(ord);
  fs[0] = 1;
  for (int i = 1; i < ord; ++i) {
    fs[i] = fs[i - 1] * (QQ[i] - 1);
  }
  
  Mint ans = 0;
  {
    // 2^(Q^k)
    Mint two = 2;
    for (int k = 0; k <= N; ++k) {
      ans += (((N-k)&1)?-1:+1) * QQ2[N - k] * qbinom(N, k) * two;
      two = two.pow(Q);
    }
  }
  return ans;
}
}  // field_m0


int main() {
  prepare();
  
  for (; ~scanf("%d%d%d", &N, &Q, &M); ) {
    scanf("%d", &T);
    assert(T == 1);
    
    const Mint ans = field_m0::run();
    printf("%u\n", ans.x);
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 6304kb

input:

2 3 665
1

output:

486

result:

wrong answer 1st words differ - expected: '51745605', found: '486'

Subtask #2:

score: 15
Accepted

Test #14:

score: 15
Accepted
time: 3ms
memory: 6252kb

input:

19 90203 0
1

output:

142145213

result:

ok "142145213"

Test #15:

score: 0
Accepted
time: 3ms
memory: 6116kb

input:

18 9697 0
1

output:

153592927

result:

ok "153592927"

Test #16:

score: 0
Accepted
time: 3ms
memory: 6256kb

input:

20 41 0
1

output:

112957727

result:

ok "112957727"

Test #17:

score: 0
Accepted
time: 0ms
memory: 6204kb

input:

20 99991 0
1

output:

151341559

result:

ok "151341559"

Subtask #3:

score: 5
Accepted

Dependency #2:

100%
Accepted

Test #18:

score: 5
Accepted
time: 3ms
memory: 6248kb

input:

999 9749 0
1

output:

77370298

result:

ok "77370298"

Test #19:

score: 0
Accepted
time: 3ms
memory: 6268kb

input:

997 55103 0
1

output:

92054017

result:

ok "92054017"

Test #20:

score: 0
Accepted
time: 0ms
memory: 6248kb

input:

1000 41 0
1

output:

6438830

result:

ok "6438830"

Test #21:

score: 0
Accepted
time: 3ms
memory: 6276kb

input:

1000 99991 0
1

output:

31676606

result:

ok "31676606"

Subtask #4:

score: 5
Accepted

Dependency #3:

100%
Accepted

Test #22:

score: 5
Accepted
time: 19ms
memory: 7016kb

input:

99996 20089 0
1

output:

163612442

result:

ok "163612442"

Test #23:

score: 0
Accepted
time: 19ms
memory: 6920kb

input:

99996 17707 0
1

output:

109099283

result:

ok "109099283"

Test #24:

score: 0
Accepted
time: 15ms
memory: 7012kb

input:

100000 41 0
1

output:

131161322

result:

ok "131161322"

Test #25:

score: 0
Accepted
time: 20ms
memory: 6956kb

input:

100000 99991 0
1

output:

84487741

result:

ok "84487741"

Subtask #5:

score: 0
Wrong Answer

Test #26:

score: 0
Wrong Answer
time: 3ms
memory: 6312kb

input:

998 24 0
1

output:

109954642

result:

wrong answer 1st words differ - expected: '75129854', found: '109954642'

Subtask #6:

score: 0
Skipped

Dependency #4:

100%
Accepted

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #6:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%

Subtask #9:

score: 0
Runtime Error

Test #46:

score: 0
Runtime Error

input:

99997 3 997
2
0 1 2
1 2 0
2 0 1
0 0 0
0 1 2
0 2 1

output:


result: