Featured image of post Codeforces Round #1066(Div.1+2)

Codeforces Round #1066(Div.1+2)

B

题目大意:

数据范围:

思路:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void solve() {
    int n;
    ll x, y;
    cin >> n >> x >> y;
    x = abs(x), y = abs(y);
    string s;
    cin >> s;
    ll tem1 = 0, tem2 = 0;
    ll res1 = x + y, res2 = x - y;
    int tot1 = 0, tot2 = 0;
    rep(i, 0, n - 1) {
        if (s[i] == '4') {
            tot1++;
        } else {
            tot2++;
        }
    }
    if (tot1 + tot2 >= max(x, y) && x + y <= tot1 + 2 * tot2) {
        cout << "YES" << endl;
        return;
    }
    cout << "NO" << endl;
    return;
}

C

题目大意:

数据范围:

思路:

 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
void solve() {
    int n, k, q;
    int c, l, r;
    cin >> n >> k >> q;
    vector<set<int>> ma(n);
    vi a(n, 1e9);
    rep(i, 0, q - 1) {
        cin >> c >> l >> r;
        l--, r--;
        rep(j, l, r) ma[j].insert(c);
    }
    int cnt = 0;
    rep(i, 0, n - 1) {
        if (ma[i].count(1) && !ma[i].count(2)) {
            a[i] = k;
        }
        if (!ma[i].count(1) && ma[i].count(2)) {
            a[i] = cnt;
            cnt = (cnt + 1) % k;
        }
    }
    rep(i, 0, n - 1) cout << a[i] << ' ';
    cout << endl;
    return;
}

D

题目大意:

数据范围:

思路:

 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
void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vl a(n);
    rep(i, 0, n - 1) cin >> a[i];
    ranges::sort(a);
    vl pre(n);
    vl suf(n + 1);
    pre[0] = a[0];
    suf[n - 1] = a[n - 1];
    rep(i, 1, n - 1) pre[i] = pre[i - 1] + a[i];
    frep(i, n - 2, 0) suf[i] = suf[i + 1] + a[i];
    ll ans = 0;
    // 枚举选择a[i]-p的数量
    // 假设a[i]-p的数量为y,p-a[i]的数量为x
    // 当y>=x时,p应该取l
    // 当y<x时,p应该取r
    rep(i, 0, n - 1) {
        if (a[i] < l) ans += l - a[i], a[i] = l;
        if (a[i] > r) ans += a[i] - r, a[i] = r;
    }
    for (int i = 0, j = n - 1; i < j; i++, j--) {
        ans += a[j] - a[i];
    }
    cout << ans << endl;
    return;
}