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. 1013团队Beta冲刺day7

    项目进展 李明皇 今天解决的进度 部分数据传递和使用逻辑测试 林翔 今天解决的进度 服务器端查看个人发布的action,修改已发布消息状态的action,仍在尝试使用第三方云存储功能保存图片 孙敏铭 ...

  2. JAVA和Android的回调机制

    本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/17483273),请尊重他人的辛勤劳动成果,谢谢 以 前不理解什么叫回 ...

  3. Codechef March Challenge 2014——The Street

    The Street Problem Code: STREETTA https://www.codechef.com/problems/STREETTA Submit Tweet All submis ...

  4. 微信小程序轮播图

    swiper标签 <!--index.wxml--> <swiper class="swiper" indicator-dots="true" ...

  5. 技术文档分享_linux中生成考核用的GPT分区表结构修复

    注:历史版本,后期改用python实现了 实验一: 目的:用于生成大量模拟破坏GPT分区结构案例,并生成唯一方式修复后的评判方法.故障:在一个完整的GPT分区磁盘上,丢失了GPT主分区表,或备份分区表 ...

  6. vue 在已有的购买列表中(数据库返回的数据)修改商品数量

    连续加班一个月  连续通宵三天 到最后还是少了一个功能 心碎 简介:一个生成好的商品列表(数据库返回的数据) 首先拿到我们需要渲染的数组 在data中定义 我是在测试的时候 直接写了两条数据 下面开始 ...

  7. LightningChart最新版 v.8.3 全新发布,新功能使用教程。

    LightningChart最新版v.8.3全新发布,主要介绍以下五个新功能及使用教程.   1. 网格模型,三角鼠标追踪 Tracing MeshModels with mouse. Traced ...

  8. Zepto.js库touch模块代码解析

    Zepto.js也许并不陌生,专门针对移动端开发,Zepto有一些基本的触摸事件可以用来做触摸屏交互(tap事件.swipe事件),Zepto是不支持IE浏览器的. 下面来解析一些Zepto.js触摸 ...

  9. java的分数类

    概述 分数类在算法中非常重要, 而在java中不那么重要,java基础类库提供 了biginteger了,提供类似方式, package 组合数学; public class Fraction { p ...

  10. python基础——面向对象进阶

    python基础--面向对象进阶 1.isinstance(obj,cls)和issubclass(sub,super) isinstance(obj,cls)检查是否obj是否是类 cls 的对象 ...