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 ;
}

最新文章

  1. jQuery $(document).ready()和JavaScript onload事件
  2. 在执行Action之间检验是否登录
  3. [Guava源码分析]Objects 和 ComparisonChain:帮助重写Object方法
  4. ACM——圆柱体的表面积
  5. 《IT运维之道》
  6. 请描述一下 cookies,sessionStorage 和 localStorage 的区别?
  7. wcf简单的创建和运用
  8. RMAN数据库恢复之对数据库进行完全介质恢复
  9. BZOJ 1660: [Usaco2006 Nov]Bad Hair Day 乱发节( 单调栈 )
  10. [Ext JS 4]性能优化
  11. Scrapy爬虫框架补充内容三(代理及其基本原理介绍)
  12. c语言的一些易错知识积累
  13. 《深入理解Java虚拟机》(三)垃圾收集器与内存分配策略
  14. JXS In Depth
  15. JPA Annotation注解
  16. Androoid studio 2.3 AAPT err(Facade for 596378712): \\?\C:\Users\中文文件夹\.android\build-cache
  17. linux系统分区参考
  18. easy UI动态赋值
  19. ACM-ICPC 2018 焦作赛区网络预赛 E. Jiu Yuan Wants to Eat (树链剖分-线性变换线段树)
  20. Redis四(Set操作)

热门文章

  1. Gym - 101810E ACM International Collegiate Programming Contest (2018)
  2. 洛谷P3603 || bzoj 4763 雪辉 &amp;&amp; bzoj4812: [Ynoi2017]由乃打扑克
  3. python学习之图形界面编程:
  4. Unity AssetBundle笔记
  5. node项目 Error: Cannot find module &#39;mongoose&#39;
  6. [转]Android应用自动更新功能的代码实现
  7. 向fedora添加rpmfusion源
  8. .aspx设置跨域
  9. LookAround开元之旅(持续更新中...)
  10. tomcat配置 —— 各个目录的作用