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

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

  1. Codeforces Round #419 D. 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 #364 (Div. 2)->A. Cards

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

  3. codeforces round #419 E. 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 #419 C. 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 #419 B. Karen and Coffee

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

  6. codeforces round #419 A. 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 #460 (Div. 2) ABCDE题解

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

  8. Codeforces Round #490 (Div. 3) F - Cards and Joy

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

  9. Codeforces Round #490 (Div. 3) :F. Cards and Joy(组合背包)

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

随机推荐

  1. 算法——算法时间复杂度的计算和大O阶的推导

    在算法分析中,我们将语句总的执行次数记为T(n)进而分析T(n)随n的变化情况确认T(n)的数量级.一般情况下,T(n)随n增大变化最缓慢的算法为最优算法. 根据定义,T(n)的求法是很简单的,也就是 ...

  2. swift 编写欢迎界面-- ios开发

    转载自:http://blog.csdn.net/u014455765/article/details/49622947 现在很多iOS开发人员都从oc转向Swift, swift 也必将成为ios开 ...

  3. Digilent Xilinx USB Jtag cable

    Digilent Xilinx USB Jtag cable 安装环境 操作系统:fedora 20 64bit 源链接:https://wiki.gentoo.org/wiki/Xilinx_USB ...

  4. Css之导航栏学习

    Css: ul { list-style-type:none; margin:; padding:; overflow:hidden; background-color:blue; /*固定在顶部*/ ...

  5. Comet之SSE(Server - Sent - Envent,服务器发送事件)

    1.SSE API 先要创建一个新的EventSource对象,并传进一个入口点: var source = new EventSource("myenvent.php"); △: ...

  6. LDAP是什么

    LDAP的英文全称是Lightweight Directory Access Protocol,一般都简称为LDAP.LDAP目录服务是一种特殊的数据库系统,其专门针对读取,浏览和搜索操作进行了特定的 ...

  7. apigw鉴权分析(1-1)阿里数加 - 鉴权方式分析

    一.访问方式 1.访问阿里云首页 https://www.aliyun.com/?utm_medium=text&utm_source=bdbrand&utm_campaign=bdb ...

  8. kafka HA

    1. replication 如图.1所示,同一个 partition 可能会有多个 replica(对应 server.properties 配置中的 default.replication.fac ...

  9. Oracle 用户创建及权限设置

    1:创建临时表空间create temporary tablespace user_temp  tempfile 'D:\app\Administrator\oradata\ORACLE\xyrj_t ...

  10. python tornado TCPserver异步协程实例

    项目所用知识点 tornado socket tcpserver 协程 异步 tornado tcpserver源码抛析 在tornado的tcpserver文件中,实现了TCPServer这个类,他 ...