Codeforces Round #439 (Div. 2)
A. The Artful Expedient
由于 xi⊕yj=xk⟺xk⊕yj=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
向
∑i≤a(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 的矩形,多次操作:
- 在一个矩形外安栅栏
- 拆掉一个安过的栅栏
- 询问两点是否联通
没见过的套路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;
}