ABC462 赛后总结
WRT_Partisan · · 题解
A - Secret Numbers
题目大意
给你一个字符串
思路
与其删除非数字字符,不如只输出数字字符。
代码
/*
* @FilePath: \c++\ABC462A.cpp
* @Author: WRT_Partisan
* @Date: 2026-06-13 19:40:22
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
string s;
signed main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> s;
for (auto i : s)
if (i >= '0' && i <= '9')
cout << i;
return 0;
}
B - Gift
题目大意
编号为
思路
按照题意模拟即可。
代码
/*
* @FilePath: \c++\ABC462B.cpp
* @Author: WRT_Partisan
* @Date: 2026-06-13 19:40:57
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, k, a;
vector<int> mp[105];
signed main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> k;
for (int j = 1; j <= k; j++)
cin >> a, mp[a].push_back(i);
}
for (int i = 1; i <= n; i++)
{
cout << mp[i].size() << " ";
for (auto j : mp[i])
cout << j << " ";
cout << "\n";
}
return 0;
}
C - Not Covered Points
题目大意
给出
思路
将点按照横坐标升序排序,从左到右对于每个点看在其之前是否有纵坐标比它小的点,如果没有则答案加一。
用 set 维护即可。
代码
/*
* @FilePath: \c++\ABC462C.cpp
* @Author: WRT_Partisan
* @Date: 2026-06-13 19:41:04
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct Node
{
int x, y;
bool operator<(const Node &a) const { return this->x < a.x; }
} a[300005];
int n, ans;
set<int> st;
signed main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i].x >> a[i].y;
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++)
{
auto it = st.upper_bound(a[i].y);
if (it == st.begin())
ans++;
st.insert(a[i].y);
}
cout << ans;
return 0;
}
D - Accomplice
题目大意
一场犯罪有
这场犯罪有两名罪犯,持续时间为
思路
刚开始题读错了(翻译的锅),认为是罪犯的组合数,吭哧半天写了个带 tag 的线段树然后发现样例过不了。
对于每一个人来说,如果
用差分维护每个人犯罪开始时间点的范围,然后对于每个时间点,如果有
代码
/*
* @FilePath: \c++\ABC462D.cpp
* @Author: WRT_Partisan
* @Date: 2026-06-13 19:41:12
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mid ((l + r) >> 1)
int n, d, s, t, ans, cf[1000005], sum;
signed main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n >> d;
for (int i = 1; i <= n; i++)
{
cin >> s >> t;
if (t - s >= d)
cf[s]++, cf[t - d + 1]--;
}
for (int i = 1; i <= 1000000; i++)
sum += cf[i], ans += sum * (sum - 1) / 2;
cout << ans;
return 0;
}