G. Snake Rana
time limit per test

4.0 s

memory limit per test

256 MB

input

standard input

output

standard output

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

Copy
3
2 2 1
2 2
6 6 2
5 2
2 5
10000 10000 1
1 1
output

Copy
5
257
2500499925000000
 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <set>
#include <queue>
using namespace std;
#define ll long long
#define N 10009
#define gep(i,a,b) for(int i=a;i<=b;i++)
#define gepp(i,a,b) for(int i=a;i>=b;i--)
#define gep1(i,a,b) for(ll i=a;i<=b;i++)
#define gepp1(i,a,b) for(ll i=a;i>=b;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define P pair<int,int>
#define inf 10000009
struct Node{
ll x,y;
}node[];
int main()
{
int t,k;
ll n,m;
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld%d",&n,&m,&k);//开始时k %lld ,t直接变为0了
ll ans=n*(n+)/*m*(m+)/;
//一共ans个,要在减去含有炸弹的,容斥定理
//含有炸弹的=仅含有一个的-含有两个的+含有三个的-……
/*
要计算几个集合并集的大小,我们要先将所有单个集合的大小
计算出来,然后减去所有两个集合相交的部分,
再加回所有三个集合相交的部分,
再减去所有四个集合相交的部分,依此类推,
一直计算到所有集合相交的部分。
*/
gep(i,,k-){
scanf("%lld %lld",&node[i].x,&node[i].y);
}
for(int i=;i<(<<k);i++)//二进制枚举所有的情况
{
ll m1=inf,m2=inf,m3=-,m4=-;
int cnt=;
gep(j,,k-){
if(i>>j&){//i的j位是1吗
m1=min(m1,node[j].x);
m2=min(m2,node[j].y);
m3=max(m3,node[j].x);
m4=max(m4,node[j].y);
cnt++;//有几个炸弹
}
}
//m1 :横坐标的最小值 m2 :纵坐标的最小值
//m3 :横坐标的最大值 m4 :纵坐标的最大值
//一个矩形由左上角 和右下角 决定
//m1*m2 左上的位置数 ,(n-m3+1)*(m-m4+1):右下的位置数
ll ret=m1*m2*(n-m3+)*(m-m4+);
if(cnt&) ans-=ret;
else ans+=ret;
}
printf("%lld\n",ans);
}
return ;
}

GYM 101350 G的更多相关文章

  1. 组队赛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 ...

  2. [codeforces/gym/101350/L]维护“凸包”

    题目链接:http://codeforces.com/gym/101350/problems 给定n个墙,每个墙有一个高度,要支持动态修改墙的高度和查询这个“容器”能盛多少水. (队友)观察发现,能盛 ...

  3. Codeforces Gym 100513G G. FacePalm Accounting

    G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...

  4. Codeforces Gym 100637G G. #TheDress 暴力

    G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...

  5. Codeforces Gym 100513G G. FacePalm Accounting 暴力

    G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...

  6. Gym - 101147G G - The Galactic Olympics —— 组合数学 - 第二类斯特林数

    题目链接:http://codeforces.com/gym/101147/problem/G G. The Galactic Olympics time limit per test 2.0 s m ...

  7. Gym 100952 G. The jar of divisors

    http://codeforces.com/gym/100952/problem/G G. The jar of divisors time limit per test 2 seconds memo ...

  8. Codeforces Gym 100203G G - Good elements 标记暴力

    G - Good elementsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  9. Codeforces Gym 100203G G - Good elements 暴力

    G - Good elementsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

随机推荐

  1. 洛谷 P2662 牛场围栏

    做法是这样的: 首先暴力把所有可能的边长搞出来..(当然<=0的不要) 排序边长+去重, 当且仅当可行边长里面有1时,任何长度都能取到,输出-1 当且仅当所有可行边长的gcd大于1时,不能取到的 ...

  2. 081 Search in Rotated Sorted Array II 搜索旋转排序数组 ||

    这是 “搜索旋转排序数组”问题的跟进:如果数组元素允许重复,怎么办?这会影响到程序的时间复杂度吗?会有怎样的影响,为什么?假设按照升序排序的数组在预先未知的某个关键点上旋转.(例如, 0 1 2 4 ...

  3. Django 的简单ajax

    需要通过ajax实现局部刷新 js代码 $('#guo-sou-ajax').click(function(){ #获取id为guo-sou-ajax点击后的信号 console.log($(this ...

  4. 牛客网Java刷题知识点之什么是JSP的3大常用指令、JSP的6大哪些动作、JSP中include指令和include动作有什么区别

    不多说,直接上干货! JSP的3大常用指令 包含指令(Include directive):用来包含文件和合并文件内容到当前的页面. 页面指令(Page directive):用来定义JSP页面中特定 ...

  5. pc端_移动端_H5_ QQ在线客服链接代码

    PC端:QQ在线客服链接代码 <a href="tencent://message/?uin=1239300678&Site=sc.chinaz.com&Menu=ye ...

  6. linux各文件夹的作用(转)

    转自:http://www.cnblogs.com/amboyna/archive/2008/02/16/1070474.html linux下的文件结构,看看每个文件夹都是干吗用的/bin 二进制可 ...

  7. 大数据freestyle: 共享单车轨迹数据助力城市合理规划自行车道

    编者按:近年来,异军突起的共享单车极大地解决了人们共同面临的“最后一公里”难题,然而,共享单车发展迅猛,自行车道建设却始终没有能够跟上脚步.幸运的是摩拜单车大量的轨迹数据为我们提供了一种新的思路:利用 ...

  8. Webpack2 视频教程

      原文发表于我的技术博客 这是我免费发布的高质量超清「Webpack 2 视频教程」.Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本 ...

  9. Base64编码密钥时关于换行的几个问题。

    在windows下一个javaweb应用,需要用http传递公钥pk.一般是String pk = BASE64ENCODER.encode(pkBytes);base64编码时,每76个字母就要换行 ...

  10. VM虚拟机下的Linux不能上网

    虚拟机linux上网配置 图解教程 首先查看window7主机下的网络配置VMNet1或VMNet8是否开启,其实linux系统的网络连接跟linux系统一致 在虚拟机界面将桥接改为NAT连接 点虚拟 ...