Old Macdonald wants to build a new hen house for his hens. He buys a new rectangular area of size N by M. The night before he builds the hen house, snake Rana devises an evil plan to plant bombs in K distinct cells in the area to kill the hens and eat them for dinner later.

The morning of, Old Macdonald notices that each of the K cells, where snake Rana planted a bomb, have a marking on them. That won’t stop him though, all he must do is build the hen house in an area with no bombs.

Assume that rows are numbered from top to bottom, and columns are numbered from left to right. Old Macdonald now wants to know the number of ways he can choose sub-rectangles of top left coordinates (x1, y1) and bottom right coordinates (x2, y2) (x1 ≤ x2) (y1 ≤ y2) such that there are no bombs in the sub rectangle.

Input

The first line of input is T – the number of test cases.

The first line of each test case is three integers NM, and K (1 ≤ N, M ≤ 104) (1 ≤ K ≤ 20).

The next K lines each contains distinct pair of integers xy (1 ≤ x ≤ N) (1 ≤ y ≤ M)- where (x, y) is the coordinate of the bomb.

Output

For each test case, output a line containing a single integer - the number of sub-rectangles that don’t contain any bombs.

Example
Input
3
2 2 1
2 2
6 6 2
5 2
2 5
10000 10000 1
1 1
Output
5
257
2500499925000000

题意:
给了一个矩阵,里面有炸弹,求不含炸弹的子矩阵个数。
思路:
状压枚举每种状况,减去奇数个炸弹的情况,加上偶数个炸弹的情况。
计算情况种数的方法,就是计算出与当前点有关的区间重合的左上角和右上角,把左上角和右上角的个数相乘就行了。
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-);
ll ans=;
int x[maxn],y[maxn];
int n,m;
void solve(int p){
int k=;
int maxx=,maxy=;
int minx=inf,miny=inf;
int t=;
while(p){
if(p&){
maxx=max(maxx,x[t]);
maxy=max(maxy,y[t]);
minx=min(minx,x[t]);
miny=min(miny,y[t]);
k++;
}
p>>=;
t++;
}
if(k&){
k=-;
}
else{
k=;
}
ans+=1ll*k*(minx)*miny*(n-maxx+)*(m-maxy+);
} int main()
{
int T;
scanf("%d",&T);
while(T--){
int k;
scanf("%d%d%d",&n,&m,&k);
int tot=<<k;
ans=1ll*n*(n+)*m*(m+)/;
for(int i=;i<=k;i++){
scanf("%d%d",&x[i],&y[i]);
} for(int i=;i<tot;i++){
solve(i);
}
printf("%lld\n",ans);
}
return ;
}

Gym - 101350G Snake Rana(容器原理)的更多相关文章

  1. Gym 101350G - Snake Rana

    题意 有一个n*m的矩形,里面有k个炸弹,给出每个炸弹的坐标,计算在n*m的矩形中有多少子矩形内是不包含炸弹的. 分析 场上很是懵逼,赛后问学长说是容斥定理?一脸懵逼..容斥不是初中奥数用在集合上的东 ...

  2. C++智能指针,指针容器原理及简单实现(auto_ptr,scoped_ptr,ptr_vector).

    目录 C++智能指针,指针容器原理及简单实现(auto_ptr,scoped_ptr,ptr_vector). auto_ptr scoped_ptr ptr_vector C++智能指针,指针容器原 ...

  3. 转 Spring源码剖析——核心IOC容器原理

    Spring源码剖析——核心IOC容器原理 2016年08月05日 15:06:16 阅读数:8312 标签: spring源码ioc编程bean 更多 个人分类: Java https://blog ...

  4. 组队赛Day1第一场 GYM 101350 G - Snake Rana (容斥)

    [题意] 给一个N×M的矩阵, K个地雷的坐标.求不含地雷的所有矩形的总数. T组数据. N M都是1e4,地雷数 K ≤ 20 Input 3 2 2 1 2 2 6 6 2 5 2 2 5 100 ...

  5. 4_9.springboot2.x之使用外置servlet容器原理解析

    问题概述 嵌入式Servlet容器: 应用打成可执行的jar 优点:简单.便携: **缺点:**默认不支持JSP.优化定制比较复杂(使用定制器[ServerProperties.自定义WebServe ...

  6. Gym 100851G Generators (vector+鸽笼原理)

    Problem G. Generators Input file: generators.in Output file: generators.outLittle Roman is studying li ...

  7. 简单解析Spring核心IOC容器原理

    将大体流程解析了一边,具体可以看源代码一个方法一个方法的跟下 XmlBeanFactory的功能是建立在DefaultListableBeanFactory这个基本容器的基础上的,并在这个基本容器的基 ...

  8. 容斥 或者 单调栈 hihocoder #1476 : 矩形计数 和 G. Snake Rana 2017 ACM Arabella Collegiate Programming Contest

    先说一个简单的题目(题目大意自己看去,反正中文):hihocoder上的:http://hihocoder.com/problemset/problem/1476 然后因为这个n和m的矩阵范围是100 ...

  9. C++ 顺序容器原理

    容器分为顺序容器与关联容器,顺序容器也称为序列式容器.序列式容器按元素插入的顺序存储元素,这些元素可以进行排序,但未必是有序的.C++本身内置了一个序列式容器array(数组),STL另外提供了vec ...

随机推荐

  1. Linux定是调用shell脚本删除文件

    编写脚本 vi delbak.sh 代码如下: #!/bin/sh location="/home/mysql/backup/" find $location -mtime +7 ...

  2. Jenkins之Job建立-运行本地脚本

    新建一个自由风格的项目,运行本地脚本 1.点击菜单栏中的“新任务” 2.进入该页面后输入一个项目名称,然后选择“构建一个自由风格的软件项目”,滑动到最底端,点击ok(在左下角) 3.进入下图页面后 “ ...

  3. 转://诊断 Grid Infrastructure 启动问题 (文档 ID 1623340.1) .

    文档内容   用途   适用范围   详细信息   启动顺序:   集群状态   问题 1: OHASD 无法启动   问题 2: OHASD Agents  未启动   问题 3: OCSSD.BI ...

  4. 英特尔关闭PC计算卡项目—插个卡片就能升级个人电脑

    在 2017 年的美国国际消费电子展上,电脑芯片巨头英特尔公司曾经推出一个名为“计算卡”的新产品,相当于把个人电脑的重要零部件整合到了一张信用卡大小的卡片设备中,未来用户升级个人电脑,只需要拔下旧卡片 ...

  5. Hexo + GitEE 搭建、备份、恢复、多终端

    Hexo 是一个快速.简洁且高效的博客框架.Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页. Hexo 是使用的比较多的博客框架了,我也尝试自己搭 ...

  6. 《通过C#学Proto.Actor模型》之Behaviors

    Behaviors就是Actor接收到消息后可以改变处理的方法,相同的Actor,每次调用,转到不同的Actor内方法执行,非常适合按流程进行的场景.Behaviors就通过在Actor内部实例化一个 ...

  7. React-propsType和defaultProps

    TodoItem.propTypes={ content:PropTypes.string, text:PropTypes.string.isRequired, handleDeleteItem:Pr ...

  8. hadoop用户写入文件权限不够的问题

    问题: 普通用户echo写入文件,提示权限不够. 解决方式: sudo tee test.txt <<< "要插入内容"

  9. DEVOPS 运维开发系列

    DEVOPS 运维开发系列四:ITIL事态管理流程.事态监控系统设计以及基于Devops的效率提升实践 - watermelonbig的专栏 - CSDN博客https://blog.csdn.net ...

  10. 6-3 Articles(a, an, some, the)

    1 Definite and Indifinite articles Indefinite articles: a, an, some Definite article:  the 2 a and t ...