4418: [Shoi2013]扇形面积并|二分答案|树状数组
2016-03-23 11:08
441 查看
为何感觉SHOI的题好水。。。又是一道SB题
从左到右枚举每一个区间,遇到一个扇形的左区间就+1,遇到右区间就-1,然后再树状数组上2分答案,还是不会码log的。。SHOI2013似乎还有一道题发牌也是类似的维护方法。。
从左到右枚举每一个区间,遇到一个扇形的左区间就+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; }
相关文章推荐
- Codeforces Coder-Strike 2014 - Finals (online edition, Div. 1)
- HDU 1166 敌兵布阵
- POJ 2352 Stars
- PAT 1057 Stack (30)
- neu 1438 树状数组求逆序数
- poj 2352
- 树状数组
- hdu 4630 No Pain No Game 树状数组
- 树状数组区间求和的三种模型
- ACM/ICPC World Finals 2013 F Low Power
- Codeforce 85E (二分答案+二分图染色)
- HDOJ1166 敌兵布阵 树状数组
- 二维树状数组
- Hoj 2275 Number Sequence
- POJ3321 Apple Tree
- BZOJ2434 [Noi2011]阿狸的打字机【AC自动机+dfs序+树状数组】
- HDU 3015
- hdu 5147
- 【转载】区间信息的维护与查询(一)——二叉索引树(Fenwick树、树状数组)
- codeforces628 E. Zbazi in Zeydabad 选择枚举对象+用顺序减少重复计算+树状数组优化