C题【博弈论找规律】
// #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;
}
K题【转化+二分+预处理】
// #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 = 1e5 + 5;
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, m, x, op, y, sum;
ll a[N], b[N], dp[1005][1005];
void init()
{
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(dp, 0, sizeof(dp));
sum = 0;
}
bool check(ll t, ll k)
{
ll res = 0;
for (int i = 1; i <= 1000; i++)
{
res += t / i * dp[i][0]; //t/i表示种类,dp[i][0]表示t/i的个数
res -= dp[i][t % i + 1]; //这里i就表示a[i]
}
return res >= k; //精简写法,高效牛逼
}
int main()
{
// IOS;
scanf("%lld", &T);
while (T--)
{ //dp[i][j]表示a[i]数组中=i且b[i]%a[i]≥j的“个数”
init();
scanf("%lld%lld", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
for (int i = 1; i <= n; i++)
{
scanf("%lld", &b[i]);
sum += (b[i] / a[i]);
dp[a[i]][b[i] % a[i]]++;
}
for (int i = 1; i <= 1000; i++) //暴力枚举i从1~1000,求dp数组
for (int j = i; j; j--)
dp[i][j - 1] += dp[i][j]; //
while (m--)
{
scanf("%lld%lld", &op, &x);
if (op == 1)
{
scanf("%lld", &y);
sum -= b[x] / a[x];
for (int j = b[x] % a[x]; ~j; j--)
dp[a[x]][j]--;
for (int j = b[x] % y; ~j; j--)
dp[y][j]++;
sum += b[x] / y;
a[x] = y; //这一步才表示真正的改变
}
else if (op == 2)
{
scanf("%lld", &y);
sum -= b[x] / a[x];
for (int j = b[x] % a[x]; ~j; j--)
dp[a[x]][j]--;
for (int j = y % a[x]; ~j; j--)
dp[a[x]][j]++;
sum += y / a[x];
b[x] = y; //这一步才表示真正的改变
}
else
{
ll l = 1, r = 1e10; //r开大点
ll res = 0;
while (l <= r)
{
ll mid = l + r >> 1;
if (check(mid, x + sum))
{
res = mid;
r = mid - 1;
}
else
l = mid + 1;
}
printf("%lld\n", res);
}
}
}
return 0;
}