求助站外题
  • 板块学术版
  • 楼主White_Falcon
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/4/19 19:04
  • 上次更新2024/4/19 21:01:49
查看原帖
求助站外题
1003209
White_Falcon楼主2024/4/19 19:04

RT

本人代码:

#include <bits/stdc++.h>
using namespace std;

const int N = 1e4 + 5;
int n, a[N][N], o;
struct node{
	int l, r;
	node(int ll, int rr): l(ll), r(rr){};
	bool operator < (const node &s) const{
		return l != s.l ? l < s.l : r > s.r;
	} 
};
vector<node>e[N];

int ans(int x){
	if(e[x].size() == 0){
		return 0;
	}
	sort(e[x].begin(), e[x].end());
	int sum = 0;
	int i = 0;
	while(i < e[x].size()){
		int l = e[x][i].l;
		int r = e[x][i].r;
		while(i < e[x].size() && r >= e[x][i].l){
			r = max(e[x][i].r, r);
			i++;
		}
		sum += r - l;
	}
	return sum;
}

int main(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		int qx, qy, wx, wy;
		cin >> qx >> qy >> wx >> wy;
		for(int j = qx; j <= wx; j++){
			e[i + 10001].push_back(node(wy, qy));
		}
	}
	for(int i = -10000; i <= 10000; i++){
		o += ans(i + 10001);
	}
	
	cout << o;
	return 0;
}
2024/4/19 19:04
加载中...