比赛 |
2025.3.6 |
评测结果 |
AAAAA |
题目名称 |
矩形周长 |
最终得分 |
100 |
用户昵称 |
健康铀 |
运行时间 |
0.030 s |
代码语言 |
C++ |
内存使用 |
3.76 MiB |
提交时间 |
2025-03-06 21:48:28 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
struct Rectangle {
int x, y1, y2, flag;
};
const int MAXN = 800001;
const int OFFSET = 400001;
Rectangle s[MAXN], t[MAXN];
int a[MAXN], b[MAXN];
int n, tot, ans;
bool comp(const Rectangle &a, const Rectangle &b) {
if (a.x == b.x) return a.flag > b.flag;
return a.x < b.x;
}
int main() {
freopen("picture.in","r",stdin);
freopen("picture.out","w",stdout);
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
int x, y, xx, yy;
scanf("%d%d%d%d", &x, &y, &xx, &yy);
s[++tot] = {x, y, yy, 1};
t[tot] = {y, x, xx, 1};
s[++tot] = {xx, y, yy, 0};
t[tot] = {yy, x, xx, 0};
}
sort(s + 1, s + tot + 1, comp);
sort(t + 1, t + tot + 1, comp);
for (int i = 1; i <= tot; ++i) {
if (s[i].flag) {
for (int j = s[i].y1; j < s[i].y2; ++j) {
if (!a[j + OFFSET]) ++ans;
++a[j + OFFSET];
}
} else {
for (int j = s[i].y1; j < s[i].y2; ++j) {
--a[j + OFFSET];
if (!a[j + OFFSET]) ++ans;
}
}
if (t[i].flag) {
for (int j = t[i].y1; j < t[i].y2; ++j) {
if (!b[j + OFFSET]) ++ans;
++b[j + OFFSET];
}
} else {
for (int j = t[i].y1; j < t[i].y2; ++j) {
--b[j + OFFSET];
if (!b[j + OFFSET]) ++ans;
}
}
}
printf("%d\n", ans);
return 0;
}