CF815D Karen and Cards
固定一维c,然后(a,b)看成坐标,矩形区域求交
1.Segment tree Beats!
2.改成不合法的区域就是求并,c反向枚举,区域只增不减且完全包含之前的
单调栈预处理找到轮廓线,然后两个指针维护顶头位置即可
#include<bits/stdc++.h>
#define reg register int
#define il inline
#define int long long
#define numb (ch^'0')
using namespace std;
typedef long long ll;
il void rd(int &x){
char ch;x=;bool fl=false;
while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
for(x=numb;isdigit(ch=getchar());x=x*+numb);
(fl==true)&&(x=-x);
}
namespace Miracle{
const int N=+;
int n,A,B,C;
ll ans,sum;
struct node{
int a,b,c;
}p[N];
bool cmpa(node a,node b){
return a.a<b.a;
}
bool cmpc(node a,node b){
return a.c>b.c;
}
int sta[N],top;
int x[N],y[N];
int main(){
rd(n);rd(A);rd(B);rd(C);
for(reg i=;i<=n;++i) rd(p[i].a),rd(p[i].b),rd(p[i].c);
sort(p+,p+n+,cmpa);
for(reg i=;i<=n;++i){
while(top&&p[sta[top]].b<p[i].b) --top;
sta[++top]=i;
}
sum=(ll)A*B;
sta[top+]=;
for(reg i=;i<=top;++i){
//cout<<" ii "<<i<<" "<<p[sta[i]].b<<endl;
sum-=(ll)((ll)p[sta[i]].a-p[sta[i-]].a)*p[sta[i]].b;
for(reg j=p[sta[i-]].a+;j<=p[sta[i]].a;++j) x[j]=p[sta[i]].b;
for(reg j=p[sta[i]].b;j>p[sta[i+]].b;--j) y[j]=p[sta[i]].a;
}
// for(reg i=1;i<=A;++i){
// cout<<x[i]<<" ";
// }cout<<endl;
// for(reg i=1;i<=B;++i){
// cout<<y[i]<<" ";
// }cout<<endl;
// cout<<" sum "<<sum<<endl;
sort(p+,p+n+,cmpc);
for(reg tx=,ty=,j=,i=C;i>=;--i){
// cout<<" i "<<i<<" tx "<<tx<<" ty "<<ty<<endl;
while(j<=n&&p[j].c>=i){
// cout<<" p[j] "<<j<<" "<<p[j].c<<endl;
for(;tx<=p[j].a;++tx) sum-=B-max(ty-,x[tx]);
// cout<<" sum1 "<<sum<<endl;
for(;ty<=p[j].b;++ty) sum-=A-max(tx-,y[ty]);
// cout<<" sum2 "<<sum<<endl;
++j;
}
ans+=sum;
}
printf("%lld",ans);
return ;
} }
signed main(){
Miracle::main();
return ;
} /*
Author: *Miracle*
Date: 2019/3/3 15:45:41
*/
很套路了
排序,然后偏序想到坐标矩形求面积
交和并的转化,容斥。或者大力吉司机线段树
CF815D Karen and Cards的更多相关文章
- CF815D Karen and Cards 官方题解翻译
看到这道题,网上没有中文版的官方题解,于是就自己翻译了一遍. 不是机器翻译,是一个字一个字纯手翻译的,如果有错误欢迎指正. 比如我们有一张卡片,三个参数分别是 a1 = 4, b1 = 2, c1 = ...
- 【CF815D】Karen and Cards 单调栈+扫描线
[CF815D]Karen and Cards 题意:一张卡片有三个属性a,b,c,其上限分别为A,B,C,现在有n张卡片,定义一张卡片能打败另一张卡片当且仅当它的至少两项属性要严格大于另一张的对应属 ...
- Codeforces Round #460 D. Karen and Cards
Description Karen just got home from the supermarket, and is getting ready to go to sleep. After tak ...
- [学习笔记]Segment Tree Beats!九老师线段树
对于这样一类问题: 区间取min,区间求和. N<=100000 要求O(nlogn)级别的算法 直观体会一下,区间取min,还要维护区间和 增加的长度很不好求.... 然鹅, 从前有一个来自杭 ...
- Petrozavodsk Summer Training Camp 2017 Day 9
Petrozavodsk Summer Training Camp 2017 Day 9 Problem A. Building 题目描述:给出一棵树,在树上取出一条简单路径,使得该路径的最长上升子序 ...
- Codeforces Round #419 (Div. 1) 补题 CF 815 A-E
A-C传送门 D Karen and Cards 技巧性很强的一道二分优化题 题意很简单 给定n个三元组,和三个维度的上限,问存在多少三元组,使得对于给定的n个三元组中的每一个,必有两个维度严格小于. ...
- Codeforces Round #419
A Karen and Morning 找最近的回文时间 模拟 往后推 判判就行 //By SiriusRen #include <bits/stdc++.h> using namesp ...
- Codeforces Round #419 (Div. 1) (ABCD)
1. 815A Karen and Game 大意: 给定$nm$矩阵, 每次选择一行或一列全部减$1$, 求最少次数使得矩阵全$0$ 贪心, $n>m$时每次取一列, 否则取一行 #inclu ...
- BZOJ 1004 【HNOI2008】 Cards
题目链接:Cards 听说这道题是染色问题的入门题,于是就去学了一下\(Bunside\)引理和\(P\acute{o}lya\)定理(其实还是没有懂),回来写这道题. 由于题目中保证"任意 ...
随机推荐
- Flutter - AAPT: error: resource android:attr/dialogCornerRadius not found.
Launching lib\main.dart on Nokia X6 in debug mode... FAILURE: Build failed with an exception. * What ...
- linux下文件加密方法总结
为了安全考虑,通常会对一些重要文件进行加密备份或加密保存,下面对linux下的文件加密方法做一简单总结: 方法一:gzexe加密这种加密方式不是非常保险的方法,但是能够满足一般的加密用途,可以隐蔽脚本 ...
- Ceph常规操作及常见问题梳理
Ceph集群管理 每次用命令启动.重启.停止Ceph守护进程(或整个集群)时,必须指定至少一个选项和一个命令,还可能要指定守护进程类型或具体例程. **命令格式如 {commandline} [opt ...
- 2-Twentieth Scrum Meeting-20151220
任务安排 成员 今日完成 明日任务 闫昊 请假(数据库) 唐彬 请假(数据库) 史烨轩 尝试使用downloadmanager对notification进行更新 尝试使用downloadm ...
- <四则运算>第二次冲刺
这一次冲刺的主要内容是完善我们的界面,是我们的APP界面更规划更标准一点, 然后还要添加一些新算法. 距离客户的需求已经一半了. 代码正在完善中,稍后上传...
- 【Deep Hash】NINH
[CVPR 2015] Simultaneous Feature Learning and Hash Coding with Deep Neural Networks [paper] Hanjiang ...
- Failed while installing JAX-RS (REST Web Services) 1.1. org.osgi.service.prefs.BackingStoreException: Resource '/.settings' does not exist.
https://issues.jboss.org/browse/JBIDE-10039?_sscc=t https://stackoverflow.com/questions/16836832/fai ...
- Chrome 启动参数列表
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --type=gpu-process --channel ...
- [区块链]POW 与POS
POW:全称Proof ofWork,工作证明. 这是什么意思呢?就是说,你能获得多少货币,取决于你挖矿贡献的有效工作,也就是说,你电脑性能越好,分给你的矿就会越多,这就是根据你的工作证明来执行货币的 ...
- Oracle ORDS的简单SQL配置模板
1. 先加上简单的SQL配置模板. DECLARE PRAGMA AUTONOMOUS_TRANSACTION; BEGIN ORDS.ENABLE_SCHEMA(p_enabled => TR ...