Educational Codeforces Round 161 (Rated for Div. 2) | JorbanS

发布时间:2024年01月20日

A - Tricky Template

string solve() {
    cin >> n >> a >> b >> c;
    if (a == c || b == c) return no;
    for (int i = 0; i < n; i ++) {
        if (a[i] == b[i]) {
            if (a[i] != c[i]) return yes;
        } else {
            if (a[i] != c[i] && b[i] != c[i]) return yes;
        }
    }
    return no;
}

B - Forming Triangles

ll C2(ll x) { return x * (x - 1) / 2; }
ll C3(ll x) { return x * (x - 1) * (x - 2) / 6; }
 
ll solve() {
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i ++) {
        int x; cin >> x;
        mp[x] ++;
    }
    ll res = 0, cnt = 0;
    for (auto [x, y]: mp) {
        if (y >= 2) res += C2(y) * cnt;
        if (y >= 3) res += C3(y);
        cnt += y;
    }
    return res;
}

C - Closest Cities

前缀和

int n, m;
int a[N];
int l[N], r[N];
int L[N], R[N];
 
void solve() {
    cin >> n;
    for (int i = 1; i <= n; i ++) cin >> a[i];
    L[n + 1] = 0;
    r[1] = l[n] = 1;
    for (int i = 2; i <= n - 1; i ++) {
        l[i] = abs(a[i] - a[i - 1]);
        r[i] = abs(a[i] - a[i + 1]);
        if (l[i] < r[i]) l[i] = 1;
        else r[i] = 1;
    }
    for (int i = 1; i <= n; i ++) R[i] = R[i - 1] + r[i];
    for (int i = n; i >= 1; i --) L[i] = L[i + 1] + l[i];
    cin >> m;
    while (m --) {
        int x, y; cin >> x >> y;
        if (x < y) cout << R[y - 1] - R[x - 1] << endl;
        else cout << L[y + 1] - L[x + 1] << endl;
    }
}
文章来源:https://blog.csdn.net/qq_40179418/article/details/135712286
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。