[线段树] Codeforces Round #419 (Div. 1) D. Karen and Cards
来源:互联网 发布:nginx防止cc攻击配置 编辑:程序博客网 时间:2024/06/08 17:21
从小到大枚举
发现平面上矩形的交取个min就好了,挖掉的矩形要取并,这个可以用平衡树或线段树维护
大概是这样,我是灵魂画师
#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;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=500005;int mx[N<<2],mn[N<<2],F[N<<2]; ll sum[N<<2];inline void mark(int x,int l,int r,int a){ mx[x]=mn[x]=a,sum[x]=(ll)(r-l+1)*a,F[x]=a;}inline void push(int x,int l,int r){ int mid=(l+r)>>1; if (F[x]) mark(x<<1,l,mid,F[x]),mark(x<<1|1,mid+1,r,F[x]),F[x]=0;}inline void upd(int x){ mx[x]=max(mx[x<<1],mx[x<<1|1]); mn[x]=min(mn[x<<1],mn[x<<1|1]); sum[x]=sum[x<<1]+sum[x<<1|1];}inline void Modify(int x,int l,int r,int ql,int qr,int a){ if (ql<=l && r<=qr){ mark(x,l,r,a); return; } push(x,l,r); int mid=(l+r)>>1; if (ql<=mid) Modify(x<<1,l,mid,ql,qr,a); if (qr>mid) Modify(x<<1|1,mid+1,r,ql,qr,a); upd(x);}inline int QL(int x,int l,int r,int a){ // <a if (l==r) return l; push(x,l,r); int mid=(l+r)>>1; if (mn[x<<1]<a) return QL(x<<1,l,mid,a); else return QL(x<<1|1,mid+1,r,a);}inline int QR(int x,int l,int r,int a){ // >=a if (l==r) return l; push(x,l,r); int mid=(l+r)>>1; if (mx[x<<1|1]<a) return QR(x<<1,l,mid,a); else return QR(x<<1|1,mid+1,r,a);}inline ll Sum(int x,int l,int r,int ql,int qr){ if (ql<=l && r<=qr) return sum[x]; push(x,l,r); int mid=(l+r)>>1; ll ret=0; if (ql<=mid) ret+=Sum(x<<1,l,mid,ql,qr); if (qr>mid) ret+=Sum(x<<1|1,mid+1,r,ql,qr); return ret;}int n,p,q,r;int a[N],b[N],c[N];int idx[N];bool cmp(int x,int y){ return a[x]<a[y];}inline void Add(int x,int y){ if (mn[1]>=y) return; int l=QL(1,1,q,y); if (l<=x) Modify(1,1,q,l,x,y);}inline ll Query(int x,int y){ if (x>q || y>r) return 0; ll ret=(ll)(q-x+1)*(r-y+1); if (mx[1]<y) return ret; int r=QR(1,1,q,y); if (x<=r){ ll tmp=Sum(1,1,q,x,r)-(ll)(r-x+1)*(y-1); ret-=tmp; } return ret;}int maxx[N],maxy[N];int main(){ freopen("t.in","r",stdin); freopen("t.out","w",stdout); read(n); read(p); read(q); read(r); for (int i=1;i<=n;i++) read(a[i]),read(b[i]),read(c[i]),idx[i]=i; sort(idx+1,idx+n+1,cmp); maxx[n+1]=1,maxy[n+1]=1; for (int i=n;i;i--) maxx[i]=max(maxx[i+1],b[idx[i]]+1),maxy[i]=max(maxy[i+1],c[idx[i]]+1); int pnt=1; ll ans=0; for (int i=1;i<=p;i++){ while (pnt<=n && a[idx[pnt]]<i) Add(b[idx[pnt]],c[idx[pnt]]),pnt++; ans+=Query(maxx[pnt],maxy[pnt]); } printf("%lld\n",ans); return 0;}
阅读全文
0 0
- [线段树] Codeforces Round #419 (Div. 1) D. Karen and Cards
- CodeForces 815D. Karen and Cards
- Codeforces Round #419 (Div. 2) (Codeforces 815B) D. Karen and Test 组合数学
- Codeforces Round #419 (Div. 2) C.Karen and Game 思维
- Codeforces Round #419 (Div. 2)Karen and Game
- Codeforces Round #419 (Div. 2)Karen and Coffee
- Codeforces Round #419 (Div. 2) C. Karen and Game 题解
- Codeforces Round #419 (Div. 2) A. Karen and Morning
- Codeforces Round #419 (Div. 2) B. Karen and Coffee
- Codeforces Round #419 (Div. 2) C. Karen and Game【贪心】
- Codeforces Round #419 (Div. 2)Karen and Coffee
- 【Codeforces Round #419 (Div. 1)】Codeforces 815A Karen and Game
- 【Codeforces Round #419 (Div. 1)】Codeforces 815C Karen and Supermarket
- Codeforces Round #419 (Div. 1) B. Karen and Test(组合数)
- Codeforces Round #419 (Div. 1) C. Karen and Supermarket(树上背包)
- [二分图匹配 线段树] Codeforces 573D Round #318 [RussianCodeCup Thanks-Round] (Div. 1) D. Bear and Cavalry
- Codeforces Round #250 (Div. 1) D. The Child and Sequence(线段树暴力)
- Codeforces Round #318(Div. 1) 573 D. Bear and Cavalry【dp+矩阵+线段树优化】
- Java Volatile 变量的可见性
- jar包和war包的介绍和区别
- java中异常处理finally和return语句的执行顺序
- 遍历map集合的四种方式
- F1V3.0-6 平台V3.0 UI体系架构
- [线段树] Codeforces Round #419 (Div. 1) D. Karen and Cards
- OSI七层模型详解
- git 技巧
- SQL复杂查询(二)
- 关于Android.9图片的处理和注意事项
- 面试题40. 数组中只出现一次的数字
- Java数据类型
- 微信网页授权获取用户信息 返回{"errcode":40066,"errmsg":"invalid url hint: [FZbxRA0556sz12!]"}错误
- 半路出家, 我的iOS自学之路-4-Block的声明,定义,闭包性,强引用循环