Submission #74657569
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define se second
#define fi first
#define pb push_back
#define pf push_front
#define ld long double
#define INF 1e18
#define lcm(x, y) x / __gcd(x, y) * y
#define Pair pair<ll, ll>
#define pii pair<int, int>
#define Pq priority_queue<ll>
#define Pqr priority_queue<ll, vector<ll>, greater<ll >>
#define clockst clock_t tStart = clock()
#define clockfin printf("Time taken: %.2fs\n",(double)(clock() - tStart)/CLOCKS_PER_SEC)
#define all(x) x.begin(), x.end()
#define sz(x)((ll)(x).size())
#define eb emplace_back
#define mp make_pair
#define mems(a, x) memset((a),(x), sizeof(a))
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,popcnt,lzcnt,bmi,bmi2,fma")
typedef unsigned long long ull;
void init() { freopen("cf.INP", "r", stdin); freopen("cf.OUT", "w", stdout); }
ll xc[5] = { -1, 1, 0, 0 }, yc[5] = { 0, 0, 1, -1 };
ll xc8[8] = { -1, 1, 0, 0, -1, 1, -1, 1 };
ll yc8[8] = { 0, 0, 1, -1, -1, 1, 1, -1 };
const long double pi = acosl(-1.0L);
template<class T1, class T2> bool cmax(T1 &x, const T2 &y) { if(x < y) { x = y; return 1; } return 0; }
inline ll read()
{
ll x = 0;
char ch = getchar();;
bool str = 1;
while(ch < '0' || ch > '9')
{
if(ch == '-') str = 0; ch = getchar();;
}
while(ch >= '0' && ch <= '9')
{
x =((x << 3) +(x << 1)) + ch - '0';
ch = getchar();;
}
return str ? x : x;
}
const ll MOD = 998244353;
void solve()
{
ll n, m;
cin >> n >> m;
vector<ll> a(n + 1), b(m + 1);
for (ll i = 1; i <= n; i++) cin >> a[i];
for (ll i = 1; i <= m; i++) cin >> b[i];
ll suma = 0, sumb = 0;
for (ll i = 1; i <= n; i++) suma = (suma + (ll)i * a[i]) % MOD;
for (ll i = 1; i <= m; i++) sumb = (sumb + b[i]) % MOD;
ll first = suma * sumb % MOD;
vector<ll> pref(n + 1, 0);
for (ll i = 1; i <= n; i++) pref[i] = (pref[i - 1] + a[i]) % MOD;
ll t = 0;
for (ll j = 1; j <= m; j++)
{
if (j > n) continue;
ll s = 0;
for (ll q = 1; (ll)q * j <= n; q++)
{
ll l = (ll)q * j;
ll r = min((ll)n, (ll)(q + 1) * j - 1);
ll block = (pref[r] - pref[l - 1] + MOD) % MOD;
s = (s + (ll)q * block) % MOD;
}
t = (t + (b[j] % MOD) * (j % MOD) % MOD * s) % MOD;
}
ll ans = (first - t + MOD) % MOD;
cout << ans << '\n';
}
bool multest = 0;
int main()
{
fast;
ll t = 1;
if(multest) cin >> t;
while(t--) solve();
return 0;
}
Submission Info
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
450 / 450 |
| Status |
|
|
| 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 |
3 ms |
3060 KiB |
| 00-sample-02.txt |
AC |
1 ms |
2996 KiB |
| 01-01.txt |
AC |
1 ms |
3056 KiB |
| 01-02.txt |
AC |
1 ms |
3100 KiB |
| 01-03.txt |
AC |
1 ms |
3100 KiB |
| 01-04.txt |
AC |
4 ms |
3228 KiB |
| 01-05.txt |
AC |
5 ms |
3228 KiB |
| 01-06.txt |
AC |
5 ms |
3236 KiB |
| 01-07.txt |
AC |
5 ms |
3124 KiB |
| 01-08.txt |
AC |
5 ms |
3236 KiB |
| 01-09.txt |
AC |
347 ms |
14560 KiB |
| 01-10.txt |
AC |
368 ms |
14668 KiB |
| 01-11.txt |
AC |
156 ms |
6972 KiB |
| 01-12.txt |
AC |
156 ms |
6940 KiB |
| 01-13.txt |
AC |
156 ms |
6980 KiB |
| 01-14.txt |
AC |
185 ms |
8052 KiB |
| 01-15.txt |
AC |
346 ms |
14748 KiB |
| 01-16.txt |
AC |
348 ms |
14628 KiB |
| 01-17.txt |
AC |
346 ms |
14688 KiB |
| 01-18.txt |
AC |
345 ms |
14780 KiB |
| 01-19.txt |
AC |
163 ms |
10740 KiB |
| 01-20.txt |
AC |
216 ms |
11340 KiB |