Files
python/TangDou/AcWing/SegmentTree/P5490_BF.cpp

34 lines
1.1 KiB
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
/*
通过了 5/10个数据
结果: Memory Limit Exceeded
*/
using namespace std;
const int N = 1e4 + 10; //矩形的数量
int n, sum;
bool p[N][N];
//这里需要估算一下空间,因为int是8个bit,bool是1个bit。
// 1e4*1e4=1e8 100000000 bit/8= 12500000 byte = 12207.03125 kb = 11.920928955078125MB
//模拟,对于(x1,y1)->(x2,y2)内的所有单元格,都标识为已被刷过油漆
//注意一下这里坐标与单元格的映射关系,就把每个单元格的左下角坐标认为是单元格的编号
void paint(int x1, int y1, int x2, int y2) {
for (int i = x1; i < x2; i++)
for (int j = y1; j < y2; j++)
p[i][j] = 1;
}
int main() {
//加快读入
ios::sync_with_stdio(false), cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
paint(x1, y1, x2, y2);
}
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
if (p[i][j]) sum++;
cout << sum << endl;
return 0;
}