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个折扣的时候,你必须 ...
随机推荐
- 【MySQL】mac环境下使用navicat premium连接mysql乱码问题
---恢复内容开始--- 最重要的两点:使用navicat premium创建mysql连接和在mysql连接里面创建数据库时,需要注意. 1.创建连接时,Encoding不需要手动选择,保持Auto ...
- 能力不足之 根据时序图转化为Verilog代码
不能够把时序图看的非常透彻,然后把时序图写成Verilog代码,有时候甚至搞不清楚信号之间的时序关系.
- graph-Dijkstra's shortest-path alogorithm
直接贴代码吧,简明易懂. 后面自己写了测试,输入数据为: a b c d e 0 1 4 0 2 2 1 2 3 1 3 2 1 4 3 2 1 1 2 3 4 2 4 5 4 3 1 也就是课本上1 ...
- 用python编写简易登录接口
需求: 让用户输入用户名密码 认证成功后显示欢迎信息 输错三次后退出程序 可以支持多个用户登录 用户3次认证失败后,退出程序,再次启动程序尝试登陆时,还是锁定状态 下面是我写的代码,如果有BUG或者不 ...
- (转).gitignore详解
本文转自http://sentsin.com/web/666.html 今天讲讲Git中非常重要的一个文件——.gitignore. 首先要强调一点,这个文件的完整文件名就是“.gitignore”, ...
- Developing for nRF52810(转载)
Table of Contents Introduction Hardware emulation of nRF52810 Limitations Software emulation of nRF5 ...
- zoj 4049
Halting Problem Time Limit: 1 Second Memory Limit: 65536 KB In computability theory, the haltin ...
- JAVA获取网络图片并保存到本地(随机图片接口)
import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import j ...
- loj2032 「SDOI2016」游戏
做了 [JSOI2008]Blue Mary开公司 以后发现这 tm 不就是个傻逼树剖+李超线段树吗,做了以后发现我才是傻逼--树剖竟然写错了--这题是我目前写过最长的代码了qwq #include ...
- Html开发小结
html部分 1.html标签 标签不区分大小写. 如:<!doctype html>与<!DOCTYPE html > <div></div>与< ...