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\)定理(其实还是没有懂),回来写这道题. 由于题目中保证"任意 ...
随机推荐
- Ionic2 下处理 Android 设备下返回按钮的事件
原文发表于我的技术博客 本文分享了 Ionic2 下处理 Android 设备下返回按钮的事件,供参考. 原文发表于我的技术博客 代码中我分享了如何捕捉 Ionic2 项目在 Android 设备下返 ...
- springcloud 笔记
官方教程 http://projects.spring.io/spring-cloud/ guide https://github.com/spring-guides 伪官方教程 https://sp ...
- JS 实现计算一段文字中的字节数,字母数,数字数,行数,汉字数。
看到了匹配,第一个想到了用正则表达式,哈哈,果然很方便.不过正则表达式高深莫测!我还没有研究明白啊..目前学了点皮毛.代码如下: <!DOCTYPE html PUBLIC "-//W ...
- github链接地址及
http://www.github.com/houyanan1/test.git git 在本地创建分支,并且已经在该分支中开发了一段时间,那么commit到本地后,代码会做一个提交快照,在本地分支保 ...
- Alpha冲刺之事后诸葛亮
组长博客 作业博客 项目Postmortem 设想和目标 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 我们的软件针对的是福大学子来到食堂会犹豫不决无法决定吃什么 ...
- 探索guava(一)——前置条件Preconditions类
作用 可以简洁的完成参数检验,在进行业务逻辑代码前进行前置判断.并且避免了冗长的if语句.guava将所有检验的API都放置于Preconditions类中. API Preconditions类大致 ...
- CodeIgniter中使用base_url()时显示http://::1/ci/
URL 辅助函数文件包含了一些帮助你处理 URL 的函数. 加载辅助函数后,你可以使用base_url(),site_url(),current_url()等一些列函数,但是有时候你会遇到这种问题,就 ...
- How To Install MySQL on Ubuntu 16.04
https://help.ubuntu.com/lts/serverguide/mysql.html http://www.cnblogs.com/wuhou/archive/2008/09/28/1 ...
- HTML的input类型为hidden导致无法reset改字段的value问题
问题关键:根据HTML规范,hidden是非ui类元素,不接受用户处理.所以form的 reset并不影响它. http://stackoverflow.com/questions/6367793/w ...
- delphi有关获取其他程序的窗口及对窗口内控件的操作
1.获取当前所有窗口 procedure TForm1.Button1Click(Sender: TObject);var szText: array[0..254] of char; hCurren ...