社区讨论
求调
P4978赌神:决斗参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @m2ckymwd
- 此快照首次捕获于
- 2024/10/17 08:46 去年
- 此快照最后确认于
- 2024/10/17 13:33 去年
CPP
#include <bits/stdc++.h>
#define int __int128
using namespace std;
using i64 = long long;
using i128 = __int128;
using ull = unsigned long long;
using pii = std::pair < int, int >;
#define fi first
#define se second
#define pc putchar
#define pb push_back
#define ma make_pair
#define eb emplace_back
#define all(x) x.begin(), x.end()
const int N = 1e6 + 10;
int mod = 998244353;
const int inf = 1e18;
void file()
{
freopen(".in","r",stdin);
freopen(".out","w",stdout);
}
char buf[1<<15],*p1=buf,*p2=buf;
#define nc() (p1==p2&&(p2=buf+fread(p1=buf,1,1<<15,stdin),p1==p2)?-1:*p1++)
inline int read()
{
int x=0;char c=nc();
for(;!isdigit(c);c=nc());
for(; isdigit(c);c=nc()) x=(x<<3)+(x<<1)+(c^48);
return x;
}
void print(int x)
{
if(x<0) putchar('-'),x=-x;
if(x>9) print(x/10);
putchar(x%10+'0');
return;
}
int n, m;
int a[N], b[N], c[N], d[N];
int sum = 1, cnt1, cnt2;
int ans;
int fpm(int a, int n)
{
int res = 1;
while(n)
{
if(n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
signed main(void)
{
// file();
cin.tie(0),cout.tie(0)->ios::sync_with_stdio(false);
n = read(), m = read();
sum = (sum * n * (n + 1) / 2 % mod + mod) % mod;
sum = (sum * m * (m + 1) / 2 % mod + mod) % mod;
for(int i = 1;i <= n;i ++) a[i] = read(), a[i] += a[i - 1];
for(int i = 1;i <= m;i ++) b[i] = read(), b[i] += b[i - 1];
for(int i = 1;i <= n;i ++) for(int j = i;j <= n;j ++) c[++ cnt1] = a[j] - a[i - 1];
for(int i = 1;i <= m;i ++) for(int j = i;j <= m;j ++) d[++ cnt2] = b[j] - b[i - 1];
sort(c + 1, c + cnt1 + 1);
sort(d + 1, d + cnt2 + 1);
// for(int i = 1;i <= cnt1;i ++) print(c[i]), pc(' ');
// pc('\n');
// for(int i = 1;i <= cnt2;i ++) print(d[i]), pc(' ');
for(int i = 1;i <= cnt2;i++) {
int pos = upper_bound(c + 1, c + cnt1 + 1, d[i]) - c;
if(c[pos] > d[i]) ans += (cnt1 - pos + 1);
ans %= mod;
}
print(ans * fpm(sum, mod - 2) % mod), pc('\n');
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...