BZOJ 1935
来源:互联网 发布:win7开机优化加速 编辑:程序博客网 时间:2024/06/08 19:28
【题目分析】
树状数组+离线。
【代码】
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;struct event{ int opt;//0 add: 1 que int x;// position int y;// position int ans;//belongs to int tmp;//+ or -}t[3000001];int top=0,xx,yy,x1,y1,x2,y2,n,m;int ans[500001];int tr[10000001];int rank[3000001];inline bool cmp(int a,int b){return (t[a].x==t[b].x)?t[a].opt<t[b].opt:t[a].x<t[b].x;}inline void add(int k){for (int i=k;k<=10000000;k+=k&(-k)) tr[k]++;}inline int gs(int k){ int ret=0; for (int i=k;i;i-=i&(-i)) ret+=tr[i]; return ret; }int main(){ scanf("%d%d",&n,&m); for (int i=1;i<=n;++i) { scanf("%d%d",&xx,&yy); xx++;yy++; ++top; rank[top]=top; t[top].opt=0; t[top].x=xx; t[top].y=yy; t[top].ans=0; t[top].tmp=0; } for (int i=1;i<=m;++i) { scanf("%d%d%d%d",&x1,&y1,&x2,&y2); x1++;x2++;y1++;y2++; ++top; rank[top]=top; t[top].opt=1; t[top].x=x1-1; t[top].y=y1-1; t[top].ans=i; t[top].tmp=1; ++top; rank[top]=top; t[top].opt=1; t[top].x=x2; t[top].y=y2; t[top].ans=i; t[top].tmp=1; ++top; rank[top]=top; t[top].opt=1; t[top].x=x2; t[top].y=y1-1; t[top].ans=i; t[top].tmp=-1; ++top; rank[top]=top; t[top].opt=1; t[top].x=x1-1; t[top].y=y2; t[top].ans=i; t[top].tmp=-1; } sort (rank+1,rank+top+1,cmp); for (int i=1;i<=top;++i) { if (!t[rank[i]].opt) add(t[rank[i]].y); else { ans[t[rank[i]].ans]+=t[rank[i]].tmp*gs(t[rank[i]].y); } } for (int i=1;i<=m;++i) printf("%d\n",ans[i]);}
0 0
- BZOJ 1935
- bzoj 1935 && bzoj 4322 离线+树状数组
- [BZOJ ]
- BZOJ****-****
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- bzoj
- bzoj
- BZOJ
- BZOJ
- java中返回值return的使用
- from now on...
- 深刻的理解Fragment生命周期 都在做什么
- C++本质:类的赋值运算符=的重载,以及深拷贝和浅拷贝
- 【华为OJ19】简单错误记录
- BZOJ 1935
- mysql 自定义hash索引
- MapReduce 例子
- Java中HashMap中对value对象进行排序
- iOS推送
- LXH必备技能
- Postfix expressions(Data Structure)
- 用c语言验证哥德巴赫猜想
- webpagetest网站性能分析