2022 China Collegiate Programming Contest (CCPC) Guilin Site(比冠军少9题)

A. Lily

签到,贪心

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < n; i++) {
        if (i == 0 and s[i] == '.' and s[i + 1] != 'L') {
            s[i] = 'C';
        } else if (i == n - 1 and s[i] == '.' and s[i - 1] != 'L') {
            s[i] = 'C';
        } else {
            if (s[i] == '.' and s[i - 1] != 'L' and s[i + 1] != 'L') {
                s[i] = 'C';
            }
        }
    }
    cout << s << '\n';
    return 0;
}

M. Youth Finale

模拟,树状数组,逆序对

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define int long long
const int mod = 10;
template <typename T>
struct Fenwick {
    const int n;
    vector<T> a;
    Fenwick(int n) : n(n), a(n + 1) {}
    void add(int x, T v) {
        for (int i = x; i <= n; i += i & -i) {
            a[i] += v;
        }
    }
    T sum(int x) {
        T ans = 0;
        for (int i = x; i > 0; i -= i & -i) {
            ans += a[i];
        }
        return ans;
    }
    T rangeSum(int l, int r) {
        return sum(r) - sum(l - 1);
    }
    void rangeAdd(int l, int r, T x) {
        add(l, x);
        add(r + 1, -x);
    }
};
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1);
    Fenwick<int> fen(n);
    string s;
    LL cnt = 0, sum = n * (n - 1) / 2, now = 1;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        cnt += i - fen.sum(a[i]) - 1;
        fen.add(a[i], 1);
    }
    cin >> s;
    cout << cnt << '\n';
    bool ok = true;
    for (int i = 0; i < m; i++) {
        if (s[i] == 'S') {
            if (ok) {
                cnt -= 2 * a[now] - 1 - n;
                now++;
                if (now == n + 1) {
                    now = 1;
                }
                cout << cnt % mod;
            } else {
                cnt -= 2 * a[now] - 1 - n;
                now--;
                if (now == 0) {
                    now = n;
                }
                cout << cnt % mod;
            }
        } else {
            if (ok) {
                ok = false;
                cnt = sum - cnt;
                cout << cnt % mod;
                now--;
                if (now == 0) {
                    now = n;
                }
            } else {
                ok = true;
                cnt = sum - cnt;
                cout << cnt % mod;
                now++;
                if (now == n + 1) {
                    now = 1;
                }
            }
        }
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值