标签:Contest2969 const int res ll UPC 训练赛 fac mod
文章目录
C题
Hakase and Nano
博弈论
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int N = 1e6 + 10;
const int M = 2e6 + 1000;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int pi = acos(-1);
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
ll T, m, f, tot;
ll a[N];
void init()
{
memset(a, 0, sizeof(a));
tot = 0;
}
int main()
{
// IOS;
scanf("%lld", &T);
while (T--)
{
init();
scanf("%lld %lld", &m, &f);
for (int i = 1; i <= m; i++)
{
scanf("%lld", &a[i]);
if (a[i] == 1)
tot++;
}
if (f == 1)
{
if (tot % 3 == 0 && tot == m)
puts("No");
else
puts("Yes");
}
else
{
if ((tot == m - 1 && m % 3 == 0) || (m % 3 == 1 && tot >= m - 1))
puts("No");
else
puts("Yes");
}
}
return 0;
}
D题
Master of Random
数论
越界问题蚌埠住了,一直RE
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int N = 1e6 + 10;
const int M = 2e6 + 1000;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int pi = acos(-1);
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
ll T, n, res, cnt;
ll a[N], fac[N], inv[N]; //1e8运行错误,内存会爆
ll ksm(ll a, ll b)
{
ll res = 1;
for (; b; b >>= 1)
{
if (b & 1)
res = res * a % mod; //快速幂能写错giao
a = a * a % mod;
}
return res % mod;
}
void init()
{
fac[0] = 1; //
for (ll i = 1; i < N; i++)
{
fac[i] = fac[i - 1] * i % mod;
inv[i] = ksm(i, mod - 2);
}
}
int main()
{
// IOS;
init();
scanf("%lld", &T);
while (T--)
{
scanf("%lld", &n);
for (ll i = 0; i < n; i++)
scanf("%lld", &a[i]);
cnt = fac[n - 1];
res = a[0] * fac[n - 1] % mod;
for (ll i = 1; i < n; i++)
{
cnt = (cnt + fac[n - 1] * inv[i] % mod) % mod;
res = (res + cnt * a[i] % mod) % mod;
}
res = res * ksm(fac[n], mod - 2) % mod;
// res = res *inv[fac[n]] % mod;//inv[fac[n]]会越界
printf("%lld\n", res % mod);
}
return 0;
}
标签:Contest2969,const,int,res,ll,UPC,训练赛,fac,mod 来源: https://blog.csdn.net/qq_51201910/article/details/120535224
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。