Description
Karen just got home from the supermarket, and is getting ready to go to sleep.
After taking a shower and changing into her pajamas, she looked at her shelf and saw an album. Curious, she opened it and saw a trading card collection.
She recalled that she used to play with those cards as a child, and, although she is now grown-up, she still wonders a few things about it.
Each card has three characteristics: strength, defense and speed. The values of all characteristics of all cards are positive integers. The maximum possible strength any card can have is p, the maximum possible defense is q and the maximum possible speed is r.
There are n cards in her collection. The i-th card has a strength ai, defense bi and speed ci, respectively.
A card beats another card if at least two of its characteristics are strictly greater than the corresponding characteristics of the other card.
She now wonders how many different cards can beat all the cards in her collection. Two cards are considered different if at least one of their characteristics have different values.
题面
Solution
考虑枚举一维,假设枚举\(c\),讨论\(c\)与某个\(c_i\)的关系
如果\(c>c_i\)那么 \(a>a_i | b>b_i\),满足一项即可
如果\(c<=c_i\),需满足 \(a>a_i \& b>b_i\)
这两个条件分别对应 矩形去掉一个小矩形 和 矩形 这两种图形
考虑多个矩形的情况:
如果所有矩形都是情况1,那么情况\(1\)就是所有矩形的并的补集
按第一维排序之后,第二位一定是递减序列,用一个单调栈即可维护
如果c取\(maxc\)的时候,得出的图形就是上面所求出的
考虑c减少时的情况,那么就会出现情况2
原图形就变成一个矩形和剩余矩形的交
我们可以通过减去补集来求出
按卡片的c属性从大到小枚举,维护轮廓即可
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=500010;
int n,A,B,C;
struct node{
int a,b,c;
}p[N];
inline bool ca(const node &i,const node &j){
if(i.a!=j.a)return i.a<j.a;
return i.b<j.b;
}
inline bool cc(const node &i,const node &j){return i.c>j.c;}
int st[N],top=0,bx[N],by[N];
int main(){
freopen("pp.in","r",stdin);
freopen("pp.out","w",stdout);
scanf("%d%d%d%d",&n,&A,&B,&C);
for(int i=1;i<=n;i++)scanf("%d%d%d",&p[i].a,&p[i].b,&p[i].c);
sort(p+1,p+n+1,ca);
for(int i=1;i<=n;i++){
while(top && p[st[top]].b<p[i].b)top--;
st[++top]=i;
}
ll tot=0,ans=0;st[top+1]=0;
for(int i=1;i<=top;i++){
tot+=1ll*p[st[i]].b*(p[st[i]].a-p[st[i-1]].a);
for(int j=p[st[i-1]].a+1;j<=p[st[i]].a;j++)by[j]=p[st[i]].b;
for(int j=p[st[i]].b;j>p[st[i+1]].b;j--)bx[j]=p[st[i]].a;
}
tot=1ll*A*B-tot;
sort(p+1,p+n+1,cc);
for(int i=C,j=1,x=1,y=1;i>=1;i--){
for(;j<=n && p[j].c>=i;j++){
while(x<=p[j].a)tot-=B-max(by[x],y-1),x++;
while(y<=p[j].b)tot-=A-max(bx[y],x-1),y++;
}
ans+=tot;
}
cout<<ans<<endl;
return 0;
}