编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#5701 #1058. 连加连乘 Compile Error 0 0 ms 0 K C++ 17 / 3.0 K YueGuan1234 2024-08-17 14:32:16
显示原始代码
#include <bits/stdc++.h>
using namespace std;
#define int long long

#define endl "\n"

#define pb push_back

int read(int x = 0, int f = 0, char ch = getchar()) {
    while (ch < 48 or 57 < ch) f = ch == 45, ch = getchar();
    while (48 <= ch and ch <= 57) x = x * 10 + ch - 48, ch = getchar();
    return f ? -x : x;
}
template <int P>
struct MInt {
    int x;
    constexpr MInt() : x{ 0 } {}
    constexpr MInt(int x) : x{ norm(x % getMod()) } {}
    static int Mod;
    constexpr static int getMod() { return P > 0 ? P : Mod; }
    constexpr static void setMod(int Mod_) { Mod = Mod_; }
    constexpr int norm(int x) const {
        if (x < 0)
            x += getMod();
        if (x >= getMod())
            x -= getMod();
        return x;
    }
    constexpr int val() const { return x; }
    constexpr MInt operator-() const {
        MInt res;
        res.x = norm(getMod() - x);
        return res;
    }
    constexpr MInt inv() const { return power(*this, getMod() - 2); }
    constexpr MInt &operator*=(MInt rhs) & {
        if (getMod() < (1ULL << 31))
            x = x * rhs.x % int(getMod());
        else
            x = mul(x, rhs.x, getMod());
        return *this;
    }
    constexpr MInt &operator+=(MInt rhs) & {
        x = norm(x + rhs.x);
        return *this;
    }
    constexpr MInt &operator-=(MInt rhs) & {
        x = norm(x - rhs.x);
        return *this;
    }
    constexpr MInt &operator/=(MInt rhs) & { return *this *= rhs.inv(); }
    friend constexpr MInt operator*(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res *= rhs;
        return res;
    }
    friend constexpr MInt operator+(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res += rhs;
        return res;
    }
    friend constexpr MInt operator-(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res -= rhs;
        return res;
    }
    friend constexpr MInt operator/(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res /= rhs;
        return res;
    }
    friend constexpr std::istream &operator>>(std::istream &is, MInt &a) {
        int v;
        is >> v;
        a = MInt(v);
        return is;
    }
    friend constexpr std::ostream &operator<<(std::ostream &os, const MInt &a) { return os << a.val(); }
    friend constexpr bool operator==(MInt lhs, MInt rhs) { return lhs.val() == rhs.val(); }
    friend constexpr bool operator!=(MInt lhs, MInt rhs) { return lhs.val() != rhs.val(); }
    friend constexpr bool operator<(MInt lhs, MInt rhs) { return lhs.val() < rhs.val(); }
};
template <>
int MInt<0>::Mod = 1e9 + 7;
constexpr int P = 1e9 + 7;
using Z = MInt<P>;
void solve() {
    Z pro = 1;
    int n = read();
    vector<int> a(n + 1, 0), pre(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        a[i] = read();
        pro *= a[i];
        pre[i] = pre[i - 1] + a[i];
    }
    for (int i = 1; i <= n; i++) {
        cout << pre[i - 1] - (pre[n] - pre[i]) << " " << pro / a[i] << endl;
    }
}
signed main() {
    // for(int T=read();T--;) solve();
    solve();
    return 0;
}

编译信息

/sandbox/1/a.cpp: In member function 'constexpr MInt<P>& MInt<P>::operator*=(MInt<P>) &':
/sandbox/1/a.cpp:3:13: error: expected primary-expression before 'long'
    3 | #define int long long
      |             ^~~~
/sandbox/1/a.cpp:35:29: note: in expansion of macro 'int'
   35 |             x = x * rhs.x % int(getMod());
      |                             ^~~
/sandbox/1/a.cpp:35:28: error: expected ';' before 'long'
   35 |             x = x * rhs.x % int(getMod());
      |                            ^
      |                            ;
/sandbox/1/a.cpp:37:17: error: there are no arguments to 'mul' that depend on a template parameter, so a declaration of 'mul' must be available [-fpermissive]
   37 |             x = mul(x, rhs.x, getMod());
      |                 ^~~
/sandbox/1/a.cpp:37:17: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
/sandbox/1/a.cpp: In instantiation of 'constexpr MInt<P>& MInt<P>::operator*=(MInt<P>) & [with long long int P = 1000000007]':
/sandbox/1/a.cpp:90:18:   required from here
/sandbox/1/a.cpp:37:20: error: 'mul' was not declared in this scope; did you mean 'fmul'?
   37 |             x = mul(x, rhs.x, getMod());
      |                 ~~~^~~~~~~~~~~~~~~~~~~~
      |                 fmul
/sandbox/1/a.cpp: In instantiation of 'constexpr MInt<P> MInt<P>::inv() const [with long long int P = 1000000007]':
/sandbox/1/a.cpp:48:69:   required from 'constexpr MInt<P>& MInt<P>::operator/=(MInt<P>) & [with long long int P = 1000000007]'
/sandbox/1/a.cpp:66:9:   required from 'constexpr MInt<1000000007> operator/(MInt<1000000007>, MInt<1000000007>)'
/sandbox/1/a.cpp:94:53:   required from here
/sandbox/1/a.cpp:32:46: error: 'power' was not declared in this scope
   32 |     constexpr MInt inv() const { return power(*this, getMod() - 2); }
      |                                         ~~~~~^~~~~~~~~~~~~~~~~~~~~