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

推荐订阅源

H
Hacker News: Front Page
博客园_首页
大猫的无限游戏
大猫的无限游戏
有赞技术团队
有赞技术团队
Microsoft Azure Blog
Microsoft Azure Blog
Recorded Future
Recorded Future
博客园 - Franky
Application and Cybersecurity Blog
Application and Cybersecurity Blog
U
Unit 42
S
Secure Thoughts
博客园 - 司徒正美
美团技术团队
C
Cisco Blogs
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
V
Vulnerabilities – Threatpost
T
Troy Hunt's Blog
S
Security Affairs
爱范儿
爱范儿
AWS News Blog
AWS News Blog
Help Net Security
Help Net Security
Blog — PlanetScale
Blog — PlanetScale
T
Threatpost
F
Fortinet All Blogs
Scott Helme
Scott Helme
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog RSS Feed
O
OpenAI News
S
Schneier on Security
Stack Overflow Blog
Stack Overflow Blog
T
Tor Project blog
AI
AI
D
DataBreaches.Net
PCI Perspectives
PCI Perspectives
T
Tailwind CSS Blog
Martin Fowler
Martin Fowler
P
Palo Alto Networks Blog
C
CERT Recently Published Vulnerability Notes
腾讯CDC
T
Tenable Blog
人人都是产品经理
人人都是产品经理
Recent Announcements
Recent Announcements
C
Cyber Attacks, Cyber Crime and Cyber Security
Jina AI
Jina AI
Hacker News - Newest:
Hacker News - Newest: "LLM"
Google Online Security Blog
Google Online Security Blog
S
Securelist
P
Proofpoint News Feed
L
LINUX DO - 最新话题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

Shiroha白羽的博客

Golang 踩坑 —— interface 为参数的时候传 nil 指针 Codeforces Round 925 (Div. 3) Codeforces Round 924 (Div. 2) Codeforces Round 923 (Div. 3) 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 一直无法启动 我的ACM脚印 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 922 (Div. 2)
Shiroha · 2024-03-24 · via Shiroha白羽的博客

A. Brick Wall

大致题意

有一堵砖墙,由砖块组成,每一个砖块都是 $1 \times k$ ($k$ 可以是任意值,每一块砖块的 $k$ 可以不一样)的方块,可以横放或者纵向放

问横放和纵放的最大差值是多少

思路

那全都横放不就行了

AC code

1
2
3
4
5
6
7
8
9
void solve() {
int _;
cin >> _;
for (int tc = 0; tc < _; ++tc) {
int n, m;
cin >> n >> m;
cout << n * (m / 2) << endl;
}
}

B. Minimize Inversions

大致题意

有两个数组,每次允许操作选择两个下标,在两个数组中分别操作交换这两个下标的值

问让这两个数组的逆序对数量之和最小,应该如何操作

思路

大胆猜测,把其中一个数组排序好就行了

AC code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void solve() {
int _;
cin >> _;
for (int tc = 0; tc < _; ++tc) {
int n;
cin >> n;
vector<pair<int, int>> data(n);
for (auto& [fst, snd]: data) cin >> fst;
for (auto& [fst, snd]: data) cin >> snd;
sort(data.begin(), data.end());
for (int i = 0; i < n; ++i) cout << data[i].first << " \n"[i == n - 1];
for (int i = 0; i < n; ++i) cout << data[i].second << " \n"[i == n - 1];
}
}

C. XOR-distance

大致题意

有两个数,现在希望找到一个 $x$,使得 $\left | (a \oplus x) - (b \oplus x)\right |$ 最小,且 $x \in [0, r]$

思路

由于是异或运算,且最后取了绝对值,实际上对于每一个比特位而言,$x$ 取什么毫无意义。因为对于这个比特位而言,$x$ 取任意值,不同的则还是不同,相同的则还是相同

所以考虑的情况是,某个高的比特位发生了 $a \neq b$ 的情况,这个时候需要努力去构造另外一个值的下面的比特位,使得高位的这个差值带来的影响尽可能小

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
#define int long long

void solve() {
int _;
cin >> _;
for (int tc = 0; tc < _; ++tc) {
int a, b, r;
cin >> a >> b >> r;

auto f = [&](const int v, int i) {
int rs = r, res = 0;
for (; i >= 0; --i) {
if ((a & 1LL << i) == (b & 1LL << i)) res += 1LL << i;
else if (v & 1LL << i) {
if (rs >= 1LL << i) rs -= 1LL << i;
else res += 2 * (1LL << i);
}
}
return res;
};

int ans = 0;
for (int i = 63; i >= 0; --i) {
if ((a & 1LL << i) == (b & 1LL << i)) continue;
ans = 1 + f(a & 1LL << i ? a : b, i - 1);
break;
}
cout << ans << endl;
}
}

D. Blocking Elements

大致题意

从一个数组中,取出一部分值,将整个数组拆成 $n$ 份,将每一份内进行求和,同时取出的值也作为单独的一份进行求和,这些求和值中最大的就是这个数组的代价

问代价最小是多少

思路

显然,可以二分,问题是如何检查二分的答案是否合法,这里设二分得到的答案是 $v$

可以通过 dp 的方式来计算,令 dp[i] 作为第 $i$ 个值被选中后,$[1, i]$ 中被选中的那些值的总代价

可以得到 $dp[i] = dp[j] + a[i]$,其中 $j \in [l, i), \sum_{x=l}^{i-1} a_x \leq v$

故搞个优先队列维护一下即可

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
#define int long long

void solve() {
int _;
cin >> _;
for (int tc = 0; tc < _; ++tc) {
int n;
cin >> n;
vector<int> data(n), dp(n);
for (auto& i: data) cin >> i;
auto check = [&](const int v) {
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq;
pq.emplace(0, -1);
int l = 0, tot = 0;
for (int i = 0; i < n; ++i) {
if (pq.empty()) dp[i] = data[i];
else dp[i] = pq.top().first + data[i];
tot += data[i];
while (tot > v) {
tot -= data[l];
++l;
}
pq.emplace(dp[i], i);
while (!pq.empty() && pq.top().second + 1 < l) pq.pop();
}
while (!pq.empty()) {
if (pq.top().first <= v) return true;
pq.pop();
}
return false;
};

int l = 0, r = 1e18;
while (l + 1 < r) {
if (const int mid = l + r >> 1; check(mid)) r = mid;
else l = mid;
}
cout << r << endl;
}
}

E. ace5 and Task Order

大致题意

有一个未知的数组 $a$ 和一个未知的初始值 $x$

每次允许你询问一个 $i$,若

  • $a_i < x$,则返回 <,且 $x \leftarrow x - 1$
  • $a_i > x$,则返回 >,且 $x \leftarrow x + 1$
  • $a_i = x$,则返回 =

要求求出原始数组

思路

因为不断轮询同一个值,必然最后 $x$ 和它相同

这之后再询问别的值,可以得到它们的关系,同时再询问一次之前的那个值,就可以恢复回来

可以考虑类似快排的方式进行操作即可。注意可以考虑随机函数避免被数据恶心

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

auto pre = [&](const int i) {
while (true) {
cout << "? " << i << endl;
cout.flush();
char tmp;
cin >> tmp;
if (tmp == '=') return;
}
};

auto check = [&](const int i, const int base) {
cout << "? " << i << endl;
cout.flush();
char tmp, temp;
cin >> tmp;
cout << "? " << base << endl;
cout.flush();
cin >> temp;
return tmp == '<';
};

function<void(int, int)> qs = [&](const int l, const int r) {
if (l >= r) return;
swap(pos[rand() % (r - l) + l], pos[r]);
pre(pos[r]);
int c = l;
for (int i = l; i < r; ++i) if (check(pos[i], pos[r])) swap(pos[c++], pos[i]);
swap(pos[c], pos[r]);
qs(l, c - 1);
qs(c + 1, r);
};
qs(1, n);
vector<int> ans(n + 1);
for (int i = 1; i <= n; ++i) ans[pos[i]] = i;
cout << "! ";
for (int i = 1; i <= n; ++i) cout << ans[i] << " \n"[i == n];
cout.flush();
}
}