QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#459545#8834. Formal Fringucup-team3099#AC ✓479ms75944kbC++237.1kb2024-06-30 06:56:082024-06-30 06:56:08

Judging History

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

  • [2024-06-30 06:56:08]
  • 评测
  • 测评结果:AC
  • 用时:479ms
  • 内存:75944kb
  • [2024-06-30 06:56:08]
  • 提交

answer

#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>

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

template <class T, class E>
constexpr T fexp(T x, E e) {
    T ans(1);
    for(; e > 0; e >>= 1) {
        if(e & 1) ans = ans * x;
        x = x * x;
    }
    return ans;
}

template <class LOW, class HIGH, const LOW mod>
struct modBase {
    using mint = modBase<LOW, HIGH, mod>;
    constexpr modBase() : val(0) {}
    // be careful of negative numbers!
    constexpr modBase(const LOW v) : val((v % mod + mod) % mod) {} 
    LOW val;

    #define add(a, b) a + b >= mod ? a + b - mod : a + b
    #define sub(a, b) a < b ? a + mod - b : a - b

    constexpr mint &operator += (const mint &o) { return val = add(val, o.val), *this; }
    constexpr mint &operator -= (const mint &o) { return val = sub(val, o.val), *this; }
    constexpr mint &operator *= (const mint &o) { return val = (LOW) ((HIGH) val * o.val % mod), *this; }
    constexpr mint &operator /= (const mint &o) { return *this *= o.inverse(); }

    constexpr mint operator + (const mint &b) const { return mint(*this) += b; }
    constexpr mint operator - (const mint &b) const { return mint(*this) -= b; }
    constexpr mint operator * (const mint &b) const { return mint(*this) *= b; }
    constexpr mint operator / (const mint &b) const { return mint(*this) /= b; }

    constexpr mint operator - () const { return mint() - mint(*this); }
    constexpr bool operator == (const mint &b) const { return val == b.val; }
    constexpr bool operator != (const mint &b) const { return val != b.val; }

    template<class E> constexpr mint pow (E e) const { return fexp(*this, e); }
    constexpr mint inverse() const { return pow(mod - 2); }
    constexpr LOW get() const { return val; }
    static constexpr LOW getMod() { return mod; }

    friend std::ostream& operator << (std::ostream &os, const mint &p) { return os << p.val; }
    friend std::istream& operator >> (std::istream &is, mint &p) { return is >> p.val; }
};

const int MOD = 998244353;
using mint = modBase<int, long long, MOD>;

int N;
mint wtf[1 << 20];
mint ans[1 << 20];

void prefixSum(std::vector<mint> &arr) {
    for(int i = 1; i < (int) arr.size(); i++) {
        arr[i] += arr[i-1];
    }
}

void solve(int sz, int n, int bit, std::vector<mint> just, std::vector<mint> extra) {
    if(bit > N) {
        return;
    }
    // std::cout << "at (" << n << ", " << bit << ")\n";
    // for(int i = 0; i < (int) just.size(); i++) {
    //     std::cout << just[i] << ' ';
    // }std::cout << std::endl;
    // for(int i = 0; i < (int) extra.size(); i++) {
    //     std::cout << extra[i] << ' ';
    //}std::cout << std::endl;
    int newN = n;
    int newBit = bit + bit;

    just.resize(sz, 0);
    extra.resize(sz, 0);
    prefixSum(just);
    prefixSum(extra);
    {
        // transition for 0
        // if extra, then must be odd and can't get extra
        // otherwise, it's just and needs to be even
        // if 2 or more, then it's extra
        auto newEven = just;
        auto newOdd = extra;
        std::vector<mint> newJust(1, 0), newExtra;
        for(int i = 0; i < (int) newEven.size(); i += 2) {
            if(i == 0) {
                newJust[0] += newEven[0];
            } else {
                newExtra.push_back(newEven[i]);
            }
        }
        for(int i = 1; i < (int) newOdd.size(); i += 2) {
            if(i / 2 < (int) newExtra.size()) {
                newExtra[i / 2] += newOdd[i];
            } else {
                newExtra.push_back(newOdd[i]);
            }
        }
        solve((sz+1)/2, newN, newBit, newJust, newExtra);
    }
    if(n + bit <= N) {
        newN += bit;
        // transition for 1
        // std::cout << "from (" << n << ", " << bit << ") filled to " << newN << " with " << extra[0] << '\n';
        ans[newN] = extra[0];
        auto newEven = extra;
        auto newOdd = just;
        std::vector<mint> newJust(1, 0), newExtra;
        for(int i = 0; i < (int) newEven.size(); i += 2) {
            if(i == 0) {
                newJust[0] += newEven[0];
            } else {
                newExtra.push_back(newEven[i]);
            }
        }
        for(int i = 1; i < (int) newOdd.size(); i += 2) {
            if(i == 1) {
                newJust[0] += newOdd[i];
            } else {
                newJust.push_back(newOdd[i]);
            }
        }
        solve((sz+1)/2, newN, newBit, newJust, newExtra);
    }
}

int main() {
    std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
    std::cin >> N;
    int n = N;
    std::vector<mint> stuff(2*n+30, 0);
    wtf[0] = 1;
    for(int i = 1; i < (1 << 20); i *= 2) {
        for(int j = i; j < (1 << 20); j++) {
            wtf[j] += wtf[j - i];
        }
    }
    auto just = stuff;
    just[0] = 1;
    solve(n+30, 0, 1, just, stuff);
    for(int i = 1; i <= N; i++) {
        std::cout << wtf[i] - ans[i] << (i == N ? '\n' : ' ');
    }
}

/*
NEVER FORGET TO:
    Look at the problem's constraints before coding.
How to cheese cf:
    Find a lower bound or upper bound for the problem. Have faith that it is the answer of the problem.
    If it isn't the answer, have more faith or change to another bound god by looking for a better bound.

    Trust guesses. Who has time to think? If people in div2 AC the problem it requires no proof since people don't prove things.

    You must draw cases. Thinking gets you nowhere, so draw cases and reach illogical conclusions from them.
    Sometimes drawing cases is bad because it takes too much time. Faster is to not think at all and just code a bruteforce solution.
    This is called "law of small numbers". If something works for small numbers, surely it works for big numbers.
    https://en.wikipedia.org/wiki/Faulty_generalization#Hasty_generalization don't mind the "faulty" part of it, in competitive programming mistakes are lightly punished
    Don't think about them being right or not, cf is a battle of intuition only.

    Be as stupid as possible in implementation. Trying to be smart is an easy way to get WA.

    Think about 2x2 cases for matrix problems and hope that everything works for the general case.

    Find a necessary condition and trust it to be sufficient. They're basically the same thing.

    Heuristics might speed up your code. Forget about complexity, it's only about ACing and not proving that your solution is good.

    For paths in a grid starting at (1, i) or something like that, assume that they never cross and do D&C

    Consider doing problems in reverse order of queries/updates

    For combinatorics problems, consider symmetry

General strategy (MUST DO):
    Try to solve the problem with more restricted constraints.

About testing:
    Test n=1, a[i]=1, a[i]=n, etc. Basically, test low values. No need to test if pretests are strong, but if you get WA it's good.

This isn't a joke. Do it if you get stuck. It's shit practice in my opinion, but do it if you want AC.
*/

详细

Test #1:

score: 100
Accepted
time: 18ms
memory: 8924kb

input:

10

output:

1 1 2 1 1 3 6 1 1 2

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 11ms
memory: 9732kb

input:

70

output:

1 1 2 1 1 3 6 1 1 2 2 5 5 11 26 1 1 2 2 4 4 6 6 11 11 16 16 27 27 53 166 1 1 2 2 4 4 6 6 10 10 14 14 20 20 26 26 37 37 48 48 64 64 80 80 107 107 134 134 187 187 353 1626 1 1 2 2 4 4 6

result:

ok 70 numbers

Test #3:

score: 0
Accepted
time: 479ms
memory: 75944kb

input:

1000000

output:

1 1 2 1 1 3 6 1 1 2 2 5 5 11 26 1 1 2 2 4 4 6 6 11 11 16 16 27 27 53 166 1 1 2 2 4 4 6 6 10 10 14 14 20 20 26 26 37 37 48 48 64 64 80 80 107 107 134 134 187 187 353 1626 1 1 2 2 4 4 6 6 10 10 14 14 20 20 26 26 36 36 46 46 60 60 74 74 94 94 114 114 140 140 166 166 203 203 240 240 288 288 336 336 400 ...

result:

ok 1000000 numbers

Extra Test:

score: 0
Extra Test Passed