Educational Codeforces Round 143

A. Two Towers

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define mp make_pair
using pii = pair<int, int>;
using vi = vector<int>;
constexpr int inf = 1e18;

void solve(){
    int n , m , cnt = 0;
    string a , b;
    cin >> n >> m;
    cin >> a >> b;
    reverse(b.begin(), b.end());
    a += b;
    for( int i = 1 ; i < a.size() ; i ++ )
        cnt += (a[i] == a[i-1]);
    cout << ( cnt <= 1 ? "YES\n" : "NO\n");

}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int t;
    for( cin >> t ; t ; t -- )
        solve();
    return 0;
}

B. Ideal Point

找一下是否存在两个区间的交集只包含\(k\)

#include <bits/stdc++.h>

using namespace std;

#define int long long

using pii = pair<int, int>;
using vi = vector<int>;
#define mp make_pair
constexpr int inf = 1e18;

void solve() {
    int n , k;
    cin >> n >> k;
    vector<pii> e(n);
    for( auto & [l , r ] : e )
        cin >> l >> r;

    for( const auto & [ a , b ] : e )
        for( const auto & [ c , d ] : e ){
            int l = max(a , c ) , r = min( b , d );
            if( l == r and l == k ){
                cout << "YES\n";
                return ;
            }
        }
    cout << "NO\n";
    return;
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int t;
    for (cin >> t; t; t--)
        solve();

    return 0;
}

C. Tea Tasting

对于每一种茶来说,二分的求出能够品尝他的人的区间,然后对这部分人进行区间修改,然后对于边界单独处理一下即可。

#include <bits/stdc++.h>

using namespace std;

#define int long long

using pii = pair<int, int>;
using vi = vector<int>;
#define mp make_pair
constexpr int inf = 1e18;

void solve() {
    int n;
    cin >> n;
    vi a(n + 1), b(n + 1), c(n + 2), d(n + 2);

    for (int i = 1; i <= n; i++) cin >> b[i];
    for (int i = 1; i <= n; i++) cin >> a[i], a[i] += a[i - 1];
    for (int i = 1; i <= n; i++) {
        int l = i, r = n, ans = i - 1;
        for (int mid, t; l <= r;) {
            mid = (l + r) / 2, t = a[mid] - a[i - 1];
            if (t <= b[i]) ans = mid, l = mid + 1;
            else r = mid - 1;
        }
        if (ans >= i) c[i]++, c[ans + 1]--;
        d[ans + 1] += b[i] - a[ans] + a[i - 1];
    }
    for (int i = 1; i <= n; i++) {
        c[i] += c[i-1];
        cout << c[i] * (a[i] - a[i-1] ) + d[i] << " ";
    }
    cout << "\n";



    return;
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int t;
    for (cin >> t; t; t--)
        solve();

    return 0;
}

D. Triangle Coloring

简单带说就是要给边权最大的两条边染上不同颜色,考虑最大值是否相同,可以计算出染色方案数。

然后就是考虑第三个的点的染色方案,因为要保证红蓝数量相同,所以要从环里面选出一半来。

#include <bits/stdc++.h>

using namespace std;

#define int long long

using pii = pair<int, int>;
using vi = vector<int>;
#define mp make_pair
constexpr int inf = 1e18;
constexpr int mod = 998244353;

const int N = 3e5 + 5;
int fact[N], invFact[N];

int power(int x, int y) {
    int ans = 1;
    while (y) {
        if (y & 1) ans = ans * x % mod;
        x = x * x % mod, y >>= 1;
    }
    return ans;
}

int inv(int x) {
    return power(x, mod - 2);
}

int C(int x, int y) {
    return fact[x] * invFact[x - y] % mod * invFact[y] % mod;
}

void solve() {
    int n;
    cin >> n, n /= 3;
    vector<array<int, 3>> e(n);
    for (auto &it: e)
        for (auto &i: it)
            cin >> i;
    int res = 1;
    for (auto &it: e) {
        sort(it.begin(), it.end());
        if (it[0] == it[1] and it[1] == it[2]) res = res * 3 % mod;
        else if (it[0] == it[1]) res = res * 2 % mod;
    }
    res = res * C(n, n / 2) % mod;
    cout << res << "\n";
    return;
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    fact[0] = 1, invFact[0] = inv(1);
    for (int i = 1; i < N; i++)
        fact[i] = fact[i - 1] * i % mod, invFact[i] = inv(fact[i]);
    solve();
    return 0;
}
posted @ 2023-09-19 15:46  PHarr  阅读(3)  评论(0编辑  收藏  举报