Submission #74655437


Source Code Expand

#include <bits/stdc++.h>
#define endl '\n'
#define MOD 998244353
using namespace std;
long long n, m, suma, sumb;
long long a[500005], b[500005];
long long pre[500005];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (long long i = 1; i <= n; i++)
        cin >> a[i];
    for (long long i = 1; i <= m; i++)
        cin >> b[i];
    for (long long i = 1; i <= n; i++)
        suma = (suma + a[i] * i) % MOD;
    for (long long i = 1; i <= m; i++)
        sumb = (sumb + b[i]) % MOD;
    long long ans1 = suma * sumb % MOD;
    pre[0] = 0;
    for (long long i = 1; i <= n; i++)
        pre[i] = (pre[i - 1] + a[i]) % MOD;
    long long ans2 = 0;
    for (long long i = 1; i <= m; i++)
    {
        if (b[i] == 0)
            continue;
        for (long long j = 1; j <= n / i; j++)
        {
            long long l = j * i;
            long long r = min(n, (j + 1) * i - 1);
            long long sum = (pre[r] - pre[l - 1] + MOD) % MOD;
            long long add = b[i] * i % MOD * j % MOD * sum % MOD;
            ans2 = (ans2 + add) % MOD;
        }
    }
    cout << (ans1 - ans2 + MOD) % MOD << endl;
    return 0;
}

Submission Info

Submission Time
Task E - You WILL Like Sigma Problem
User xzy404
Language C++23 (GCC 15.2.0)
Score 450
Code Size 1215 Byte
Status AC
Exec Time 71 ms
Memory 15368 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 2
AC × 22
Set Name Test Cases
Sample 00-sample-01.txt, 00-sample-02.txt
All 00-sample-01.txt, 00-sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 1 ms 3644 KiB
00-sample-02.txt AC 1 ms 3700 KiB
01-01.txt AC 1 ms 3700 KiB
01-02.txt AC 1 ms 3688 KiB
01-03.txt AC 1 ms 3532 KiB
01-04.txt AC 1 ms 3652 KiB
01-05.txt AC 1 ms 3828 KiB
01-06.txt AC 1 ms 3840 KiB
01-07.txt AC 1 ms 3844 KiB
01-08.txt AC 1 ms 3844 KiB
01-09.txt AC 71 ms 15368 KiB
01-10.txt AC 70 ms 15336 KiB
01-11.txt AC 20 ms 7668 KiB
01-12.txt AC 20 ms 7536 KiB
01-13.txt AC 20 ms 7396 KiB
01-14.txt AC 25 ms 8816 KiB
01-15.txt AC 70 ms 15236 KiB
01-16.txt AC 70 ms 15364 KiB
01-17.txt AC 70 ms 15288 KiB
01-18.txt AC 70 ms 15360 KiB
01-19.txt AC 22 ms 11340 KiB
01-20.txt AC 53 ms 12004 KiB