多校 Day 1
A
选择 ,使得 最大。
由于可以不选,可以把 加入到 和 中。
若固定 ,则 ,是关于 的一次函数,因此要取到极值, 一定在两个端点上。固定 的情况同理。
因此全局最优解一定在这之中:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int maxn = 2e5 + 5;
int x, y, n, m;
void Solve() {
cin >> x >> y >> n >> m;
int maxx = 0, minx = 0;
int maxy = 0, miny = 0;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
maxx = max(maxx, a);
minx = min(minx, a);
}
for (int i = 1; i <= m; i++) {
int b;
cin >> b;
maxy = max(maxy, b);
miny = min(miny, b);
}
maxx += x, minx += x, maxy += y, miny += y;
cout << max(max(maxx * maxy, minx * miny), max(maxx * miny, minx * maxy)) << endl;
}
signed main() {
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T;
cin >> T;
while (T--) {
Solve();
}
return 0;
}
F
把总期望拆成 每盏灯打开时的 连续段的期望个数 之和。
给每盏灯独立分配一个 上的均匀随机数 ,按 从小到大的顺序开灯。由于这些随机数几乎一定两两不同,它们的相对大小构成一个均匀随机排列,与原问题完全等价。
亮灯连续段的数量等于「既是亮着的,又是所在段的起点」的位置数。位置 是起点,需要满足:
- 第 盏灯亮着。
- ,或第 盏灯不亮。
设灯 正在打开,。
1. 端点
第 盏灯一定是起点。位置 因为左边有灯 亮着,不可能是起点。
其余 个位置 成为起点的概率均为 (自身亮且左边不亮)。
积分得
2. 端点
位置 成为起点的概率为 。位置 成为起点的概率为 (左边不亮)。
其余 个位置成为起点的概率为 。
同样得到
3. 内部点
- 位置 :概率 。
- 位置 :正在打开,它成为起点要求左边不亮,概率 。
- 位置 :左边是 已亮,不可能成为起点,概率 。
- 其余 个位置:概率 。
积分得
汇总
记 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using namespace std;
typedef long long ll;
// #define int long long
const int mod = 998244353;
const int maxn = 2e5 + 5;
int qpow(int a, int n) {
int res = 1;
while (n) {
if (n & 1) res = 1ll * res * a % mod;
a = 1ll * a * a % mod;
n /= 2;
}
return res;
}
int n;
int a[maxn];
void Solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int ans = 0;
if (n == 1) {
cout << a[1] << endl;
return;
}
ans = 1ll * (n + 4) * (a[1] + a[n]) % mod;
for (int i = 2; i < n; i++) {
ans = (ans + 1ll * (n + 3) * (a[i]) % mod) % mod;
}
cout << 1ll * ans * qpow(6, mod - 2) % mod << endl;
}
signed main() {
// freopen("1006.in", "r", stdin);
// freopen("1006.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T;
cin >> T;
while (T--) {
Solve();
}
return 0;
}
E
构造 ,字符集设为 。
令 的数量为 , 的数量为 。
全 串对答案的贡献为 ,全 串对答案的贡献为 。
所以只需要找到最大的 ,使得 ,然后再填 个 就行了。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using namespace std;
using i64 = long long;
const int inf = 2e9;
const int maxn = 1e6 + 5;
int k;
void solve() {
cin >> k;
int n = 1;
while (n * (n + 1) / 2 <= k) ++n;
--n;
vector<char> ans;
for (int i = 1; i <= n + 1; i++) ans.push_back('a');
for (int i = 1; i <= k - n * (n + 1) / 2; i++) ans.push_back('b');
cout << ans.size() << " " << 2 << endl;
for (char x : ans) cout << x;
cout << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}