QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#740734#9619. 乘积,欧拉函数,求和Golem__WA 895ms5140kbC++207.5kb2024-11-13 11:19:212024-11-13 11:19:22

Judging History

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

  • [2024-11-13 11:19:22]
  • 评测
  • 测评结果:WA
  • 用时:895ms
  • 内存:5140kb
  • [2024-11-13 11:19:21]
  • 提交

answer

// [Golem]
#include<bits/stdc++.h>

namespace Golem // [Golem Library] Golem
{
    #define Golem__ 201307
    #define fcc(i, j, k) for(num (i)=(j); (i)<=(k); ++(i))
    #define ccf(i, j, k) for(num (i)=(j); (i)>=(k); --(i))
    #define I (*this)
    #define same_type(T1, T2) (std::is_same<T1, T2>::value)
    #define num_type(T) (same_type(T, num) || same_type(T, Num))
    #define fra_type(T) (same_type(T, fra) || same_type(T, Fra))
    #define num_or_fra_type(T) (num_type(T) || fra_type(T))

    using std::cin, std::cout, std::min, std::max, std::string, std::pair, std::make_pair;
    using num = int;
    using unum = unsigned int;
    using Num = long long;
    using uNum = unsigned long long;
    using fra = double;
    using Fra = long double;
    using pnum = pair<num, num>;
    using pNum = pair<Num, Num>;
    template<typename T>
    using heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

    const char newl = '\n', *snewl = " \n";

    constexpr Num read()
    {
        Num ret = 0, s = 1, c = getchar();
        if(c == -1) return std::numeric_limits<Num>::min();
        for(; !isdigit(c); c = getchar()) if(c == '-') s = -1;
        for(; isdigit(c); c = getchar()) ret = (ret << 1) + (ret << 3) + (c ^ 48);
        return s * ret;
    }
    constexpr string readstr()
    {
        string ret; char c;
        for(; (c = getchar()) <= ' ';);
        for(; c > ' '; c = getchar()) ret += c;
        return ret;
    }
    template<typename T>
    constexpr void min_(T &a, auto &&b) { if(b < a) a = b; }
    template<typename T>
    constexpr void max_(T &a, auto &&b) { if(a < b) a = b; }
    template<typename Tnf> requires num_or_fra_type(Tnf)
    constexpr Tnf inf() { return (std::numeric_limits<Tnf>::max() - Golem__) / 2; }
    template<typename Tn> requires num_type(Tn)
    constexpr Tn lowbit(Tn i) { return i & -i; }

    template<typename T>
    class array : private std::vector<T>
    {
        public:
        using iterator = std::vector<T>::iterator;
        iterator begin() { return std::vector<T>::begin(); }
        iterator end() { return std::vector<T>::end(); }

        array() { }
        array(num siz) : std::vector<T>(siz) { }
        array(num siz, auto &&t) : std::vector<T>(siz, t) { }
        array(std::initializer_list<T> il) : std::vector<T>(il) { }
        array(T *pb, T *pe) : std::vector<T>(pb, pe) { }
        array(iterator itb, iterator ite) : std::vector<T>(itb, ite) { }

        void clear() { std::vector<T>::clear(); }
        operator bool () { return !I.empty(); }
        num size() { return std::vector<T>::size(); }
        array& set(num siz) { return I.resize(siz), I; }
        T& front() { return std::vector<T>::front(); }
        T& back() { return std::vector<T>::back(); }
        T& operator [] (num i)
        {
            #ifdef DEBUG__
            assert(0 <= i && i < size());
            #endif
            return std::vector<T>::operator[](i);
        }
        void push(auto &&...t) { I.emplace_back(t...); }
        void insert(num i, auto &&...t) { I.emplace(begin() + i, t...); }
        void pop() { I.pop_back(); }
        void erase(num i) { std::vector<T>::erase(begin() + i); }
        void fill(auto &&t) { std::fill(begin(), end(), t); }
        void reverse() { std::reverse(begin(), end()); }
        template<typename Tcom = std::less<T>>
        void sort() { std::sort(begin(), end(), Tcom()); }
        template<typename Tcom = std::less<T>>
        num lower(auto &&t) { return std::lower_bound(begin(), end(), t, Tcom()) - begin(); }
        template<typename Tcom = std::less<T>>
        num upper(auto &&t) { return std::upper_bound(begin(), end(), t, Tcom()) - begin(); }
        template<typename Tcom = std::less<T>>
        void discretize()
        {
            sort<Tcom>(), set(std::unique(begin(), end(),
                [&](T &a, T &b) { return !Tcom()(a, b) && !Tcom()(b, a); }) - begin());
        }
    };

    #define every(e, G, o) for(num (e)=(G).las[(o)]; (e); (e)=(G).pre[(e)])
    template<typename Tn> requires num_type(Tn)
    class graph
    {
        public:
        num V, E; array<num> las, pre, to, fro; array<Tn> wei, cap;

        graph(num V = 0) : V(V), E(0), las(V + 1), pre(2), to(2), fro(2), wei(2), cap(2) { }

        void add(num u, num v, Tn w = 0, Tn c = 0)
        { pre.push(las[u]), las[u] = ++E + 1, to.push(v), fro.push(u), wei.push(w), cap.push(c); }
        void addb(num u, num v, Tn w = 0, Tn c = 0) { add(u, v, w, c), add(v, u, w, c); }
    };
}

namespace Golem // [Golem Library] modulus
{
    template<num mod>
    class modnum
    {
        private:
        num i;

        public:
        modnum(num i = 0) : i(i) { }

        num operator () () { return i; }
        modnum& operator ++ () { if(++i == mod) i = 0; return I; }
        modnum operator ++ (num) { modnum ret = I; return ++I, ret; }
        modnum operator + (modnum m) { num ret = i + m.i; if(ret >= mod) ret -= mod; return ret; }
        modnum& operator += (modnum m) { if((i += m.i) >= mod) i -= mod; return I; }
        modnum& operator -- () { if(!i--) i = mod - 1; return I; }
        modnum operator -- (num) { modnum ret = I; return --I, ret; }
        modnum operator - (modnum m) { num ret = i - m.i; if(ret < 0) ret += mod; return ret; }
        modnum& operator -= (modnum m) { if((i -= m.i) < 0) i += mod; return I; }
        modnum operator * (modnum m) { return 1ULL * i * m.i % mod; }
        modnum& operator *= (modnum m) { return i = 1ULL * i * m.i % mod, I; }
        modnum operator / (modnum m) { return I * m.inv(); }
        modnum& operator /= (modnum m) { return I *= m.inv(); }
        modnum power(num e)
        { modnum ret = 1, d = I; for(; e; e >>= 1, d *= d) if(e & 1) ret *= d; return ret; }
        modnum inv() { return power(mod - 2); }
        friend std::ostream& operator << (std::ostream &os, modnum m) { return cout << m.i; }
    };
}

using namespace Golem;

const num mod = 998244353, max_a = 3000, mas = (1 << 16) - 1;
using Mod = modnum<mod>;
num P, pri[max_a + 10]; std::bitset<max_a + 10> isp;
Mod D[max_a + 10], inv[mas + 1];
struct info { num a = 0, les = 0, gre = 0; };
inline bool operator < (info a, info b) { return a.gre < b.gre; }
void solve()
{
    num N = read();
    array<info> A(N + 10);
    fcc(i, 1, N) A[i].a = read();
    fcc(i, 1, N)
    {
        num a = A[i].a;
        fcc(j, 1, 16) if(!(a % pri[j]))
            for(A[i].les |= 1 << j - 1; !(a % pri[j]);) a /= pri[j];
        if(a > 1) A[i].les = a;
    }
    std::sort(A.begin() + 1, A.begin() + N + 1);
    Mod dp[2][2][mas + 1] = { };
    fcc(j, 0, 1) fcc(k, 0, mas) dp[0][j][k] = 1;
    fcc(i, 1, N) fcc(j, 0, 1) fcc(k, 0, mas)
        dp[i & 1][j][k] = dp[i - 1 & 1][j && A[i].gre == A[i - 1].gre][k] +
            dp[i - 1 & 1][A[i].gre == A[i - 1].gre][k | A[i].les] * A[i].a *
            inv[(k | A[i].les) ^ k] * (!j && A[i].gre ? D[A[i].a] : 1);
    cout << dp[N & 1][0][0] << newl;
}
num main()
{
    #ifndef ONLINE_JUDGE
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
    #endif
    std::ios::sync_with_stdio(0), cin.tie(0);

    isp.set(), isp[1] = 0;
    fcc(i, 2, max_a) if(isp[i])
    {
        pri[++P] = i, D[i] = Mod(i - 1) / i;
        for(Num j = 1LL * i * i; j <= max_a; j += i) isp[j] = 0;
    }
    inv[0] = 1;
    fcc(i, 1, 16) inv[1 << i - 1] = D[pri[i]];
    fcc(i, 1, mas) inv[i] = inv[i ^ lowbit(i)] * inv[lowbit(i)];

    for(num T = 1; T --> 0;) solve();
    return 0 ^ 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 4728kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

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

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Wrong Answer
time: 895ms
memory: 5140kb

input:

2000
79 1 1 1 1 1 1 2803 1 1 1 1 1 1 1609 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2137 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 613 1 499 1 211 1 2927 1 1 1327 1 1 1123 1 907 1 2543 1 1 1 311 2683 1 1 1 1 2963 1 1 1 641 761 1 1 1 1 1 1 1 1 1 1 1 1489 2857 1 1 1 1 1 1 1 1 1 1 1 1 1 967 1 821 1 1 1 1 2143 1861...

output:

930909552

result:

wrong answer 1st lines differ - expected: '50965652', found: '930909552'