多校冲刺 NOIP 20211101 模拟 (20)
T1
根据期望的线性性,即求\(E(每次操作的平均数)\),然后考虑每个元素被计算多少次,然后就无了
T2
\(f_i\)表示 i 以后的期望值
考虑逆推,枚举到 i 时比较平均值和\(f_{i+1}\)的大小关系,分情况转移
T3
这个发现数据是随的,因为随的程序都发出来了
然后还是那个结论,随机数据下单调栈元素不超过log个,然后就可以快乐地爆扫单调栈了
单调栈每个元素维护管辖的左端点,最大值和除去最大值的乘积之和,每次加入一个点就爆扫单调栈乘上这个点的点权
需要卡常,然后可以\(O(n\log_2 n)\)过1e7
T4
式子是\(\sum_{d=1}^{\sqrt n}\mu (d)S(\frac{n}{d^2})\),其中\(S(x)=\frac{x*(x+1)}{2}\)
然后这个显然可以除法分块,但是我因为不会证明这题除法分块的复杂度就死了,最后写的\(O(n\sqrt n)\)
\(O(\sqrt n+T\sqrt[3]n)\),因为若\(i <= n^{\frac{1}{3}}\),值不超过\(n^{\frac{1}{3}}\)种
若\(i>n^{\frac{1}{3}}\),\(\frac{n}{i^2}<n^{\frac{1}{3}}\)也不超过\(n^{\frac{1}{3}}\)种
代码
T1
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e7 + 11;
const int mod = 998244353;
int n, m;
int jc[N], ny[N];
int inv[N];
inline int read() {
int s = 0;
char ch = getchar();
while (ch > '9' || ch < '0') ch = getchar();
while (ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return s;
}
int fm(int x, int y) {
int ans = 1;
x %= mod;
while (y) {
if (y & 1)
ans = ans * x % mod;
x = x * x % mod, y >>= 1;
}
return ans;
}
void pre() {
jc[0] = 1, ny[0] = 1;
inv[0] = inv[1] = 1;
for (int i = 1; i <= 2e7; ++i) jc[i] = jc[i - 1] * i % mod;
ny[(int)2e7] = fm(jc[(int)2e7], mod - 2);
for (int i = 2e7 - 1; i; --i) ny[i] = ny[i + 1] * (i + 1) % mod, inv[i + 1] = jc[i] * ny[i + 1] % mod;
return;
}
int C(int x, int y) {
if (x == y || x == 0)
return 1;
if (x < 0 || x > y)
return 0;
return jc[y] * ny[x] % mod * ny[y - x] % mod;
}
signed main() {
FILE* x = freopen("mos.in", "r", stdin);
x = freopen("mos.out", "w", stdout);
pre();
n = read();
m = read();
int num = n * m, sum = 0;
for (int i = 1; i <= n; ++i) sum += read();
sum %= mod;
(sum *= m) %= mod;
int ans = 0;
int nynum = fm(num, mod - 2);
for (int i = 1; i <= num; ++i) ans = (ans + i * inv[i + 1]) % mod;
cout << ans * nynum % mod * sum % mod << endl;
return 0;
}
T2
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define double long double
const int N = 1e6 + 11;
int n;
double f[N];
int l[N], r[N];
inline int read() {
int s = 0;
char ch = getchar();
while (ch > '9' || ch < '0') ch = getchar();
while (ch >= '0' && ch <= '9') {
s = (s << 1) + (s << 3) + (ch ^ 48);
ch = getchar();
}
return s;
}
inline int max_(int a, int b) { return a > b ? a : b; }
int main() {
FILE* x = freopen("pag.in", "r", stdin);
x = freopen("pag.out", "w", stdout);
n = read();
int ans = 0;
for (int i = 1; i <= n; ++i) l[i] = read(), r[i] = read();
f[n] = (l[n] + r[n]) / 2.0;
double sum = 0;
for (int i = n - 1; i; --i) {
sum = (l[i] + r[i]) / 2.0;
if (l[i] == r[i]) {
f[i] = max_(l[i], f[i + 1]);
continue;
}
if (r[i] < f[i + 1])
f[i] = f[i + 1];
else
f[i] = (r[i] + f[i + 1]) / 2 * (r[i] - f[i + 1]) / (r[i] - l[i]) +
f[i + 1] * (f[i + 1] - l[i]) / (r[i] - l[i]);
}
printf("%.5Lf\n", f[1]);
return 0;
}
T3
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
#define int unsigned long long
const int N = 1e7 + 11;
struct sta_ {
int sum;
int maxx;
int l, i;
} sta[N];
int top, p;
vector<int> vct;
namespace GenHelper {
unsigned z1, z2, z3, z4, b;
unsigned rand_() {
b = ((z1 << 6) ^ z1) >> 13;
z1 = ((z1 & 4294967294U) << 18) ^ b;
b = ((z2 << 2) ^ z2) >> 27;
z2 = ((z2 & 4294967288U) << 2) ^ b;
b = ((z3 << 13) ^ z3) >> 21;
z3 = ((z3 & 4294967280U) << 7) ^ b;
b = ((z4 << 3) ^ z4) >> 12;
z4 = ((z4 & 4294967168U) << 13) ^ b;
return (z1 ^ z2 ^ z3 ^ z4);
}
} // namespace GenHelper
inline int read() {
int s = 0;
char ch = getchar();
while (ch > '9' || ch < '0') ch = getchar();
while (ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return s;
}
std::vector<int> get(int n, unsigned s, int l, int r) {
std::vector<int> a;
using namespace GenHelper;
z1 = s;
z2 = unsigned((~s) ^ 0x233333333U);
z3 = unsigned(s ^ 0x1234598766U);
z4 = (~s) + 51;
for (int i = 1; i <= n; i++) {
int x = rand_() & 32767;
int y = rand_() & 32767;
a.push_back(l + (x * 32768 + y) % (r - l + 1));
}
return a;
}
inline int min_(int x, int y) { return x > y ? y : x; }
inline void md(int& x) {
if (x >= p)
x -= p;
return;
}
signed main() {
FILE* x = freopen("tio.in", "r", stdin);
x = freopen("tio.out", "w", stdout);
int n = read(), s = read();
int l = read(), r = read();
p = read();
vct = get(n, s, l, r);
int ans = 0;
for (int lst, x, sum, i = 1; i <= n; ++i) {
x = vct[i - 1];
lst = i;
sum = 1;
while (top > 0 && sta[top].maxx <= x) lst = min_(lst, sta[top].l), md(sum += sta[top].sum), --top;
sta[++top] = (sta_){ (sum * x) % p, x, lst, i };
for (int j = 1; j < top; ++j) sta[j].sum = sta[j].sum * x % p;
for (int j = 1; j <= top / 2; ++j) ans += sta[j].maxx * sta[j].sum;
ans %= p;
for (int j = top / 2 + 1; j <= top; ++j) ans += sta[j].maxx * sta[j].sum;
ans %= p;
}
cout << ans << endl;
return 0;
}
T4
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
#define int unsigned long long
const int N = 1e7 + 11;
bool fp[N];
int p[N], num;
int mu[N];
int sum[N];
inline int read() {
int s = 0;
char ch = getchar();
while (ch > '9' || ch < '0') ch = getchar();
while (ch >= '0' && ch <= '9') {
s = (s << 1) + (s << 3) + (ch ^ 48);
ch = getchar();
}
return s;
}
void pre() {
fp[0] = fp[1] = 1;
mu[1] = 1;
sum[1] = 1;
for (int i = 2; i <= 1e7; ++i) {
if (!fp[i]) {
p[++num] = i;
mu[i] = -1;
}
for (int j = 1; j <= num && p[j] * i <= 1e7; ++j) {
fp[i * p[j]] = 1;
if (i % p[j] == 0) {
mu[i * p[j]] = 0;
break;
} else
mu[i * p[j]] = -mu[i];
}
sum[i] = sum[i - 1] + mu[i] * i * i;
}
return;
}
inline int min_(int a, int b) { return a > b ? b : a; }
inline int js(int x) {
if (x & 1)
return (x + 1) / 2 * x;
else
return x / 2 * (x + 1);
}
int get_ans(int n) {
int s = 0;
int k = sqrt(n);
int l = 1, r = 0;
while (l <= k) {
r = min_(k, sqrt(n / (n / (l * l))));
s += (sum[r] - sum[l - 1]) * js(n / (l * l));
l = r + 1;
}
return s;
}
signed main() {
FILE* x = freopen("kfc.in", "r", stdin);
x = freopen("kfc.out", "w", stdout);
pre();
int t = read();
while (t--) printf("%llu\n", get_ans(read()));
return 0;
}