CSP ?- Round 8 总结 2026.10.19
summer0703 · · 个人记录
CSP-S Round x 模拟赛总结
比赛基本信息
- 比赛日期:2026.10.19
- 比赛时长:
4 \ h - 比赛得分:
140 - 比赛排名:
\operatorname{rk}4
比赛整体回顾
这次我按照
题目解法
A题
这个题我们先考虑
考虑枚举当前
这样我们就得到了一个
考虑优化。
我们注意到可以一开始将这些
这样就是一个二分板子,然而这道题里面由于
set 是不够的,这个操作其实本质上是平衡树的板子题,然而这可是第一题啊,不应该用这么超标的算法.我们注意到
时间复杂度
B题
这道题正着做比较困难,我们考虑反过来,将
对于
对于负数,其可能存在循环,当然,如果存在循环,至少在题目数据范围中,
单独特判一下即可。
由于
时间复杂度
C题
我们考虑
由于
时间复杂度
D题
我们首先考虑暴力。
先将
然后我们枚举当前的
这还不够优秀,我们考虑优化:
首先令
我们预处理出
令
然后靠率现在的
我们回代式子,对于每一种质因数,答案是这些数除以对应
最后只剩下一个问题:当
我们在上面是直接令
于是我们要维护一个单点赋值、全局最小值的线段树,整体时间复杂度
#include<bits/stdc++.h>
#define pre(i, l, r) for(int i = (l); i <= (r); ++i)
#define fpre(i, r, l) for(int i = (r); i >= (l); --i)
#define ll long long
using namespace std;
const int maxn = 1.2e6 + 5;
const int inf = 1e9;
const ll lnf = 2e18;
int n;
int a[maxn], c[maxn];
int p[maxn];
ll f[maxn], h[maxn];
const int L = 3e5 + 6;
struct Node
{
ll val;
Node(ll val = lnf) : val(val) {}
};
Node t[maxn];
Node operator + (const Node&x, const Node&y)
{
Node ans;
ans.val = min(x.val, y.val);
return ans;
}
void push_up(int p)
{
t[p] = t[p << 1] + t[p << 1 | 1];
}
void update(int p, int s, int t, int k, ll c)
{
if(s == t)
{
::t[p] = Node(c);
return;
}
int mid = (s + t) / 2;
if(k <= mid)
update(p << 1, s, mid, k, c);
if(k > mid)
update(p << 1 | 1, mid + 1, t, k, c);
push_up(p);
}
int main()
{
freopen("secure.in", "r", stdin);
freopen("secure.out", "w", stdout);
scanf("%d", &n);
pre(i, 1, n)
scanf("%d", &a[i]);
if(*max_element(a + 1, a + n + 1) == 1)
{
puts("0");
return 0;
}
pre(i, 2, L)
if(!p[i])
{
p[i] = i;
for(ll j = (ll)i * i;j <= L;j += i)
p[j] = i;
}
pre(i, 1, n) c[a[i]]++;
fpre(i, L, 1) c[i] += c[i + 1];
pre(i, 2, L)
{
int x = i;
while(x > 1)
{
int y = p[x], e = 0;
while(x > 1 && p[x] == y)
x /= y, ++e;
f[y] += e;
h[y] += (ll)c[i] * e;
}
}
pre(i, 2, L)
if(p[i] == i)
update(1, 0, L, i, h[i] / f[i]);
vector<pair<int,ll>> ans;
ll tag = 0;
fpre(i, L, 2)
{
ll c = t[1].val - tag;
if(c > 0)
{
ans.emplace_back(i, c);
tag += c;
}
int x = i;
while(x > 1)
{
int y = p[x], e = 0;
while(x > 1 && p[x] == y)
x /= y, ++e;
f[y] -= e;
h[y] -= tag * e;
update(1, 0, L, y, (f[y] ? h[y] / f[y] : lnf));
}
}
printf("%d\n", ans.size());
for(auto y : ans)
printf("%d %lld\n", y.first, y.second);
return 0;
}
怎么还有zkw()
666码字就算了怎么还有这么多
\KaTeX