QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#556982#6323. Range NEQucup-team3691AC ✓960ms44056kbC++144.0kb2024-09-10 23:13:502024-09-10 23:13:51

Judging History

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

  • [2024-09-10 23:13:51]
  • 评测
  • 测评结果:AC
  • 用时:960ms
  • 内存:44056kb
  • [2024-09-10 23:13:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;

using ll = long long;
using ull = unsigned long long;

string to_string(const string &s) {
  return '"' + s + '"';
}

string to_string(bool b) {
  return b ? "true" : "false";
}

template <typename A, typename B>
string to_string(const pair<A, B> &p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename T>
string to_string(const T &v) {
  string s = "{";
  bool first = true;
  for (const auto &it : v) {
    if (!first)
      s += ", ";
    else
      first = false;
    s += to_string(it);
  }
  return s += "}";
}

void debug_out() {
  cerr << endl;
}

template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
  cerr << to_string(first) << " ";
  debug_out(rest...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

auto startTime = high_resolution_clock::now();
int get_time() {
  auto stopTime = chrono::high_resolution_clock::now();
  auto duration = duration_cast<milliseconds>(stopTime - startTime);
  return duration.count(); // in ms
}

constexpr int MOD = 998244353;
constexpr int lgpow(int x, int p) {

  int aux = x, ans = 1;
  for (int i = 1; i <= p; i <<= 1) {
    if (i & p)
      ans = 1ll * ans * aux % MOD;
    aux = 1ll * aux * aux % MOD;
  }

  return ans;
}

namespace NTT {
  vector<int> ntt( vector<int> &a, int g ) {
    int n = a.size();
    int lg = log2(n); 
    for ( int i = 0; i < n; ++i ) {
      int j = 0;
      for ( int b = 0; b < lg; ++b ) {
        j += ( ( ( i >> b ) & 1 ) << ( lg - b - 1 ) );
      }
      if ( j < i ) {
        swap(a[i], a[j]);
      }
    }

    for ( int l = 2; l <= n; l <<= 1 ) {
      int p = lgpow(g, n / l);
      for ( int b = 0; b < n; b += l ) {
        for ( int i = 0, t = 1; i < l / 2; ++i, t = (1ll * t * p) % MOD ) {
          int x = a[b + i], y = 1ll * a[b + i + l / 2] * t % MOD;
          a[b + i] = (x + y) % MOD;
          a[b + i + l / 2] = (1ll * MOD + x - y) % MOD;
        }
      }
    }
    return a;
  }

  vector<int> mul( vector<int> a, vector<int> b ) {
    int n = a.size() + b.size() - 1;
    int p2 = 1;
    while ( p2 < n ) {
      p2 *= 2;
    }
    n = p2;

    while ( a.size() < n ) {
      a.push_back(0);
    }

    while ( b.size() < n ) {
      b.push_back(0);
    } 

    auto ra = ntt(a, lgpow(3, MOD / n));
    auto rb = ntt(b, lgpow(3, MOD / n));

    for( int i = 0; i < ra.size(); ++i ) {
      ra[i] = 1ll * ra[i] * rb[i] % MOD;
    }

    ra = ntt(ra, lgpow(lgpow(3, MOD - 2), MOD / n));
    int inv = lgpow(ra.size(), MOD - 2);
    for( int i = 0; i < ra.size(); ++i ) {
      ra[i] = 1ll * ra[i] * inv % MOD;
    }
    while ( !ra.back() )
      ra.pop_back();  
    return ra;
  }
};



void solve() {
  int n, m;
  cin >> n >> m;

  std::vector<int> fact(n * m + 1, 1);
  std::vector<int> ifact(n * m + 1, 1);

  auto comb = [&](int n, int m) {
    return 1LL * fact[n] * ifact[n - m] % MOD * ifact[m] % MOD;
  };

  for (int i = 1; i <= n * m; ++i) {
    fact[i] = 1LL * fact[i - 1] * i % MOD;
  }

  ifact[n * m] = lgpow(fact[n * m], MOD - 2);
  for (int i = n * m - 1; i >= 1; --i) {
    ifact[i] = 1LL * ifact[i + 1] * (i + 1) % MOD;
  }

  vector<int> poly(1, 1);
  vector<int> tmp(m + 1, 0);
  for ( int i = 0; i <= m; ++i ) {
    tmp[i] = 1ll * comb(m, i) * comb(m, i) % MOD * fact[i] % MOD;
  }  

  for ( int p = 1; p <= n; p <<= 1 ) {
    if ( p & n ) {
      poly = NTT::mul(poly, tmp);
    }
    tmp = NTT::mul(tmp, tmp);
  }

  int ans = 0;
  for ( int i = 0; i < poly.size(); ++i ) {
    ans = (1ll * MOD + ans + (i % 2 ? -1 : 1) * 1ll * poly[i] * fact[(n * m - i)] % MOD) % MOD;
  }
  cout << ans << "\n";
}

int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);

  int t = 1;
//  cin >> t;
  while (t--)
    solve();

  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3844kb

input:

2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

5 1

output:

44

result:

ok 1 number(s): "44"

Test #3:

score: 0
Accepted
time: 14ms
memory: 4304kb

input:

167 91

output:

284830080

result:

ok 1 number(s): "284830080"

Test #4:

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

input:

2 1

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

2 3

output:

36

result:

ok 1 number(s): "36"

Test #6:

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

input:

2 4

output:

576

result:

ok 1 number(s): "576"

Test #7:

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

input:

3 1

output:

2

result:

ok 1 number(s): "2"

Test #8:

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

input:

3 2

output:

80

result:

ok 1 number(s): "80"

Test #9:

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

input:

3 3

output:

12096

result:

ok 1 number(s): "12096"

Test #10:

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

input:

3 4

output:

4783104

result:

ok 1 number(s): "4783104"

Test #11:

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

input:

4 1

output:

9

result:

ok 1 number(s): "9"

Test #12:

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

input:

4 2

output:

4752

result:

ok 1 number(s): "4752"

Test #13:

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

input:

4 3

output:

17927568

result:

ok 1 number(s): "17927568"

Test #14:

score: 0
Accepted
time: 1ms
memory: 3856kb

input:

4 4

output:

776703752

result:

ok 1 number(s): "776703752"

Test #15:

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

input:

5 2

output:

440192

result:

ok 1 number(s): "440192"

Test #16:

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

input:

5 3

output:

189125068

result:

ok 1 number(s): "189125068"

Test #17:

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

input:

5 4

output:

975434093

result:

ok 1 number(s): "975434093"

Test #18:

score: 0
Accepted
time: 876ms
memory: 41612kb

input:

1000 1000

output:

720037464

result:

ok 1 number(s): "720037464"

Test #19:

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

input:

72 42

output:

638177567

result:

ok 1 number(s): "638177567"

Test #20:

score: 0
Accepted
time: 1ms
memory: 3880kb

input:

15 19

output:

663050288

result:

ok 1 number(s): "663050288"

Test #21:

score: 0
Accepted
time: 6ms
memory: 4036kb

input:

68 89

output:

94365047

result:

ok 1 number(s): "94365047"

Test #22:

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

input:

92 37

output:

652605307

result:

ok 1 number(s): "652605307"

Test #23:

score: 0
Accepted
time: 5ms
memory: 4104kb

input:

61 87

output:

498277867

result:

ok 1 number(s): "498277867"

Test #24:

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

input:

81 40

output:

133095344

result:

ok 1 number(s): "133095344"

Test #25:

score: 0
Accepted
time: 1ms
memory: 3968kb

input:

7 91

output:

524164813

result:

ok 1 number(s): "524164813"

Test #26:

score: 0
Accepted
time: 1ms
memory: 3748kb

input:

31 18

output:

361233485

result:

ok 1 number(s): "361233485"

Test #27:

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

input:

74 54

output:

500686087

result:

ok 1 number(s): "500686087"

Test #28:

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

input:

32 2

output:

586504335

result:

ok 1 number(s): "586504335"

Test #29:

score: 0
Accepted
time: 580ms
memory: 32576kb

input:

656 718

output:

346764298

result:

ok 1 number(s): "346764298"

Test #30:

score: 0
Accepted
time: 190ms
memory: 12076kb

input:

254 689

output:

358078813

result:

ok 1 number(s): "358078813"

Test #31:

score: 0
Accepted
time: 616ms
memory: 38368kb

input:

713 674

output:

914437613

result:

ok 1 number(s): "914437613"

Test #32:

score: 0
Accepted
time: 112ms
memory: 10956kb

input:

136 698

output:

56687290

result:

ok 1 number(s): "56687290"

Test #33:

score: 0
Accepted
time: 161ms
memory: 11904kb

input:

369 401

output:

312325811

result:

ok 1 number(s): "312325811"

Test #34:

score: 0
Accepted
time: 59ms
memory: 7404kb

input:

280 204

output:

280012063

result:

ok 1 number(s): "280012063"

Test #35:

score: 0
Accepted
time: 180ms
memory: 12552kb

input:

904 225

output:

162909174

result:

ok 1 number(s): "162909174"

Test #36:

score: 0
Accepted
time: 833ms
memory: 40536kb

input:

855 928

output:

39885159

result:

ok 1 number(s): "39885159"

Test #37:

score: 0
Accepted
time: 194ms
memory: 12260kb

input:

503 365

output:

745115888

result:

ok 1 number(s): "745115888"

Test #38:

score: 0
Accepted
time: 725ms
memory: 40872kb

input:

646 996

output:

610925577

result:

ok 1 number(s): "610925577"

Test #39:

score: 0
Accepted
time: 890ms
memory: 42788kb

input:

990 918

output:

203469632

result:

ok 1 number(s): "203469632"

Test #40:

score: 0
Accepted
time: 926ms
memory: 42860kb

input:

961 949

output:

169566857

result:

ok 1 number(s): "169566857"

Test #41:

score: 0
Accepted
time: 938ms
memory: 42668kb

input:

946 932

output:

352423195

result:

ok 1 number(s): "352423195"

Test #42:

score: 0
Accepted
time: 887ms
memory: 42416kb

input:

903 981

output:

196309824

result:

ok 1 number(s): "196309824"

Test #43:

score: 0
Accepted
time: 930ms
memory: 42748kb

input:

916 988

output:

487208972

result:

ok 1 number(s): "487208972"

Test #44:

score: 0
Accepted
time: 960ms
memory: 41920kb

input:

982 982

output:

387421488

result:

ok 1 number(s): "387421488"

Test #45:

score: 0
Accepted
time: 922ms
memory: 42376kb

input:

955 911

output:

955637031

result:

ok 1 number(s): "955637031"

Test #46:

score: 0
Accepted
time: 886ms
memory: 42952kb

input:

906 999

output:

798469943

result:

ok 1 number(s): "798469943"

Test #47:

score: 0
Accepted
time: 904ms
memory: 44056kb

input:

982 975

output:

193506289

result:

ok 1 number(s): "193506289"

Test #48:

score: 0
Accepted
time: 858ms
memory: 42764kb

input:

921 991

output:

431202149

result:

ok 1 number(s): "431202149"