比赛 2025.3.6 评测结果 AAAAA
题目名称 矩形周长 最终得分 100
用户昵称 darkMoon 运行时间 1.906 s
代码语言 C++ 内存使用 4.50 MiB
提交时间 2025-03-06 20:03:25
显示代码纯文本
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
auto IN = freopen("picture.in", "r", stdin);
auto OUT = freopen("picture.out", "w", stdout);
auto IOS = ios::sync_with_stdio(false);
auto CIN = cin.tie(nullptr);
int mread(){
    int x = 0, f = 1;
    char c = cin.get();
    while(c < '0' || c > '9'){
        if(c == '-'){
            f = -1;
        }
        c = cin.get();
    }
    while(c >= '0' && c <= '9'){
        x = x * 10 + c - '0';
        c = cin.get();
    }
    return x * f;
}
const int N = 2e4 + 5;
int n = mread(), ans;
vector<pair<int, int> > add[N], del[N];
vector<int> now(N), la(N);
signed main(){
    for(int i = 1, a, b, c, d; i <= n; i ++){
        a = mread() + 10000, b = mread() + 10000, c = mread() + 10000 - 1, d = mread() + 10000 - 1;
        add[a].push_back(mp(b, d));
        del[c + 1].push_back(mp(b, d));
    }
    for(int i = 0; i <= 20001; i ++){
        for(auto t : add[i]){
            for(int j = t.fi; j <= t.se; j ++){
                now[j] ++;
            }
        }
        for(auto t : del[i]){
            for(int j = t.fi; j <= t.se; j ++){
                now[j] --;
            }
        }
        for(int j = 0; j <= 20000; j ++){
            if(now[j]){
                // printf("*** %d %d\n", i, j);
                if(j == 0 || now[j - 1] == 0){
                    ans ++;
                }
                if(j == 20000 || now[j + 1] == 0){
                    ans ++;
                }
                if(la[j] == 0){
                    ans ++;
                }
            }
            if(now[j] == 0 && la[j]){
                ans ++;
            }
        }
        la = now;
    }
    cout << ans;
    return 0;
}