UVALIVE 3525 Wild West <分类枚举 + 二分优化>
来源:互联网 发布:淘宝二手镜头靠谱吗 编辑:程序博客网 时间:2024/06/05 03:06
传送门:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1526
题意:
每个人有三种属性(a,b,c),1<=a,b,c<=M,一共有M^3个人,没有两个人的属性是完全相同的。其中有N个人成立了邪恶党,一个人能战胜另一个人的条件是至少有一个属性大于对方对应属性。问剩下M^3-N个人中有多少人可以战胜所有的邪恶党。
数据范围:1<=N<=10^5,2<=M<=10^5分析:枚举,set优化
求M^3个组合中有多少个(a,b,c)满足a<=ai且b<=bi且c<=ci for at least one (ai,bi,ci) in N。
枚举每个c,求出对于每个邪恶(ai,bi,ci) ci>=c,然后进行处理,求出不符合的(ai,bi),area个数。对于每一个c,有ans = M^2-area;
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cstdlib>#include <set>#define LL long long#define maxn 100010using namespace std;struct Node{ int x,y,z; void read(int &x) { x=0;char ch; do ch = getchar();while(ch<'0'||ch>'9'); do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0'); } void read() {read(x);read(y);read(z);} bool operator< (const Node& tmp) const {return x<tmp.x||(x==tmp.x&&y<tmp.y);} Node(int x=0,int y=0,int z=0):x(x),y(y),z(z) {}}p[maxn];bool cmp(const Node& a,const Node& b) {return a.z>b.z;}set<Node> s;set<Node>::iterator it;LL calc(const Node& a){ Node b=*--s.lower_bound(a),c=*s.upper_bound(a); //printf("%d %d %d %d\n",a.y,c.y,a.x,b.x); return 1LL*(a.y-c.y)*(a.x-b.x);}LL area;void Add(const Node& a){ it=s.lower_bound(a); if(it==s.end()||it->y<=a.y) { it=--s.upper_bound(a); for(;it!=s.end()&&it->y<=a.y;) area-=calc(*it),s.erase(it--); s.insert(a);area+=calc(a); }}int n,m;void Work(){ int now=0;area = 0;LL ans =0; for(int i =0;i<n;i++) p[i].read(); sort(p,p+n,cmp); s.clear(); s.insert(Node(0,m+1,-1));s.insert(Node(m+1,0,-1)); for(int i=m;i;i--) { while(now<n&&p[now].z>=i) Add(p[now++]); ans += (1LL*m*m-area); } printf("%lld\n",ans);}int main(){ while(scanf("%d %d",&n,&m)==2&&(n+m)) { Work(); } return 0;}
0 0
- UVALIVE 3525 Wild West <分类枚举 + 二分优化>
- LA 3525 Wild West 单调性
- Central Europe 2005 Wild West ( POJ 2944 )
- UVALive - 3887 Slim Span(枚举+二分)
- 二分优化的暴力枚举
- 【枚举情况】UVALive
- UVAlive 4975 Manacher+枚举
- UVALIVE 3635 Pie 二分
- UVALive 6144 Radiation 二分
- uvalive 2949(二分+贪心)
- Clock Splitter+uvalive+二分
- UVALive - 3635 Pie 二分
- uvalive 4254(二分)
- uvalive 4725(贪心 + 二分)
- UVALive 6525 二分匹配
- UVALive 3635-Pie-二分
- UVALive 3177-贪心+二分
- UVALive 4254 二分
- java.lang.IllegalMonitorStateException: object not locked by thread before notify()
- Virtualbox下Ubuntu扩展根分区
- linux命令详解:md5sum命令
- 线性表—链式存储
- git的廖雪峰教程(其个人网站在阿里云挂载)
- UVALIVE 3525 Wild West <分类枚举 + 二分优化>
- AlertDialog的使用
- 欢迎使用CSDN-markdown编辑器
- myeclipse安装ant和ivy
- msp430g2553单片机学习心得
- 67.[LeetCode]Add Binary
- 不能用sendmsg提升原始套接字发送性能
- RDLC 设置表的重复标题行(在每页中显示标题行)
- C#对象深拷贝