4418: [Shoi2013]扇形面积并|二分答案|树状数组
2017-06-27 19:26
387 查看
为何感觉SHOI的题好水。
。。又是一道SB题
从左到右枚举每个区间,遇到一个扇形的左区间就+1。遇到右区间就-1,然后再树状数组上2分答案,还是不会码log的。。
SHOI2013似乎另一道题发牌也是相似的维护方法。。
。。又是一道SB题
从左到右枚举每个区间,遇到一个扇形的左区间就+1。遇到右区间就-1,然后再树状数组上2分答案,还是不会码log的。。
SHOI2013似乎另一道题发牌也是相似的维护方法。。
#include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<vector> #include<cmath> #include<queue> #include<set> #include<map> #define ll long long #define mod 999911659 //2 3 4679 35617 #define N 500001 using namespace std; int sc() { int i=0,f=1; char c=getchar(); while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9')i=i*10+c-'0',c=getchar(); return i*f; } struct W{int p,r,x;}a ; long long ans; int n,tot,mx,k,m,tr ; bool cmp(W a,W b) { return a.p<b.p; } void change(int x,int f) { for(;x<=mx;x+=x&-x)tr[x]+=f; } ll ask(int x) { ll ans=0; for(;x;x-=x&-x)ans+=tr[x]; return ans; } int query() { int l=1,r=mx,ans=0; while(l<=r) { int mid=l+r>>1; if(ask(mid)>=k)ans=mid,l=mid+1; else r=mid-1; } return ans; } int main() { n=sc();m=sc(),k=sc(); for(int i=1;i<=n;i++) { int x=sc(),l=sc(),r=sc();mx=max(mx,x); a[++tot].p=l,a[tot].r=x,a[tot].x=1; a[++tot].p=r,a[tot].r=x,a[tot].x=-1; if(l>r) a[++tot].p=-m,a[tot].r=x,a[tot].x=1; } sort(a+1,a+tot+1,cmp); int now=1; for(int i=-m;i<m;i++) { while(now<=tot&&a[now].p<=i) change(1,a[now].x),change(a[now].r+1,-a[now].x),now++; ll res=query(); ans+=res*res; } cout<<ans; return 0; }
相关文章推荐
- 4418: [Shoi2013]扇形面积并|二分答案|树状数组
- [BZOJ]4418: [Shoi2013]扇形面积并 线段树
- bzoj 4418: [Shoi2013]扇形面积并
- 【BZOJ4418】[Shoi2013]扇形面积并 扫描线+线段树
- 【bzoj4418】[Shoi2013]扇形面积并 扫描线+线段树
- bzoj4418 [Shoi2013]扇形面积并
- BZOJ_P3048 [Usaco2013 Jan]Cow Lineup(二分答案+树状数组/单调队列)
- bzoj 3130: [Sdoi2013]费用流 网络流+二分答案
- 【BZOJ 3110】 [Zjoi2013]K大数查询 整体二分+树状数组区间修改
- BZOJ 4590 [Shoi2015]自动刷题机 ——二分答案
- 【HDU4560 2013西山居复赛D】【二分答案+网络流拆点】我是歌手 安排演唱会_每人歌不同_每场歌不同_人歌匹配一次
- BZOJ 3110 [Zjoi2013]K大数查询 (整体二分 + 树状数组或线段树处理区间合值)
- BZOJ_3969_[WF2013]Low Power_二分答案
- BZOJ4590 SHOI2015自动刷题机(二分答案)
- [BZOJ3969]WF2013 Low Power|二分答案|贪心
- BZOJ_3110_[Zjoi2013]K大数查询_整体二分+树状数组
- bzoj3130 [SDOI2013]费用流 结论+二分答案+网络流检验
- BZOJ_4590_[Shoi2015]自动刷题机_二分答案
- bzoj 4326: NOIP2015 运输计划 (二分答案+树链剖分+树状数组)
- bzoj 3969 WF2013 Low Power [贪心] [二分答案]