编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#5672 #1058. 连加连乘 Accepted 100 126 ms 1592 K C++ 17 / 3.1 K TosakaUCW 2024-08-17 14:06:49
显示原始代码
#include <bits/stdc++.h>
using i64 = long long;
#define pb push_back

using std::cin, std::cout, std::string, std::vector;
i64 read(i64 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 <class T>
constexpr T power(T a, i64 b) {
    T res{ 1 };
    for (; b; b /= 2, a *= a)
        if (b % 2)
            res *= a;
    return res;
}
constexpr i64 mul(i64 a, i64 b, i64 p) {
    i64 res = a * b - (i64)(1.L * a * b / p) * p;
    res %= p;
    if (res < 0)
        res += p;
    return res;
}
template <i64 P>
struct MInt {
    i64 x;
    constexpr MInt() : x{ 0 } {}
    constexpr MInt(i64 x) : x{ norm(x % getMod()) } {}
    static i64 Mod;
    constexpr static i64 getMod() { return P > 0 ? P : Mod; }
    constexpr static void setMod(i64 Mod_) { Mod = Mod_; }
    constexpr i64 norm(i64 x) const {
        if (x < 0)
            x += getMod();
        if (x >= getMod())
            x -= getMod();
        return x;
    }
    constexpr i64 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) {
        i64 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 <>
i64 MInt<0>::Mod = 1e9 + 7;
constexpr int P = 1e9 + 7;
using Z = MInt<P>;

void solve() {
    i64 n = read();

    Z prod = 1;

    vector<i64> a(n + 1), sum(n + 1);
    for (int i = 1; i <= n; i++) {
        a[i] = read();
        sum[i] = sum[i - 1] + a[i];
        prod *= a[i];
    }

    for (int i = 1; i <= n; i++) {
        cout << sum[i - 1] - (sum[n] - sum[i]) << ' ';
        cout << prod / a[i] << '\n';
    }
}

signed main() {
#ifndef ONLINE_JUDGE
    // freopen("10.in", "r", stdin);
    // freopen("10.ans", "w", stdout);
#endif
    // for (int T = read(); T--; solve());
    solve();
    return 0;
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:3 ms
内存:260 KiB

输入文件(1.in

9
4575 6426 9445 8772 81 3447 629 3497 7202

答案文件(1.out

-39499 786611800
-28498 872821195
-12627 300026361
5590 488229479
14443 577147656
17971 342543942
22
<46 bytes omitted>

用户输出

-39499 786611800
-28498 872821195
-12627 300026361
5590 488229479
14443 577147656
17971 342543942
22047 889902963
26173 41199570
<18 bytes omitted>

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:3 ms
内存:268 KiB

输入文件(2.in

710
4325 3982 4784 8417 2156 1932 5902 5728 8537 3857 739 6918 9211 9679 8506 3340 6568 1868 16 7940
<3390 bytes omitted>

答案文件(2.out

-3620791 592199113
-3612484 292381003
-3603718 496292049
-3590517 690894759
-3579944 631846547
-3575
<12735 bytes omitted>

用户输出

-3620791 592199113
-3612484 292381003
-3603718 496292049
-3590517 690894759
-3579944 631846547
-3575856 371770782
-3568022 85161
<12707 bytes omitted>

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:3 ms
内存:248 KiB

输入文件(3.in

965
7801 8433 2359 1986 7193 7147 8119 2927 1528 5310 9747 9323 8294 6305 7798 9399 3654 1649 5020 7
<4615 bytes omitted>

答案文件(3.out

-4796301 676932003
-4780067 753201300
-4769275 373779790
-4764930 29076797
-4755751 578721889
-47414
<17414 bytes omitted>

用户输出

-4796301 676932003
-4780067 753201300
-4769275 373779790
-4764930 29076797
-4755751 578721889
-4741411 233069334
-4726145 553485
<17386 bytes omitted>

系统信息

Exited with return code 0
测试点 #4
Accepted
得分:100
用时:4 ms
内存:416 KiB

输入文件(4.in

1762
5583 2045 6032 8833 2940 8465 9065 6864 261 987 1243 2849 4856 435 2589 9271 1350 8418 4810 544
<8520 bytes omitted>

答案文件(4.out

-8787348 47387884
-8779720 830594898
-8771643 479536899
-8756778 671976293
-8745005 649172302
-87336
<32059 bytes omitted>

用户输出

-8787348 47387884
-8779720 830594898
-8771643 479536899
-8756778 671976293
-8745005 649172302
-8733600 71892092
-8716070 1835153
<32031 bytes omitted>

系统信息

Exited with return code 0
测试点 #5
Accepted
得分:100
用时:4 ms
内存:476 KiB

输入文件(5.in

5450
5437 1153 6197 9144 9833 7544 66 8057 2075 6243 3152 3701 3173 4149 3625 7703 1082 2162 3275 22
<26547 bytes omitted>

答案文件(5.out

-27333086 260657833
-27326496 915174879
-27319146 746521972
-27303805 487116870
-27284828 390236617

<103418 bytes omitted>

用户输出

-27333086 260657833
-27326496 915174879
-27319146 746521972
-27303805 487116870
-27284828 390236617
-27267451 580885029
-2725984
<103390 bytes omitted>

系统信息

Exited with return code 0
测试点 #6
Accepted
得分:100
用时:5 ms
内存:552 KiB

输入文件(6.in

5421
3772 6835 4474 9228 3228 1496 4478 7040 1076 1252 9610 9265 537 4770 5707 5975 4192 3669 898 97
<26443 bytes omitted>

答案文件(6.out

-27432130 226486028
-27421523 270125136
-27410214 490457154
-27396512 716331311
-27384056 40367191
-
<102799 bytes omitted>

用户输出

-27432130 226486028
-27421523 270125136
-27410214 490457154
-27396512 716331311
-27384056 40367191
-27379332 907958089
-27373358
<102771 bytes omitted>

系统信息

Exited with return code 0
测试点 #7
Accepted
得分:100
用时:30 ms
内存:1496 KiB

输入文件(7.in

68885
4562 2481 5891 482 2333 4220 1644 4852 3626 5922 3288 7781 754 8966 2925 2543 5890 2830 9184 7
<336766 bytes omitted>

答案文件(7.out

-344430252 138530325
-344423209 417966685
-344414837 637408821
-344408464 389990331
-344405649 34418
<1382331 bytes omitted>

用户输出

-344430252 138530325
-344423209 417966685
-344414837 637408821
-344408464 389990331
-344405649 344181459
-344399096 976771414
-3
<1382303 bytes omitted>

系统信息

Exited with return code 0
测试点 #8
Accepted
得分:100
用时:31 ms
内存:1592 KiB

输入文件(8.in

70577
5729 2787 8964 6447 2045 9183 977 7830 6799 3352 9180 5611 8431 2718 9145 5354 8744 759 3228 7
<344860 bytes omitted>

答案文件(8.out

-352506248 280420351
-352497732 314505987
-352485981 375895605
-352470570 287657545
-352462078 43497
<1417251 bytes omitted>

用户输出

-352506248 280420351
-352497732 314505987
-352485981 375895605
-352470570 287657545
-352462078 434977108
-352450850 938966377
-3
<1417223 bytes omitted>

系统信息

Exited with return code 0
测试点 #9
Accepted
得分:100
用时:14 ms
内存:780 KiB

输入文件(9.in

28947
6440 9700 4510 9633 6834 4860 6068 1975 6979 2246 3831 5366 7309 7134 5795 7347 4101 8336 9046
<141434 bytes omitted>

答案文件(9.out

-144784436 259459821
-144768296 665043431
-144754086 213064577
-144739943 510424714
-144723476 59919
<567483 bytes omitted>

用户输出

-144784436 259459821
-144768296 665043431
-144754086 213064577
-144739943 510424714
-144723476 599198312
-144711782 566033180
-1
<567455 bytes omitted>

系统信息

Exited with return code 0
测试点 #10
Accepted
得分:100
用时:29 ms
内存:1488 KiB

输入文件(10.in

67510
4320 3497 9468 5703 386 1598 3617 4052 4306 1770 1756 1329 6295 7516 9759 8887 2538 263 1052 7
<330124 bytes omitted>

答案文件(10.out

-337437626 615911186
-337429809 412564002
-337416844 18666699
-337401673 386592376
-337395584 789472
<1354768 bytes omitted>

用户输出

-337437626 615911186
-337429809 412564002
-337416844 18666699
-337401673 386592376
-337395584 789472298
-337393600 422237991
-33
<1354740 bytes omitted>

系统信息

Exited with return code 0