ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall
Feeling hungry, a cute hamster decides to order some take-away food (like fried chicken for only 3030 Yuan).
However, his owner CXY thinks that take-away food is unhealthy and expensive. So she demands her hamster to fulfill a mission before ordering the take-away food. Then she brings the hamster to a wall.
The wall is covered by square ceramic tiles, which can be regarded as a n * mn∗m grid. CXY wants her hamster to calculate the number of rectangles composed of these tiles.
For example, the following 3 * 33∗3 wall contains 3636 rectangles:
Such problem is quite easy for little hamster to solve, and he quickly manages to get the answer.
Seeing this, the evil girl CXY picks up a brush and paint some tiles into black, claiming that only those rectangles which don't contain any black tiles are valid and the poor hamster should only calculate the number of the valid rectangles. Now the hamster feels the problem is too difficult for him to solve, so he decides to turn to your help. Please help this little hamster solve the problem so that he can enjoy his favorite fried chicken.
Input
There are multiple test cases in the input data.
The first line contains a integer TT : number of test cases. T \le 5T≤5.
For each test case, the first line contains 33 integers n , m , kn,m,k , denoting that the wall is a n \times mn×m grid, and the number of the black tiles is kk.
For the next kk lines, each line contains 22 integers: x\ yx y ,denoting a black tile is on the xx-th row and yy-th column. It's guaranteed that all the positions of the black tiles are distinct.
For all the test cases,
1 \le n \le 10^5,1\le m \le 1001≤n≤105,1≤m≤100,
0 \le k \le 10^5 , 1 \le x \le n, 1 \le y \le m0≤k≤105,1≤x≤n,1≤y≤m.
It's guaranteed that at most 22 test cases satisfy that n \ge 20000n≥20000.
Output
For each test case, print "Case #xx: ansans" (without quotes) in a single line, where xx is the test case number and ansans is the answer for this test case.
Hint
The second test case looks as follows:
样例输入
2 3 3 0 3 3 1 2 2
样例输出
Case #1: 36 Case #2: 20
题目来源
//
题意:
给你一个n*m(1e5*100)的矩阵和k(1e5)个黑点,问有多少个不含这些黑点的子矩形。
(4,5)作为矩形的右下角时,j==5 (4-2),j==4(4-2),j==3(4-3),j==2(4-3),j==1(4-3)
//暴力 #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <utility> #include <algorithm> #include <vector> #include <queue> #include <stack> using namespace std; #define N 100009 #define M 200009 #define lowbit(x) x&(-x) #define ll long long const ll inf =9e18; int t,n,m,k; int x,y; int mp[150],vis[N][150]; int main() { scanf("%d",&t); for(int f=1;f<=t;f++) { for(int i=1;i<=N;i++) { for(int j=1;j<=100;j++){ vis[i][j]=0; } } scanf("%d%d%d",&n,&m,&k); for(int i=0;i<k;i++) { scanf("%d%d",&x,&y); vis[x][y]=1; } ll ans=0; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++){ if(vis[i][j]){ mp[j]=i;//到第i行为止,该列的黑快的最大纵坐标 } } for(int j=1;j<=m;j++) { int maxx=0; for(int k=j;k>=1;k--) { maxx=max(maxx,mp[k]);//前面maxx行是不行的,因为有黑快 ans+=(ll)(i-maxx);//仅针对第k列,以(i,j)为纵坐标时的子矩形数目 } } } printf("Case #%d: %lld\n",f,ans); } return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现