[Treap 笛卡尔树 扫描线 补集转化] BZOJ 2658 [Zjoi2012]小蓝的好友(mrx)
来源:互联网 发布:linux 查看磁盘空间 编辑:程序博客网 时间:2024/06/04 08:24
这个先转化成全部矩形
我们考虑扫描线 也就是以当前直线作为右边界的矩形有多少个
对于每个纵坐标 设h表示最左能扩展到哪里
假设
那么答案至少应该
然后还要加上
然后还要继续递归式的加 这个可以用笛卡尔树维护
扫描线向右移就h都+1 碰到点就h降为0
#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;typedef pair<int,int> abcd;typedef long long ll;inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline void read(int &x){ char c=nc(),b=1; for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1; for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;}const int N=100005;int n,R,C; abcd a[N];ll Ans;inline ll calc(int n){ return (ll)n*(n+1)/2; }struct node{ node *l,*r; int size; int add,h; ll ans; void upd(){ size=1,ans=0; if (l) size+=l->size,ans+=l->ans+(ll)(l->h-h)*calc(l->size); if (r) size+=r->size,ans+=r->ans+(ll)(r->h-h)*calc(r->size); } void mark(int t){ add+=t,h+=t; } void push(){ if(l)l->mark(add); if(r)r->mark(add); add=0; }}nodes[N],*root;typedef pair<node*,node*> Droot;inline int ran(){ static int x=31253125; x+=(x<<4)+1; return x&65536;}inline node* M(node *x,node *y){ if (!x || !y) return x?x:y; x->push(); y->push(); if (x->h>y->h || (x->h==y->h && ran())) return y->l=M(x,y->l),y->upd(),y; else return x->r=M(x->r,y),x->upd(),x;}inline int Size(node *x){ return x?x->size:0; }inline Droot S(node *x,int k){ if(!x) return Droot(NULL,NULL); x->push(); Droot y; if (Size(x->l)>=k){ y=S(x->l,k); x->l=y.second; x->upd(); y.second=x; }else{ y=S(x->r,k-Size(x->l)-1); x->r=y.first; x->upd(); y.first=x; } return y;}int main(){ freopen("mrx.in","r",stdin); freopen("mrx.out","w",stdout); read(R); read(C); read(n); for (int i=1;i<=n;i++) read(a[i].first),read(a[i].second); sort(a+1,a+n+1); Ans=calc(R)*calc(C); for (int i=1;i<=C;i++) nodes[i].size=1,root=M(root,nodes+i); int pnt=1; for (int i=1;i<=R;i++){ root->mark(1); while (pnt<=n && a[pnt].first==i){ Droot t1=S(root,a[pnt].second-1),t2=S(t1.second,1); t2.first->h=0; root=M(M(t1.first,t2.first),t2.second); pnt++; } Ans-=root->ans+(ll)root->h*calc(root->size); } printf("%lld\n",Ans); return 0;}
0 0
- [Treap 笛卡尔树 扫描线 补集转化] BZOJ 2658 [Zjoi2012]小蓝的好友(mrx)
- bzoj 2658: [Zjoi2012]小蓝的好友(mrx) treap+扫描线
- bzoj 2658: [Zjoi2012]小蓝的好友(mrx) Treap
- BZOJ 2658 [Zjoi2012]小蓝的好友(mrx)
- bzoj2658: [Zjoi2012]小蓝的好友(mrx)
- bzoj2658: [Zjoi2012]小蓝的好友(mrx)
- 【ZJOI2012】小蓝的好友(mrx)
- BZOJ2658 [Zjoi2012]小蓝的好友(mrx)
- [bzoj2658]小蓝的好友
- 关于笛卡尔树及Treap的线性构造法
- [BZOJ 2657][Zjoi2012]旅游(journey):树的直径
- [线段树 Treap] BZOJ 2770 YY的Treap
- 笛卡尔树简介(分类到treap里面)
- BZOJ 2815 [ZJOI2012]灾难【灭绝树
- bzoj 2815: [ZJOI2012]灾难 支配树
- bzoj 2657: [Zjoi2012]旅游(journey) (map建图+树的直径)
- bzoj 3224 平衡树 treap
- BZOJ 2815【ZJOI2012灾难】
- SQL模糊查询
- 761D Dasha and Very Difficult Problem[数学][思维]
- java使用cors解决跨域问题
- ios直播技术(1)-- 视频采集
- 阿里巴巴Java开发手册- 编程规约-集合处理
- [Treap 笛卡尔树 扫描线 补集转化] BZOJ 2658 [Zjoi2012]小蓝的好友(mrx)
- 在域名中检索内容(site)
- 修改origin的地址定向
- this指针
- 1010. Radix (25)
- Linux硬件设备访问
- Oracle 11g 密码设置永不过期
- How to Get More Grit in Your Life (Rebroadcast)
- SpringMVC详解