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

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;
    }
}
  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JorbanS

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值