首页 技术 正文
技术 2022年11月13日
0 收藏 308 点赞 2,741 浏览 2146 个字

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;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,491
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,493
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,294