Codeforces Round #439 (Div. 2)

Codeforces Round #439 (Div. 2)


A. The Artful Expedient

由于 xiyj=xkxkyj=xi ,所以一定是偶数个。

Karen

B. The Eternal Immortality

差超过5的一定是0,否则暴力就好。

#include <bits/stdc++.h>
using namespace std;

long long a, b;
int main()
{
    cin >> a >> b;
    if (b-a > 20) puts("0");
    else {
        long long ans = 1;
        for (long long i = b; i > a; i--)
            ans = ans*(i%10)%10;
        cout << ans << endl;
    }
    return 0;
}

C. The Intriguing Obsession

三种颜色的岛屿分别有 a,b,c 个,要求连边使得同色两点间距离至少是3,问如何连接。

显然这个要求等价于不能有一个节点连向两个同色节点。考虑分别由 a b a c c b连边。 a b连边为例,则连边方案数是:

ia(ai)(bi)i!

暴力计算即可。

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5005, mod = 998244353;

int C[MAXN][MAXN], fac[MAXN];
int a, b, c;

int main()
{
    scanf("%d%d%d", &a, &b, &c);
    C[0][0] = 1;
    for (int i = 1; i <= 5000; i++)
        for (int j = 0; j <= i; j++)
            C[i][j] = (C[i-1][j]+C[i-1][j-1]*(j!=0))%mod;
    fac[0] = 1;
    for (int i = 1; i <= 5000; i++)
        fac[i] = (long long)fac[i-1]*i%mod;
    int ans[3] = {0, 0, 0};
    for (int i = 0; i <= a; i++) 
        ans[0] = (ans[0]+(long long)C[a][i]*C[b][i]%mod*fac[i]%mod)%mod;
    for (int i = 0; i <= a; i++)
        ans[1] = (ans[1]+(long long)C[a][i]*C[c][i]%mod*fac[i]%mod)%mod;
    for (int i = 0; i <= c; i++)
        ans[2] = (ans[2]+(long long)C[c][i]*C[b][i]%mod*fac[i]%mod)%mod;
    cout << (long long)ans[0]*ans[1]%mod*ans[2]%mod << endl;
    return 0;
}

E. The Untended Antiquity(补)

题意:一个 n×m 的矩形,多次操作:

  1. 在一个矩形外安栅栏
  2. 拆掉一个安过的栅栏
  3. 询问两点是否联通

没见过的套路orz,就是给每个栅栏随机一个权值,然后用二维树状数组大力维护一下,每次安栅栏就给矩形内的点异或一个权值。如果两点权值相等则两点联通。

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2505;

typedef unsigned long long ull;

ull c[MAXN][MAXN];
int n, m, q;

inline int lowbit(int nd)
{ return nd&(-nd); }

struct pt {
    int x1, y1, x2, y2;
    friend bool operator < (const pt &a, const pt &b)
    {
        if (a.x1 != b.x1) return a.x1 < b.x1;
        if (a.y1 != b.y1) return a.y1 < b.y1;
        if (a.x2 != b.x2) return a.x2 < b.x2;
        return a.y2 < b.y2;
    }
};

map<pt, ull> dt;

void modify(int x, int y, ull dt)
{
    for (int i = x; i <= n; i += lowbit(i))
        for (int j = y; j <= m; j += lowbit(j))
            c[i][j] ^= dt;
}

ull sum(int x, int y)
{
    ull ans = 0;
    for (int i = x; i; i -= lowbit(i))
        for (int j = y; j; j -= lowbit(j))
            ans ^= c[i][j];
    return ans;
}

void cover(int x1, int y1, int x2, int y2, ull dt)
{
    modify(x1, y1, dt);
    modify(x1, y2+1, dt);
    modify(x2+1, y1, dt);
    modify(x2+1, y2+1, dt);
}

int main()
{
    srand(time(0));
    scanf("%d%d%d", &n, &m, &q);
    for (int i = 1; i <= q; i++) {
        int t, r1, r2, c1, c2;
        scanf("%d%d%d%d%d", &t, &r1, &c1, &r2, &c2);
        if (t == 1) {
            ull rk = rand()*RAND_MAX+rand();
            // cerr << rk << endl;
            dt[(pt){r1, c1, r2, c2}] = rk;
            cover(r1, c1, r2, c2, rk);
        } else if (t == 2) {
            ull rk = dt[(pt){r1, c1, r2, c2}];
            cover(r1, c1, r2, c2, rk);
        } else {
            if (sum(r1, c1) == sum(r2, c2)) puts("Yes");
            else puts("No");
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值