cf232E. Quick Tortoise(分治 bitset dp)
题意

Sol
感觉这个思路还是不错的


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 501, SS = 5e6 + 10;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M, Q, ans[SS];
char s[MAXN][MAXN];
bitset<MAXN> f[MAXN][MAXN], g[MAXN][MAXN], Empty;
struct Query {
int x1, y1, x2, y2, id;
}q[SS];
void solve(int l, int r, vector<Query> q) {
if(l > r) return ;
vector<Query> lq, rq;
int mid = l + r >> 1;
//f[i][j]从i,j能到达的mid中的点集
//g[i][j]从mid能到达i, j的点集
for(int i = mid; i >= l; i--) {
for(int j = M; j >= 1; j--) {
f[i][j] = Empty;
if(i == mid) f[i][j][j] = (s[i][j] == '.');
if(i + 1 <= mid && s[i + 1][j] == '.') f[i][j] = f[i][j] | f[i + 1][j];
if(j + 1 <= M && s[i][j + 1] == '.') f[i][j] = f[i][j] | f[i][j + 1];
}
}
for(int i = mid; i <= r; i++) {
for(int j = 1; j <= M; j++) {
g[i][j] = Empty;
if(i == mid) g[i][j][j] = (s[i][j] == '.');
if(i - 1 >= mid && s[i - 1][j] == '.') g[i][j] = g[i][j] | g[i - 1][j];
if(j - 1 >= 1 && s[i][j - 1] == '.') g[i][j] = g[i][j] | g[i][j - 1];
}
}
for(auto &cur : q) {
if(cur.x2 < mid) lq.push_back(cur);
else if(cur.x1 > mid) rq.push_back(cur);
else {
//cout << f[cur.x1][cur.y1] << endl;
//cout << g[cur.x2][cur.y2] << endl;
ans[cur.id] = (f[cur.x1][cur.y1] & g[cur.x2][cur.y2]).count();
}
}
solve(l, mid - 1, lq);
solve(mid + 1, r, rq);
}
int main() {
N = read(); M = read();
for(int i = 1; i <= N; i++) scanf("%s", s[i] + 1);
Q = read();
vector<Query> now;
for(int i = 1; i <= Q; i++) {
q[i].x1 = read(), q[i].y1 = read(), q[i].x2 = read(), q[i].y2 = read(); q[i].id = i;
now.push_back(q[i]);
}
solve(1, N, now);
for(int i = 1; i <= Q; i++) puts(ans[i] ? "Yes" : "No");
return 0;
}
/*
3 3
...
.##
.#.
1
1 1 3 1
3 3
...
.##
.#.
5
1 1 3 3
1 1 1 3
1 1 3 1
1 1 1 2
1 1 2 1
*/
cf232E. Quick Tortoise(分治 bitset dp)的更多相关文章
- [CF232E]Quick Tortoise
题目大意: 给你一个$n\times m(n,m\leq 500)$的格子,有一些是障碍物.从一个格子出发只能向下或向右走,有$q$组询问,每次询问从一个点是否能够到达另一个点. 思路: 分治. 两点 ...
- CF232E Quick Tortoise , Fzoj 3118
这一题由于数据较多,我们考虑离线处理. 分治.对于两个点s,t,如果起点在mid这条横线上方,终点在下方,那么它必定会穿过mid这条线.所以只要s可以到mid上一点x,x可以到t,st就是安全的. 用 ...
- Codeforces 789e The Great Mixing (bitset dp 数学)
Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th typ ...
- 洛谷 P4093 [HEOI2016/TJOI2016]序列 CDQ分治优化DP
洛谷 P4093 [HEOI2016/TJOI2016]序列 CDQ分治优化DP 题目描述 佳媛姐姐过生日的时候,她的小伙伴从某宝上买了一个有趣的玩具送给他. 玩具上有一个数列,数列中某些项的值可能会 ...
- Codeforces 232E - Quick Tortoise bitset+分治
题意: 思路: //By SiriusRen #include <cstdio> #include <bitset> #include <vector> using ...
- CCPC 2016 杭州 E. Master of Subgraph(点分治+bitset优化DP)
题目链接:http://acm.hdu.edu.cn/downloads/CCPC2018-Hangzhou-ProblemSet.pdf 题意:给定一棵有 n 个结点的树和一个数 m,对于 i ∈ ...
- CodeForces 232E.Quick Tortoise
John Doe has a field, which is a rectangular table of size n × m. We assume that the field rows are ...
- [集训队作业2018]蜀道难——TopTree+贪心+树链剖分+链分治+树形DP
题目链接: [集训队作业2018]蜀道难 题目大意:给出一棵$n$个节点的树,要求给每个点赋一个$1\sim n$之内的权值使所有点的权值是$1\sim n$的一个排列,定义一条边的权值为两端点权值差 ...
- 洛谷.3733.[HAOI2017]八纵八横(线性基 线段树分治 bitset)
LOJ 洛谷 最基本的思路同BZOJ2115 Xor,将图中所有环的异或和插入线性基,求一下线性基中数的异或最大值. 用bitset优化一下,暴力的复杂度是\(O(\frac{qmL^2}{w})\) ...
随机推荐
- Nginx 负载均衡和反向代理实践
nginx 以哪个配置文件启动 Nginx 负载均衡和反向代理实践 环境介绍 192.168.1.50 在这台主机上配置Nginx 的反向代理,负载均衡,和web1,web1使用的81号端口 1 ...
- log4j的日志级别(ssm中log4j的配置)
log4j定义了8个级别的log(除去OFF和ALL,可以说分为6个级别),优先级从高到低依次为:OFF.FATAL.ERROR.WARN.INFO.DEBUG.TRACE. ALL. 1. ALL ...
- Go语言学习笔记(1)——Hello World!
第一个go程序——HelloWorld.go 源码 : package main import ("fmt") // import "fmt" func mai ...
- POJ 2578
#include<iostream> #include<stdio.h> #include<vector> using namespace std; int mai ...
- Linux下安装Nginx详细图解教程 (nginx-1.2.6)
什么是Nginx? Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器,在高连接并发的情况下N ...
- 最大子数组问题/Maximum Subarray
问题描述: Find the contiguous subarray within an array (containing at least one number) which has the la ...
- 如何测试你给客户端app开的接口
这里介绍一款工具用于测试后台给客户端开的接口. 采用http或者https 采用表单或者json格式 这款工具之前是谷歌浏览器的一款插件,后来出现了各个平台的客户端.非常实用. 名叫postman 官 ...
- docker cgroup技术之cpu和cpuset
在centos7的/sys/fs/cgroup下面可以看到与cpu相关的有cpu,cpuacct和cpuset 3个subsystem.cpu用于对cpu使用率的划分:cpuset用于设置cpu的亲和 ...
- javascript实现代码高亮-wangHighLighter.js
1. 引言 (先贴出wangHighLighter.js的github地址:https://github.com/wangfupeng1988/wangHighLighter注意,程序和使用说明的更新 ...
- MyCAT 源码解析 —— 分片结果合并(使用unsaferow)
1. 概述 2. 多分片执行 SQL 3. 合并多分片结果 3.1 记录头(header) 3.2 记录行(row) 3.1 AbstractDataNodeMerge 3.2 DataNodeMer ...