Codeforces Round #439 (Div. 2) 题解
题目链接 Round 439 div2
就做了两道题TAT
开场看C题就不会
然后想了好久才想到。
三种颜色挑出两种算方案数其实是独立的,于是就可以乘起来了。
E题想了一会有了思路,然后YY出了一种方案。
我们可以对每个矩形随机一个权值,然后用二维树状数组搞下。
询问的时候看两个点权值是否相等就可以了
于是就过了。
D题待补
给出一棵完全二叉树,这棵树上有附带的m条边(m <= 4),求这张图的简单路径条数。
qls的题就是厉害……
C题
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair
#define fi first
#define se second typedef long long LL; const int N = 5010; const int mod = 998244353; int P[N][N], C[N][N];
int a, b, c; int calc(int x, int y){
if (x > y) swap(x, y);
LL ret = 0;
rep(i, 0, x) ret = (ret + 1ll * P[y][i] * C[x][i]) % mod;
return ret;
} int main(){ C[0][0] = P[0][0] = 1;
scanf("%d%d%d", &a, &b, &c); rep(i, 1, 5000){
C[i][0] = P[i][0] = 1;
rep(j, 1, i){
P[i][j] = (1ll * P[i - 1][j - 1] * j % mod + 1ll * P[i - 1][j] % mod) % mod;
C[i][j] = (1ll * C[i - 1][j - 1] + 1ll * C[i - 1][j]) % mod;
}
} int ans = 1ll * calc(a, b) % mod * 1ll * calc(b, c) % mod * 1ll * calc(a, c) % mod;
printf("%d\n", ans);
return 0;
}
E题
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define MP make_pair typedef long long LL;
typedef pair <int, int> PII; const LL mod = 1e9 + 7;
const int N = 5010; map <PII, LL> mp; int cnt = 0;
int n, m, q;
int p[N][N];
LL c[N][N]; inline void add(int x, int y, LL val){
for (; x <= n; x += x & -x){
for (int t = y; t <= m; t += t & -t){
c[x][t] = (c[x][t] + val) % mod;
c[x][t] = (c[x][t] + mod) % mod;
}
}
} inline LL query(int x, int y){
LL ret = 0;
for (; x ; x -= x & -x){
for (int t = y; t ; t -= t & -t){
(ret += c[x][t]) %= mod;
}
} return ret;
} inline LL solve(int x, int y){
LL ret = query(x, y) % mod;
return ret;
} int main(){ scanf("%d%d%d", &n, &m, &q);
rep(i, 1, n) rep(j, 1, m) p[i][j] = ++cnt; rep(i, 1, q){
int op;
scanf("%d", &op);
if (op == 1){
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
if (x1 > x2) swap(x1, x2);
if (y1 > y2) swap(y1, y2);
LL cnt = (LL)rand() * (LL)rand() * (LL)rand() % mod;
mp[MP(p[x1][y1], p[x2][y2])] = cnt; add(x1, y1, cnt);
add(x1, y2 + 1, -cnt);
add(x2 + 1, y1, -cnt);
add(x2 + 1, y2 + 1, cnt);
} else if (op == 2){
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
if (x1 > x2) swap(x1, x2);
if (y1 > y2) swap(y1, y2);
LL cnt = mp[MP(p[x1][y1], p[x2][y2])];
add(x1, y1, -cnt);
add(x1, y2 + 1, cnt);
add(x2 + 1, y1, cnt);
add(x2 + 1, y2 + 1, -cnt);
} else{
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
LL xx = solve(x1, y1);
LL yy = solve(x2, y2);
if (xx == yy) puts("Yes");
else puts("No");
} } return 0;
}
Codeforces Round #439 (Div. 2) 题解的更多相关文章
- Codeforces Round #439 (Div. 2)【A、B、C、E】
Codeforces Round #439 (Div. 2) codeforces 869 A. The Artful Expedient 看不透( #include<cstdio> in ...
- Codeforces Round #182 (Div. 1)题解【ABCD】
Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...
- Codeforces Round #608 (Div. 2) 题解
目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...
- Codeforces Round #525 (Div. 2)题解
Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...
- Codeforces Round #528 (Div. 2)题解
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
- Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F
Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...
- Codeforces Round #677 (Div. 3) 题解
Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...
- Codeforces Round #665 (Div. 2) 题解
Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...
- Codeforces Round #160 (Div. 1) 题解【ABCD】
Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...
随机推荐
- GoogleTest 之路3-Mocking Framework
当你写一个原型或者测试的时候,依赖整个object 是不可行和明智的.一个 mock object和 real object 有同样的接口(所以它可以像同一个使用),但是让你在运行时进行指定它应该如何 ...
- 8.Yii2.0框架控制器接收get.post数据
8.Yii2.0框架控制器接收get.post数据 一.get传参 <?php /** * Created by Haima. * Author:Haima * QQ:228654416 * D ...
- and和or运算
and和or的运算,从前向后按顺序计算,当True结果遇到or就停止,返回True:当False结果遇到and就停止,返回False:False遇到or,继续走:True遇到and,继续走. > ...
- FIFO buffer 和普通buffer区别
1.FIFO可以说一块具体的硬件存储设备,也可以说程序在内存中开辟的一段内存区域.而buffer往往就是一段缓冲的数据区域 2.FIFO的数据是先进先出的,而buffer没有这个限制,可以全局访问 3 ...
- Java学习——面对对象的思想入门
本文是看过<head first Java>之后的一点感悟,写点东西帮忙以后回忆,Java目前在我的工作中用到还不多,而我又对面对对象的编程非常的感兴趣.曾经在MFC平台上写过 ...
- LA 7056 Colorful Toy Polya定理
题意: 平面上给出一个\(N\)个点\(M\)条边的无向图,要用\(C\)种颜色去给每个顶点染色. 如果一种染色方案可以旋转得到另一种染色方案,那么说明这两种染色方案是等价的. 求所有染色方案数 \( ...
- python基础学习笔记——单继承
1.为什么要有类的继承性?(继承性的好处)继承性的好处:①减少了代码的冗余,提供了代码的复用性②提高了程序的扩展性 ③(类与类之间产生了联系)为多态的使用提供了前提2.类继承性的格式:单继承和多继承# ...
- DS博客作业06--图
1.本周学习总结 1.1.思维导图 1.2.谈谈你对图结构的认识及学习体会 本章学习了图结构的相关知识,图形结构属于复杂的非线性数据结构,在实际应用中很多问题可以用图来描述.在图结构中,每个元素可以有 ...
- git如何忽略文件或者文件夹
用git开发中会有一些不愿意提交的目录或者文件 在仓库目录下新建一个名为.gitignore的文件(因为是点开头,没有文件名,没办法直接在windows目录下直接创建,必须通过右键Git Bash,按 ...
- JDBC 学习笔记(一)—— JDBC 基础
1. 什么是 JDBC JDBC,Java Database Connectivity(Java 数据库连接),是一组执行 SQL 语句的 Java API. JDBC,是 Java SE(Java ...