Codeforces Round #754 (Div. 2)E 待写

Posted Newuser233

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #754 (Div. 2)E 待写相关的知识,希望对你有一定的参考价值。

待写

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
int n;
int a[maxn], b[maxn];
ll qz[maxn], qzh[maxn], tot;
ll c[maxn], mob[maxn];
int pri[maxn], cnt;
bool nop[maxn];
void init() {
    nop[1] = 1;
    mob[1] = 1;
    for (int i = 2; i <= n; i++) {
        if (!nop[i]) {
            pri[++cnt] = i;
            mob[i] = -1;
        }
        for (int j = 1; j <= cnt && 1ll * i * pri[j] <= n; j++) {
            nop[i * pri[j]] = 1;
            if (i % pri[j] == 0)
                break;
            mob[i * pri[j]] = -mob[i];
        }
    }
}
ll sum(int l, int r) {
    if (l > r)
        return 0;
    return qzh[r] - qzh[l - 1];
}
int main() {
    scanf("%d", &n);
    init();
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n; i++) {
        scanf("%d", &b[i]);
    }
    for (int i = 1; i <= n; i++)
        c[i] = b[i] - a[i];
    c[1] = 0;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = i + i; j <= n; j += i) {
            c[j] -= c[i];
        }
    }
    for (int i = 1; i <= n; i++) {
        if (mob[i] == 0)
            ans += llabs(c[i]);
        else if (mob[i] == -1)
            qz[++tot] = -c[i];
        else
            qz[++tot] = c[i];
    }
    sort(qz + 1, qz + 1 + tot);
    for (int i = 1; i <= tot + 1; i++)
        qzh[i] = qzh[i - 1] + qz[i];
    int q;
    scanf("%d", &q);
    while (q--) {
        int x;
        scanf("%d", &x);
        x -= a[1];
        int wz = lower_bound(qz + 1, qz + 1 + tot, -x) - qz;
        ll nans = sum(wz, tot) + 1ll * (tot - wz + 1) * x;
        nans -= sum(1, wz - 1) + 1ll * (wz - 1) * x;
        printf("%lld\\n", ans + nans);
    }
    return 0;
}

以上是关于Codeforces Round #754 (Div. 2)E 待写的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #754 (Div. 2) C

Codeforces Round #436 E. Fire(背包dp+输出路径)

[ACM]Codeforces Round #534 (Div. 2)

Codeforces 754E:Dasha and cyclic table

CodeForces - 754D

Codeforces Round #726 (Div. 2) B. Bad Boy(贪心)