QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#283653 | #6328. Many Products | Misuki | WA | 43ms | 82228kb | C++20 | 7.5kb | 2023-12-15 01:09:42 | 2023-12-15 01:09:43 |
Judging History
answer
#pragma GCC optimize("O2")
#include <bits/extc++.h>
#include <algorithm>
#include <array>
#include <bit>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <compare>
#include <complex>
#include <concepts>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numbers>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <ranges>
#include <set>
#include <span>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <type_traits>
#include <variant>
#define int ll
#define INT128_MAX (__int128)(((unsigned __int128) 1 << ((sizeof(__int128) * __CHAR_BIT__) - 1)) - 1)
#define INT128_MIN (-INT128_MAX - 1)
namespace R = std::ranges;
namespace V = std::views;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using tiii = tuple<int, int, int>;
using ldb = long double;
//#define double ldb
template<class T>
ostream& operator<<(ostream& os, const pair<T, T> pr) {
return os << pr.first << ' ' << pr.second;
}
template<class T, size_t N>
ostream& operator<<(ostream& os, const array<T, N> &arr) {
for(const T &X : arr)
os << X << ' ';
return os;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T> &vec) {
for(const T &X : vec)
os << X << ' ';
return os;
}
/**
* template name: MontgomeryModInt
* author: Misuki
* reference: https://github.com/NyaanNyaan/library/blob/master/modint/montgomery-modint.hpp#L10
* last update: 2023/11/30
* note: mod should be a prime less than 2^30.
*/
template<uint32_t mod>
struct MontgomeryModInt {
using mint = MontgomeryModInt;
using i32 = int32_t;
using u32 = uint32_t;
using u64 = uint64_t;
static constexpr u32 get_r() {
u32 res = 1, base = mod;
for(i32 i = 0; i < 31; i++)
res *= base, base *= base;
return -res;
}
static constexpr u32 get_mod() {
return mod;
}
static constexpr u32 n2 = -u64(mod) % mod; //2^64 % mod
static constexpr u32 r = get_r(); //-P^{-1} % 2^32
u32 a;
static u32 reduce(const u64 &b) {
return (b + u64(u32(b) * r) * mod) >> 32;
}
static u32 transform(const u64 &b) {
return reduce(u64(b) * n2);
}
MontgomeryModInt() : a(0) {}
MontgomeryModInt(const int64_t &b)
: a(transform(b % mod + mod)) {}
mint pow(u64 k) const {
mint res(1), base(*this);
while(k) {
if (k & 1)
res *= base;
base *= base, k >>= 1;
}
return res;
}
mint inverse() const { return (*this).pow(mod - 2); }
u32 get() const {
u32 res = reduce(a);
return res >= mod ? res - mod : res;
}
mint& operator+=(const mint &b) {
if (i32(a += b.a - 2 * mod) < 0) a += 2 * mod;
return *this;
}
mint& operator-=(const mint &b) {
if (i32(a -= b.a) < 0) a += 2 * mod;
return *this;
}
mint& operator*=(const mint &b) {
a = reduce(u64(a) * b.a);
return *this;
}
mint& operator/=(const mint &b) {
a = reduce(u64(a) * b.inverse().a);
return *this;
}
mint operator-() { return mint() - mint(*this); }
bool operator==(mint b) {
return (a >= mod ? a - mod : a) == (b.a >= mod ? b.a - mod : b.a);
}
bool operator!=(mint b) {
return (a >= mod ? a - mod : a) != (b.a >= mod ? b.a - mod : b.a);
}
friend mint operator+(mint a, mint b) { return a += b; }
friend mint operator-(mint a, mint b) { return a -= b; }
friend mint operator*(mint a, mint b) { return a *= b; }
friend mint operator/(mint a, mint b) { return a /= b; }
friend ostream& operator<<(ostream& os, const mint& b) {
return os << b.get();
}
friend istream& operator>>(istream& is, mint& b) {
int64_t val;
is >> val;
b = mint(val);
return is;
}
};
using mint = MontgomeryModInt<998244353>;
/**
* template name: hashTable
* reference: https://codeforces.com/blog/entry/62393
* last update: 2022/12/03
* header: bit/extc++.h (or ext/pb_ds/assoc_container.hpp for CF)
*/
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
using namespace __gnu_pbds;
gp_hash_table<ll, int, custom_hash> toId;
const int pi = 40;
const int mod = 998244353;
const int MAX = 200000 + 50;
int C[MAX][50];
signed main() {
ios::sync_with_stdio(false), cin.tie(NULL);
for(int i = 0; i < 50; i++)
C[i][0] = C[i][i] = 1;
for(int i = 2; i < MAX; i++)
for(int j = 1; j < min(i, 50ll); j++)
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
int n, m; cin >> n >> m;
vector<mint> a(n);
for(mint &x : a)
cin >> x;
vector<int> div;
for(int i = 1; i * i <= m; i++) {
if (m % i == 0) {
div.emplace_back(i);
if (i * i != m)
div.emplace_back(m / i);
}
}
R::sort(div);
vector<int> pf;
{
int tmp = m;
for(int i = 2; i * i <= m; i++) {
if (tmp % i == 0) {
pf.emplace_back(i);
while(tmp % i == 0)
tmp /= i;
}
}
if (tmp != 1)
pf.emplace_back(tmp);
}
for(int i = 0; i < ssize(div); i++)
toId[div[i]] = i;
vector<vector<int>> f(ssize(div));
for(int i = 0; int d : div) {
for(int p : pf) {
if (d % p == 0) {
f[i].emplace_back(0);
while(d % p == 0)
d /= p, f[i].back()++;
}
}
i++;
}
vector<vector<array<int, 2>>> trans(ssize(div));
for(int j = 0; j < ssize(div); j++)
for(int k = 1; k <= j; k++)
if (div[j] % div[k] == 0)
trans[j].push_back({toId[div[j] / div[k]], div[k] - 1});
vector dp(pi + 1, vector<mint>(ssize(div)));
dp[0][0] = 1;
for(int i = 1; i <= pi; i++)
for(int j = 0; j < ssize(div); j++)
for(auto [k, r] : trans[j])
dp[i][j] += dp[i - 1][k] * r;
vector<mint> dp2(pi + 1);
dp2[0] = 1;
for(int i = 0; i < n; i++) {
vector<mint> tmp(pi + 1);
for(int j = 0; j <= pi; j++)
tmp[j] = dp2[j] * (a[i] + 1);
for(int j = 1; j <= pi; j++)
tmp[j] += dp2[j - 1];
dp2.swap(tmp);
}
mint ans = 0;
for(int i = 0; i <= min(pi, n); i++) {
for(int j = 0; j < ssize(div); j++) {
int tmp = 1;
for(int k : f[toId[m / div[j]]])
tmp = tmp * C[n - i - 1 + k][k] % mod;
ans += dp[i][j] * dp2[i] * tmp;
}
}
cout << ans << '\n';
/*
cout << "div: " << div << '\n';
cout << "pf: " << pf << '\n';
cout << "f: " << f << '\n';
cout << "dp: \n";
for(auto v : dp)
cout << v << '\n';
cout << "dp2: " << dp2 << '\n';
for(auto [x, y] : toId)
cout << x << ' ' << y << '\n';
*/
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 7ms
memory: 81720kb
input:
2 3 0 1
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 3ms
memory: 81664kb
input:
5 1 0 1 2 3 4
output:
120
result:
ok 1 number(s): "120"
Test #3:
score: 0
Accepted
time: 22ms
memory: 81680kb
input:
10 314159265358 0 1 2 3 4 5 6 7 8 9
output:
658270849
result:
ok 1 number(s): "658270849"
Test #4:
score: -100
Wrong Answer
time: 43ms
memory: 82228kb
input:
200000 999999999989 823489320 406308599 710963770 183707427 192930969 941365774 318564299 391028855 945374838 651744270 515755727 220857626 599403217 214957584 335628890 771694833 40989299 34892948 630275822 869708185 432704750 924850167 707864789 232688853 406616372 529994171 782650336 979286144 65...
output:
92077961
result:
wrong answer 1st numbers differ - expected: '777405593', found: '92077961'