AcWing 3068. 扫描线
原题链接
中等
作者:
harry12138
,
2021-04-21 17:46:09
,
所有人可见
,
阅读 661
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<unordered_set>
#include<unordered_map>
using namespace std;
//extern "C"{void *__dso_handle=0;}
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define lowbit(x) x&-x
const double PI=acos(-1.0);
const double eps=1e-6;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
const int maxn=1e3+10;
const int maxm=100+10;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
pii l[maxn],r[maxn],lie[maxn];
vector<int> p;
int n;
ll merge(int a,int b)
{
int cnt=0;
for(int i=1;i<=n;i++)
{
if(l[i].fi<=a && r[i].fi>=b)
lie[cnt++]=make_pair(l[i].se, r[i].se);
}
if(!cnt) return 0;
sort(lie,lie+cnt);
ll ans=0;
ll l=lie[0].fi,r=lie[0].se;
for(int i=1;i<cnt;i++)
{
if(lie[i].fi<=r) r=max(r,(ll)lie[i].se);
else
{
ans+=r-l;
l=lie[i].fi,r=lie[i].se;
}
}
ans+=r-l;
return ans;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d%d%d",&l[i].fi,&l[i].se,&r[i].fi,&r[i].se);
p.push_back(l[i].fi),p.push_back(r[i].fi);
}
sort(p.begin(),p.end());
ll ans=0;
for(int i=0;i+1<p.size();i++)
{
ll len=p[i+1]-p[i];
ans += len*merge(p[i],p[i+1]);
}
printf("%lld\n",ans);
return 0;
}
’‘’
ORZ
‘’‘