惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
AI
AI
博客园 - 三生石上(FineUI控件)
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Y
Y Combinator Blog
大猫的无限游戏
大猫的无限游戏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
雷峰网
雷峰网
NISL@THU
NISL@THU
S
Schneier on Security
T
Threatpost
T
Tenable Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
IT之家
IT之家
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
C
Cybersecurity and Infrastructure Security Agency CISA
P
Privacy & Cybersecurity Law Blog
I
Intezer
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
T
Threat Research - Cisco Blogs
SecWiki News
SecWiki News
AWS News Blog
AWS News Blog
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Proofpoint News Feed
V
V2EX
Recorded Future
Recorded Future
Microsoft Security Blog
Microsoft Security Blog
S
Secure Thoughts
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
Apple Machine Learning Research
Apple Machine Learning Research
Project Zero
Project Zero
PCI Perspectives
PCI Perspectives
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Cloudbric
Cloudbric
Recent Announcements
Recent Announcements
V
Visual Studio Blog
Hacker News: Ask HN
Hacker News: Ask HN
N
News and Events Feed by Topic
C
CERT Recently Published Vulnerability Notes
The Cloudflare Blog
Forbes - Security
Forbes - Security
C
Cisco Blogs
O
OpenAI News
www.infosecurity-magazine.com
www.infosecurity-magazine.com

Shiroha白羽的博客

Golang 踩坑 —— interface 为参数的时候传 nil 指针 Codeforces Round 925 (Div. 3) Codeforces Round 924 (Div. 2) Codeforces Round 923 (Div. 3) Codeforces Round 922 (Div. 2) Codeforces Round 921 (Div. 2) Educational Codeforces Round 161 (Rated for Div. 2) Codeforces Round 920 (Div. 3) Codeforces Round 919 (Div. 2) Hello 2024 Good Bye 2023 Codeforces Round 918 (Div. 4) 个人备份的常用 macOS 清理命令 Codeforces Round 917 (Div. 2) Pinely Round 3 (Div. 1 + Div. 2) Educational Codeforces Round 160 (Rated for Div. 2) Codeforces Round 915 (Div. 2) Codeforces Round 914 (Div. 2) Codeforces Round 913 (Div. 3) Educational Codeforces Round 159 (Rated for Div. 2) Codeforces Round 912 (Div. 2) Codeforces Round 911 (Div. 2) CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!) Educational Codeforces Round 158 (Rated for Div. 2) Codeforces Round 910 (Div. 2) Codeforces Round 909 (Div. 3) Codeforces Round 908 (Div. 2) Educational Codeforces Round 157 (Rated for Div. 2) C++自定义的字面量 Codeforces Round 907 (Div. 2) Codeforces Round 916 (Div. 3) 关于 LRU map 的一些灵感 2023 杭州站 ICPC 现场赛 反复横跳的 Clang-Tidy(cert-dcl21-cpp) Codeforces Round 906 (Div. 2) 一段奇怪的 CPP 代码 Codeforces Round 905 (Div. 3) Codeforces Round 904 (Div. 2) Codeforces Round 903 (Div. 3) Educational Codeforces Round 156 (Rated for Div. 2) Codeforces Round 902 (Div. 2, based on COMPFEST 15 - Final Round) Codeforces Round 901 (Div. 2) Codeforces Round 900 (Div. 3) Codeforces Round 899 (Div. 2) Educational Codeforces Round#155 (Div. 2) Codeforces Round 898 (Div. 4) CodeTON Round 6 (Div. 2) Codeforces Round 897 (Div. 2) Codeforces Round 896 (Div. 2) Codeforces Round 887 (Div. 2) Codeforces Round 895 (Div. 3) 左值-右值-将亡值 blog.mauve.icu Pinely Round 2 (Div. 1 + Div. 2) Harbour.Space Scholarship Contest 2023-2024 (Div. 1 + Div. 2) Codeforces Round 894 (Div. 3) Codeforces Round 888 (Div. 3) Educational Codeforces Round#153 (Div. 2) Codeforces Round 893 (Div. 2) OTPAUTH,两步验证中的通用协议 Codeforces Round 892 (Div. 2) Codeforces Round 891 (Div. 3) Codeforces Round 890 (Div. 2) Educational Codeforces Round#152 (Div. 2) blog.mauve.icu Java Script 的 null 和 undefined 随想 记一次 SQL LEFT JOIN 没有得到预期结果的错误 Codeforces Round#789(Div. 2) GCC/G++ 预编译头性能优化 使用 Junit5 和 Mockito 实现 SpringBoot 的单元测试最优美的解决方案 centOS 防火墙 docker-compse 的问题 C++ 语言实现动态变化的线程池 Codeforces Round#744 (Div. 3) 计算机图形学 Windows 通过网络访问 WSL2 原生 JavaScript 实现图片裁剪 面试复习(计算机图形学) 面试复习(算法) Codeforces Round#706(Div. 2)-Let's Go Hiking 面试复习(Java) 面试复习(Git) 面试复习(Linux) 面试复习(数据库) 面试复习(计算机网络) 面试复习(操作系统) 面试复习(C++) Codeforces Round#699 (Div. 2) 清理 WSL2 的磁盘占用 Codeforces Round#697 (Div. 3) Windows 下的 NTFS 驱动器索引 BUG 计算机网络复习 记一次 Navicat 连接 MySQL 一直报认证错误(Access denied) 计算机网络实验复习 WSL1 使用 Docker 一直无法启动 2020牛客暑期多校训练营(第三场)D-Points Construction Problem——构造 2020牛客暑期多校训练营(第三场)E-Two Matchings——复杂思维与简单dp 2020牛客暑期多校训练营(第二场)I-Interval——最大流转对偶图求最短路 Educational Codeforces Round 80 D. Minimax Problem——二分+二进制处理 Codeforces Round 606 E. Two Fairs——图论 Codeforces Round 612 (Div. 2) C. Garland——DP
Codeforces Round 1099 (Div. 2)
Shiroha · 2026-06-07 · via Shiroha白羽的博客

A. Construct an Array

大致题意

要求构造一个数组,满足:

  1. 任意两项不同
  2. 任意相邻的两项相加不同
  3. 任意相邻的两项相加不等于原数组中任意一个值

思路

我的构造思路比较简单:

注意到任意两项奇数相加一定为偶数,所以我们可以令原数组内的每一个元素都为奇数,那么相邻两数之和肯定为偶数,即可以满足第三条

剩下两条就比较好做,原数列保证递增,这样相邻两项相加后肯定不相等,因为一定也是一个递增序列

AC Code

1
2
3
4
5
6
7
8
9
void solve() {
int _;
cin >> _;
for (int ts = 0; ts < _; ++ts) {
int n;
cin >> n;
for (int i = 0; i < n; ++i) cout << (i << 1) + 1 << " \n"[i == n -1];
}
}

B. Another Sorting Problem

大致题意

给出一个序列 $a$,允许你选择其中的一个子序列,让子序列上的每一项都执行 $+ k$,其中 $k$ 为任意值。问能否将序列转为非递减序列

思路

容易得到,$k$ 不是越大越好,即有一个范围下,$k$ 可以达成目标,所以我们可以考虑找到最小的 $k$

由于需要加的那个值是确定的,且对所有值生效,那么它必定要满足一个条件,即

$\forall i > j, a_i < a_j$ 必然需要一个 $k$ 满足 $a_j + k >= a_i$

所以我们需要先找到最小的 $k$,即找到最大的 $k$,满足前面的等式

然后再带入序列测试一下是否满足,如果满足那就是正确答案

AC Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void solve() {
int _;
cin >> _;
for (int ts = 0; ts < _; ++ts) {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; ++i) cin >> v[i];
int l = 0, ml = v[0];
for (int i = 1; i < n; ++i) {
if (v[i] >= ml) {
ml = v[i];
continue;
}

l = max(l, ml - v[i]);
}

for (int i = 1; i < n; ++i) if (v[i] < v[i - 1]) v[i] += l;
bool ok = true;
for (int i = 0; i < n - 1; ++i) if (v[i] > v[i + 1]) ok = false;
cout << (ok ? "YES" : "NO") << endl;
}
}

C. Chipmunk Theo and Equality

大致题意

有一个序列,允许你对任意一项执行以下操作

  1. 如果它是偶数,则除以 2
  2. 如果它是奇数,则 + 1

问至少需要几步,才能让整个序列里的所有值相同

思路

一开始我从二进制角度在考虑,其实这个过程就是不断消去末尾的 $0$,然后再 $+1$ 去消去末尾的 $1$,直到最后只剩下一个 $1$ 在二进制视角上,也就是 $2^n$

但是这道题其实可以很简单完成,由于上面提到的内容(不断消去末尾的 $0$ 和 $1$),实际上每个值不会像冰雹定理一样执行很多次,而是仅仅 $2 \times bits$ 次就可以到 $1$

所以直接枚举所有值到 $1$ 的过程中会产生的数字,并记录步数,找到那些出现次数等于序列长度,且总步数最小的那个就行了

AC Code

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
void solve() {
int _;
cin >> _;
for (int ts = 0; ts < _; ++ts) {
int n;
cin >> n;
vector<int> data(n);
for (int i = 0; i < n; ++i) cin >> data[i];

unordered_map<int, pair<int, int>> ans;
for (int i = 0; i < n; ++i) {
int cnt = 0;
ans[data[i]].first++;
if (data[i] == 1) {
ans[2].first++;
ans[2].second++;
continue;
}

while (data[i] > 1) {
++cnt;
if (data[i] & 1) ++data[i];
else data[i] >>= 1;
ans[data[i]].second += cnt;
ans[data[i]].first++;
}
}
int res = INT_MAX;

for (auto &item: ans) {
if (item.second.first != n) continue;
res = min(res, item.second.second);
}
cout << res << endl;
}
}

D. Maximum Prefix Sums

大致题意

有一个原始数组 $a$,其中一部分丢失了,需要你还原或者说找到一种可能的 $a$ 的解

对于这个数组 $a$,定义前缀和数组 $b$,满足 $b_i = \sum_{n=1}^{i} a_i$

对于这个数组,再定义前缀和最大值数组 $c$,满足 $c_i = \max_{n=1}^{i} b_i$

现在给你完整的 $c$ 数组和部分 $a$ 数组,询问一种可能的 $a$ 的解

思路

首先根据 $c_i$ 去反推每一个 $b_i$ 的范围,即

  • 如果 $c_i \neq c_{i-1}$ 那么必然 $b_i = c_i$
  • 如果 $c_i = c_{i-1}$ 那么必然 $b_i \in \left [ -\infty , c_i \right ]$

然后,如果此时 $a_i$ 已知的话,那么还可以得到

$b_i \in \left [ min(b_{i-1}) + a_i , max(b_{i-1}) + a_i \right ]$

完成一次正向推演后,还需要进行一次逆向推演,如果此时 $a_i$ 已知的话,可以得到:

$b_{i-1} \in \left [ min(b_{i}) - a_i , max(b_{i}) - a_i \right ]$

这三个条件需要同时满足,可以得到一个具体的 $b_i$ 的范围了。接下来就是尝试构造即可,只要在范围内理论上都可以构造出来,最后检查一遍是否满足预期即可

AC Code

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
48
49
50
51
52
53
54
55
56
57
#define int long long

void solve() {
int _;
cin >> _;
for (int ts = 0; ts < _; ++ts) {
int n;
cin >> n;
string s;
s.resize(n);
vector<int> a(n), c(n);
cin >> s;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < n; ++i) cin >> c[i];

if (s[0] == '1' && a[0] != c[0]) {
cout << "No" << endl;
continue;
}

a[0] = c[0];

vector<pair<int, int>> pb(n);
// init pb
int last = INT_MIN;
for (int i = 0; i < n; ++i) {
if (last != c[i]) pb[i] = {c[i], c[i]};
else pb[i] = {INT_MIN, c[i]};
last = c[i];

if (s[i] == '1' && i != 0) {
auto [fst, snd] = make_pair(pb[i - 1].first + a[i], pb[i - 1].second + a[i]);
pb[i] = {max(pb[i].first, fst), min(pb[i].second, snd)};
}
}
// rof
for (int i = n - 1; i >= 1; --i) {
if (s[i] == '0') continue;
auto [fst, snd] = make_pair(pb[i].first - a[i], pb[i].second - a[i]);
pb[i - 1] = {max(pb[i - 1].first, fst), min(pb[i - 1].second, snd)};
}

for (int i = 1; i < n; ++i) if (s[i] == '0') a[i] = pb[i].second - pb[i - 1].second;

// check
int fb = 0, fc = INT_MIN;
bool flag = true;
for (int i = 0; i < n; ++i) {
fb += a[i];
fc = max(fc, fb);
if (fc != c[i]) flag = false;
}

cout << (flag ? "Yes" : "No") << endl;
if (flag) for (int i = 0; i < n; ++i) cout << a[i] << " \n"[i == n - 1];
}
}