Featured image of post Codeforces Round #1008(Div.2)

Codeforces Round #1008(Div.2)

B

题目大意:

数据范围:

思路:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
void solve() {
    int n, k;
    cin >> n >> k;
    vi res(n);
    if (k % 2 == 1) {
        rep(i, 0, n - 2) res[i] = n;
        res[n - 1] = n - 1;
    } else {
        res[n - 2] = n;
        rep(i, 0, n - 1) {
            if (i == n - 2) continue;
            res[i] = n - 1;
        }
    }
    rep(i, 0, n - 1) cout << res[i] << ' ';
    cout << endl;
    return;
}

C

题目大意:

数据范围:

思路:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
void solve() {
    int n;
    cin >> n;
    vl a(2 * n);
    rep(i, 0, 2 * n - 1) cin >> a[i];
    ranges::sort(a);
    ll tem1 = 0;
    ll tem2 = 0;
    rep(i, 0, n - 2) tem2 += 1LL * a[i];
    rep(i, n - 1, 2 * n - 1) tem1 += 1LL * a[i];
    ll tem = tem1 - tem2;
    vl b(2 * n + 1);
    for (int i = 0; i <= 2 * n; i += 2) b[i] = a[2 * n - 1 - i / 2];
    for (int i = 1; i < 2 * n - 1; i += 2) b[i] = a[(i - 1) / 2];
    b[2 * n - 1] = tem;
    for (ll p : b) cout << p << ' ';
    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
28
29
30
31
32
void solve() {
    int n;
    cin >> n;
    vector<pll> ma(n);
    vector<pair<char, char>> op(n);
    rep(i, 0, n - 1) { cin >> op[i].first >> ma[i].first >> op[i].second >> ma[i].second; }
    vector<pll> suf(n + 1);
    suf[n].first = suf[n].second = 1;
    frep(i, n - 1, 0) {
        suf[i] = suf[i + 1];
        if (op[i].first == 'x') suf[i].first += max(suf[i + 1].first, suf[i + 1].second) * (ma[i].first - 1);
        if (op[i].second == 'x') suf[i].second += max(suf[i + 1].first, suf[i + 1].second) * (ma[i].second - 1);
    }
    ll l = 1, r = 1;
    rep(i, 0, n - 1) {
        ll tem = 0;
        if (op[i].first == '+')
            tem += ma[i].first;
        else
            tem += (ma[i].first - 1) * l;
        if (op[i].second == '+')
            tem += ma[i].second;
        else
            tem += (ma[i].second - 1) * r;
        if (suf[i + 1].first >= suf[i + 1].second)
            l += tem;
        else
            r += tem;
    }
    cout << l + r << endl;
    return;
}

E

题目大意:

数据范围:

思路:

 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const int tem1 = 715827882;
const int tem2 = 357913941;
ll ask(ll l) {
    cout << l << '\n';
    cout.flush();
    ll op;
    cin >> op;
    return op;
}
ll report() {
    cout << "! " << '\n';
    cout.flush();
    ll op;
    cin >> op;
    return op;
}
void report2(ll x) {
    cout << x << '\n';
    cout.flush();
}
void solve() {
    ll tem3 = ask(tem1);
    tem3 -= 2 * tem1;
    ll tem4 = ask(tem2);
    tem4 -= 2 * tem2;
    ll m = report();
    ll x = 0, y = 0;
    for (int i = 0; i < 30; i += 2) {
        if ((tem3 >> i) & 1)
            x |= (1LL << i);
        else if ((tem3 >> (i + 1)) & 1)
            x |= (1LL << i), y |= (1LL << i);
    }
    for (int i = 1; i < 30; i += 2) {
        if ((tem4 >> i) & 1)
            x |= (1LL << i);
        else if ((tem4 >> (i + 1)) & 1)
            x |= (1LL << i), y |= (1LL << i);
    }
    report2((x | m) + (y | m));
    return;
}

F

题目大意:

数据范围:

思路:

 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
28
29
30
31
32
const ll MOD = 998244353;
ll mul(ll x, ll y) { return x * y % MOD; }
ll qpow(ll x, ll y) {
    ll z = 1;
    while (y > 0) {
        if (y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}  // 求x**y%MOD

// 注意:当MOD为质数时, (x/y)%MOD=(x*(y**(MOD-2)))%MOD,即y在模MOD意义下的逆元为b^{-1} \equiv b^{p-2} mod p

void solve() {
    int n, q, x;
    cin >> n >> q;
    string s;
    cin >> s;
    ll tot = 0;
    rep(i, 0, n - 1) tot += (s[i] == '1' ? 1 : -1);
    rep(i, 0, q - 1) {
        cin >> x;
        x--;
        tot -= (s[x] == '1' ? 2 : -2);
        s[x] = (s[x] == '1' ? '0' : '1');
        cout << (n <= 4 ? qpow((1 << (4 - n)), MOD - 2) * (tot * tot % MOD + n - 2 + MOD) % MOD
                        : qpow(2, n - 4) * (tot * tot % MOD + n - 2 + MOD) % MOD)
             << endl;
    }
    return;
}