Codeforces Round 924 (Div. 2) 题解 A~D | JorbanS

A - Recovering a Small String

string solve() {
    cin >> n >> m;
    if (n < m) swap(n, m);
    if (n & 1 && m & 1) return no;
    if (m & 1 && n == m << 1) return no;
    return yes;
}

B - Make Equal

由于排列 1 ∼ n 1\sim n 1n 均不一样,故先对原数组排序并去重

所给数组范围明显大于 n n n,容易想到用区间长度为 n n n 的去匹配数组 a a a,故而用二分确定端点,故只要对每个左端点 l l l,二分出 r r r,取最大值即可

int solve() {
    cin >> n;
    set<int> s;
    for (int i = 0; i < n; i ++) {
        int x; cin >> x;
        s.insert(x);
    }
    vector<int> a;
    for (auto i : s) a.emplace_back(i);
    int res = 0;
    for (int i = 0; i < a.size(); i ++) {
        int t = upper_bound(a.begin() + i, a.end(), a[i] + n - 1) - a.begin() - i;
        res = max(res, t);
    }
    return res;
}

C - Make Equal Again

易得 2 k − 2 ∣ n − x 2k-2|n-x 2k2∣nx 2 k − 2 ∣ n + x − 2 2k-2|n+x-2 2k2∣n+x2,直接暴力求约数即可

set<int> s;

void cal(int n) {
    if (n & 1) return;
    n >>= 1;
    for (int i = 1; i <= n / i; i ++)
        if (n % i == 0) {
            int a = i, b = n / i;
            if (a + 1 >= x) s.insert(a);
            if (b + 1 >= x) s.insert(b);
        }
}

int solve() {
    cin >> n >> x;
    s.clear();
    cal(n - x);
    cal(n + x - 2);
    return s.size();
}

D - Divisible Pairs

结果具备单峰性,三分即可,赛时漏了个 b b b,小丑了(

ll cal(int t) {
    ll res = -(ll)(t - 1) * x;
    for (int i = 0; i < n; i ++) {
        int p = a[i] / t, q = (a[i] + t - 1) / t;
        int nq = a[i] % t, np = t - nq;
        res += (ll)p * np * (a[i] - p) / 2 * b;
        res += (ll)q * nq * (a[i] - q) / 2 * b;
    }
    return res;
}

ll solve() {
    cin >> n >> b >> x;
    for (int i = 0; i < n; i ++) cin >> a[i];
    int l = 1, r = 2e5;
    while (l + 2 < r) {
        int L = (l * 2 + r) / 3;
        int R = (l + r * 2) / 3;
        if (cal(L) >= cal(R)) r = R;
        else l = L;
    }
    return max(cal(l), max(cal(r), cal(l + 1)));
}
  • 22
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
抱歉,根据提供的引用内容,我无法理解你具体想要问什么问题。请提供更清晰明确的问题,我将竭诚为你解答。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [【CodeforcesCodeforces Round 865 (Div. 2) (补赛)](https://blog.csdn.net/t_mod/article/details/130104033)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JorbanS

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值