Codeforces Round #460 D. Karen and Cards

时间:2022-09-12 20:25:23

Description

Karen just got home from the supermarket, and is getting ready to go to sleep.

Codeforces Round #460 D. Karen and Cards

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;
}

Codeforces Round #460 D. Karen and Cards的更多相关文章

  1. Codeforces Round &num;419 D&period; Karen and Test

    Karen has just arrived at school, and she has a math test today! The test is about basic addition an ...

  2. Codeforces Round &num;364 &lpar;Div&period; 2&rpar;-&gt&semi;A&period; Cards

    A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  3. codeforces round &num;419 E&period; Karen and Supermarket

    On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a ...

  4. codeforces round &num;419 C&period; Karen and Game

    C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...

  5. codeforces round &num;419 B&period; Karen and Coffee

    To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...

  6. codeforces round &num;419 A&period; Karen and Morning

    Karen is getting ready for a new school day! It is currently hh:mm, given in a 24-hour format. As yo ...

  7. Codeforces Round &num;460 &lpar;Div&period; 2&rpar; ABCDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8397685.html 2018-02-01 $A$ 题意概括 你要买$m$斤水果,现在有$n$个超市让你选择. ...

  8. Codeforces Round &num;490 &lpar;Div&period; 3&rpar; F - Cards and Joy

    F - Cards and Joy 思路:比较容易想到dp,直接dp感觉有点难,我们发现对于每一种数字要处理的情况都相同就是有 i 张牌 要给 j 个人分, 那么我们定义dp[ i ][ j ]表示 ...

  9. Codeforces Round &num;490 &lpar;Div&period; 3&rpar; &colon;F&period; Cards and Joy(组合背包)

    题目连接:http://codeforces.com/contest/999/problem/F 解题心得: 题意说的很复杂,就是n个人玩游戏,每个人可以得到k张卡片,每个卡片上有一个数字,每个人有一 ...

随机推荐

  1. BigDecimal 加减乘除

    BigDecimal bignum1 = new BigDecimal("10"); BigDecimal bignum2 = new BigDecimal("5&quo ...

  2. C&num;导入导出数据你该知道的方法。

    导入数据 using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using System; us ...

  3. vs emulator for android使用

    在windows上调试android程序,可以利用hyperv虚拟化功能,微软也提供了模拟工具和android studio.eclipse的配置说明,不再累述. 关于启动vs模拟器的cmd命令: e ...

  4. paip&period;Adblock屏蔽onlinedown华军软件园的4秒下载广告总结&period;&period;

    paip.Adblock屏蔽onlinedown华军软件园的4秒下载广告总结..      作者Attilax ,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址 ...

  5. pumping lemma for finite regular language&quest;

    some books describe pumping lemma as this: Let L be a regular language. Then there exists an integer ...

  6. Web后端 JAVA实现验证码生成与验证功能

    首先,写一个验证码生成帮助类,用来绘制随机字母: <span style="font-size:14px;">import java.awt.Color;  impor ...

  7. Liferay7 BPM门户开发之19&colon; 理解Service Builder体系

    Service Builder是Liferay为业务开发而设计的模型驱动(model-driven)平台工具,提供一系列的实体类.数据持久化.服务相关的代码自动生成服务.支持Hibernate and ...

  8. nginx日志分析工具

    https://www.linuxidc.com/Linux/2016-12/138731.htm

  9. dom4j解析xml报&quot&semi;文档中根元素后面的标记格式必须正确&quot&semi;

    今天,在写个批量启动报盘机的自动化应用,为了简化起见,将配置信息存储在xml中,格式如下: <?xml version="1.0" encoding="UTF-8& ...

  10. ESXI服务器的四个网口负载均衡

    什么是NIC Team(负载均衡) NIC Team其实就是将多个物理网卡同时分配到相同的端口/端口组,目的是为了实现带宽聚合,负载均衡以及故障转移 配置NIC Team 一.选择一台ESXi主机,打 ...