QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#738584#9631. Median ReplacementVegJJJyCompile Error//C++175.5kb2024-11-12 19:27:012024-11-12 19:27:01

Judging History

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

  • [2024-11-12 19:27:01]
  • 评测
  • [2024-11-12 19:27:01]
  • 提交

answer

#include<bits/stdc++.h>
#define dbg(x) cout << #x"=" << (x) << ' '
#define int long long
// #define endl '\n'

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;

struct Poly {
    vector<int> p;
    Poly(int n = 0) : p(n) {}
    Poly(const vector<int> &v) : p(v) {}
    int size() const {
        return p.size();
    }
    int get(int x) {
        int res = 0, t = 1;
        for(int i = 0; i < p.size(); i++) {
            res = (res + 1ll * p[i] * t) % MOD;
            t = 1ll * t * x % MOD;
        }
        return res;
    }
};

ostream& operator<<(ostream &out, const Poly &u) {
    out << "{";
    for(auto t : u.p)
        out << ' ' << t;
    out << "}";
    return out;
}

Poly operator*(const Poly &u, const Poly &v) {
    Poly res(max(0, u.size() + v.size() - 1));
    for(int i = 0; i < u.size(); i++)
        for(int j = 0; j < v.size(); j++)
            res.p[i + j] = (res.p[i + j] + 1ll * u.p[i] * v.p[j]) % MOD;
    return res;
}

Poly operator+(const Poly &u, const Poly &v) {
    Poly res(max(u.size(), v.size()));
    for(int i = 0; i < u.size(); i++)
        res.p[i] = u.p[i];
    for(int i = 0; i < v.size(); i++)
        res.p[i] = (res.p[i] + v.p[i]) % MOD;
    return res;
}

int qpow(int a, int b) {
    int res = 1;
    while(b) {
        if(b & 1) res = 1ll * res * a % MOD;
        a = 1ll * a * a % MOD;
        b >>= 1;
    }
    return res;
}

Poly f[155][4][2];

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

    vector<int> l(n + 1), r(n + 1), a;
    for(int i = 1; i <= n; i++) {
        cin >> l[i];
        a.push_back(l[i]);
    }
    for(int i = 1; i <= n; i++) {
        cin >> r[i];
        a.push_back(r[i]);
        a.push_back(r[i] + 1);
    }
    a.push_back(1);
    sort(a.begin(), a.end());
    {
        vector<int> a2;
        for(int i = 0; i < a.size(); i++)
            if(i == 0 || a[i] != a[i - 1])
                a2.push_back(a[i]);
        a = a2;
    }
    a.push_back(a.back() + 1);

    vector<tuple<Poly, int, int>> g;
    auto getPoly = [&](int p, int L, int R, int tp) -> Poly {
        if(tp == 0) {//<x
            if(l[p] >= R) {
                return vector<int>{0};
            } else if(r[p] < L) {
                return vector<int>{r[p] - l[p] + 1};
            } else if(r[p] == L) {
                return vector<int>{L - l[p]};
            } else {
                return vector<int>{-l[p], 1};
            }
        } else {//>=x
            if(r[p] < L) {
                return vector<int>{0};
            } else if(r[p] == L) {
                return vector<int>{1};
            } else if(l[p] >= R) {
                return vector<int>{r[p] - l[p] + 1};
            } else {
                return vector<int>{r[p] + 1, -1};
            }
        }
    };
    for(int p = 0; p + 1 < a.size(); p++) {
        int L = a[p], R = a[p + 1] - 1;
        //0:00, 1:01, 2:10, 3:11
        //0<, 1>=
        // cout << "--- p = " << p << "  "; dbg(L); dbg(R) << endl;
        for(int c1 = 0; c1 <= 1; c1++)
            for(int c2 = 0; c2 <= 1; c2++)
                f[2][c1 * 2 + c2][0] = getPoly(1, L, R, c1) * getPoly(2, L, R, c2);
        for(int i = 3; i <= n; i++) {
            Poly p[2] = {getPoly(i, L, R, 0), getPoly(i, L, R, 1)};
            for(int j = 0; j < 4; j++)
                for(int k = 0; k < 2; k++)
                    f[i][j][k] = vector<int>{0};
            for(int c1 = 0; c1 <= 1; c1++)
                for(int c2 = 0; c2 <= 1; c2++)
                    for(int c3 = 0; c3 <= 1; c3++) {
                        int t1 = c1 * 2 + c2, t2 = c2 * 2 + c3;
                        if(c1 + c2 + c3 >= 2) {
                            f[i][t2][1] = f[i][t2][1] + (f[i - 1][t1][0] + f[i - 1][t1][1]) * p[c3];
                        } else {
                            f[i][t2][0] = f[i][t2][0] + f[i - 1][t1][0] * p[c3];
                            f[i][t2][1] = f[i][t2][1] + f[i - 1][t1][1] * p[c3];
                        }
                    }
            // dbg(i); dbg(p[0]); dbg(p[1]) << endl;
            // dbg(f[i][0][0]); dbg(f[i][0][1]) << endl;
            // dbg(f[i][1][0]); dbg(f[i][1][1]) << endl;
            // dbg(f[i][2][0]); dbg(f[i][2][1]) << endl;
            // dbg(f[i][3][0]); dbg(f[i][3][1]) << endl;
        }
        g.push_back({f[n][0][1] + f[n][1][1] + f[n][2][1] + f[n][3][1], L, R});
    }

    int ans = 0;
    for(auto [p, L, R] : g) {
        // dbg(L); dbg(R); dbg(p) << endl;
        if(R - L + 1 <= n + 2) {
            for(int i = L; i <= R; i++)
                ans = (ans + p.get(i)) % MOD;
        } else {
            vector<pair<int, int>> s;
            for(int i = L; i <= L + n; i++) {
                s.push_back({i, p.get(i)});
            }
            for(int i = 1; i < s.size(); i++)
                s[i].second = (s[i].second + s[i - 1].second) % MOD;
            for(int i = 0; i < s.size(); i++) {
                int fz = 1, fm = 1;
                for(int j = 0; j < s.size(); j++) {
                    if(j == i) continue;
                    fz = 1ll * fz * (R - s[j].first) % MOD;
                    fm = 1ll * fm * (s[i].first - s[j].first) % MOD;
                }
                ans = (ans + 1ll * s[i].second * fz % MOD * qpow(fm, MOD - 2)) % MOD;
            }
        }
    }
    cout << (ans % MOD + MOD) % MOD << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    cin >> T;
    while(T--) {
        solve();
    }

    return 0;
}

Details

answer.code: In function ‘Poly operator*(const Poly&, const Poly&)’:
answer.code:37:17: error: no matching function for call to ‘max(int, long long int)’
   37 |     Poly res(max(0, u.size() + v.size() - 1));
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from answer.code:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
answer.code:37:17: note:   deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘long long int’)
   37 |     Poly res(max(0, u.size() + v.size() - 1));
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
answer.code:37:17: note:   deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘long long int’)
   37 |     Poly res(max(0, u.size() + v.size() - 1));
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)’
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
answer.code:37:17: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘int’
   37 |     Poly res(max(0, u.size() + v.size() - 1));
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)’
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
answer.code:37:17: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘int’
   37 |     Poly res(max(0, u.size() + v.size() - 1));
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~