QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#445631#8527. Power Divisionsucup-team3099#WA 10ms7604kbC++238.8kb2024-06-16 06:47:392024-06-16 06:47:39

Judging History

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

  • [2024-06-16 06:47:39]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:7604kb
  • [2024-06-16 06:47:39]
  • 提交

answer

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

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; }
};

struct Info {
    int pos;
    int potL, potR;
    int L, R;
};

std::vector<Info> genInfo(int n, const std::vector<int> &a) {
    std::set<int> st;
    st.insert(-1);
    st.insert(n);
    std::vector<int> p(n);
    for(int i = 0; i < n; i++) {
        p[i] = i;
    }
    std::sort(p.begin(), p.end(), [&](int v0, int v1) { return a[v0] > a[v1]; });
    std::vector<Info> ans;
    for(auto x : p) {
        auto itL = st.lower_bound(x);
        auto itR = itL;
        itL--;
        int l = *itL + 1, r = *itR - 1;
        if(x - l < r - x) {
            for(int i = l; i <= x; i++) {
                ans.push_back({i, a[x], a[x] + (int) log2(r - l + 1) + 1, x+1, r+1});
            }
        } else {
            for(int i = x; i <= r; i++) {
                ans.push_back({i+1, a[x], a[x] + 20, l, x});
            }
        }
        st.insert(x);
    }
    return ans;
}

struct Triple {
    int l, r, pot;
};

template<const int MOD>
std::vector<Triple> solve(int n, const std::vector<int> &a, const std::vector<Info> &info) {
    using mint = modBase<int, long long, MOD>;
    std::vector<Triple> ans;
    const int ms = 1001000;
    std::vector<mint> b(n+1, 0), pot(ms, 1);
    for(int i = 1; i < ms; i++) {
        pot[i] = pot[i-1] * 2;
    }
    for(int i = 0; i < n; i++) {
        b[i+1] = b[i] + pot[a[i]];
    }
    std::vector<std::pair<int, int>> st;
    for(int i = 0; i <= n; i++) {
        //std::cout << b[i] << (i == n ? '\n' : ' ');
        st.push_back({b[i].val, i});
    }
    std::sort(st.begin(), st.end());
    for(auto [pos, potL, potR, l, r] : info) {
        for(int i = potL; i <= potR; i++) {
            int target = (pos <= l ? (b[pos] + pot[i]).val : (b[pos] - pot[i]).val);
            //std::cout << "pos " << pos << ", pot " << i << " range [" << l << ", " << r << ") got target " << target << '\n';
            int first = (int)(std::lower_bound(st.begin(), st.end(), std::pair<int, int>(target, l)) - st.begin());
            for(int j = first; j <= n && st[j].first == target && st[j].second <= r; j++) {
                ans.push_back({std::min(pos, st[j].second), std::max(pos, st[j].second), i});
                //std::cout << "found " << ans.back().first << ", " << ans.back().second << '\n';
            }
        }
    }
    //std::sort(ans.begin(), ans.end());
    return ans;
}

template<const int MOD>
std::vector<Triple> solve(int n, const std::vector<int> &a, const std::vector<Triple> &info) {
    using mint = modBase<int, long long, MOD>;
    std::vector<Triple> ans;
    const int ms = 1001000;
    std::vector<mint> b(n+1, 0), pot(ms, 1);
    for(int i = 1; i < ms; i++) {
        pot[i] = pot[i-1] * 2;
    }
    for(int i = 0; i < n; i++) {
        b[i+1] = b[i] + pot[a[i]];
    }
    for(auto [l, r, i] : info) {
        if(b[r] - b[r] == pot[i]) {
            ans.push_back({l, r, i});
        }
    }
    //std::sort(ans.begin(), ans.end());
    return ans;
}

constexpr int MOD[] = {(int) 1e9 + 7, (int) 1e9 + 9, 998244353};

int main() {
    std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
    int n;
    std::cin >> n;
    std::vector<int> a(n, 0);
    for(int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    auto info = genInfo(n, a);
    std::vector<Triple> transitions = solve<MOD[0]>(n, a, info);
    transitions = solve<MOD[1]>(n, a, transitions);
    transitions = solve<MOD[2]>(n, a, transitions);
    // {
    //     auto cur = solve<MOD[1]>(n, a, info);
    //     int sz = 0;
    //     for(int i = 0, j = 0; i < (int) transitions.size(); i++) {
    //         while(j+1 < (int) cur.size() && cur[j] < transitions[i]) j++;
    //         if(cur[j] == transitions[i]) {
    //             transitions[sz++] = transitions[i];
    //         }
    //     }
    //     transitions.resize(sz);
    // }
    // {
    //     auto cur = solve<MOD[2]>(n, a, info);
    //     int sz = 0;
    //     for(int i = 0, j = 0; i < (int) transitions.size(); i++) {
    //         while(j+1 < (int) cur.size() && cur[j] < transitions[i]) j++;
    //         if(cur[j] == transitions[i]) {
    //             transitions[sz++] = transitions[i];
    //         }
    //     }
    //     transitions.resize(sz);
    // }
    using mint = modBase<int, long long, MOD[0]>;
    std::vector<mint> dp(n+1, 0);
    dp[0] = 1;
    std::vector<std::vector<int>> trans(n+1);
    for(auto [l, r, _] : transitions) {
        //std::cout << "[" << l << ", " << r << ")" << std::endl;
        trans[l].push_back(r);
    }
    for(int i = 0; i < n; i++) for(auto j : trans[i]) {
        dp[j] += dp[i];
    }
    std::cout << dp.back() << '\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.
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 10ms
memory: 7604kb

input:

5
2 0 0 1 1

output:

0

result:

wrong answer 1st numbers differ - expected: '6', found: '0'