1935: [Shoi2007]Tree 园丁的烦恼
2015-12-18 16:37
309 查看
离线处理+离散化+BIT
果然读入优化这种东西还是不能懒,没判断负数WA两次TAT。
明明xi,yi都是非负数啊,为毛矩阵坐标就可以是负数了,还能不能好好玩了。
果然读入优化这种东西还是不能懒,没判断负数WA两次TAT。
明明xi,yi都是非负数啊,为毛矩阵坐标就可以是负数了,还能不能好好玩了。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=500000+5; inline int read(){ char ch;int x=0,f=1; while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } struct Node{ int x,y,id,tp; bool operator<(const Node &rhs)const{ if(x!=rhs.x)return x<rhs.x; return y<rhs.y; } }t ,q[N*4]; int hash[N*3],d[N*3],lim,ans ; void add(int x,int v){ for(;x<=lim;x+=(x&-x))d[x]+=v; } int sum(int x){ int ret=0; for(;x>0;x-=(x&-x))ret+=d[x]; return ret; } int main(){ int n,m;n=read();m=read(); int cnt=0; for(int i=1;i<=n;i++){ t[i].x=read();t[i].y=read();t[i].y++; hash[++lim]=t[i].y; } int aj,bj,cj,dj; for(int i=1;i<=m;i++){ aj=read();bj=read();cj=read();dj=read();bj++;dj++; q[++cnt].id=i;q[cnt].x=cj;q[cnt].y=dj;q[cnt].tp=1; q[++cnt].id=i;q[cnt].x=aj-1;q[cnt].y=bj-1;q[cnt].tp=1; q[++cnt].id=i;q[cnt].x=aj-1;q[cnt].y=dj;q[cnt].tp=-1; q[++cnt].id=i;q[cnt].x=cj;q[cnt].y=bj-1;q[cnt].tp=-1; hash[++lim]=dj;hash[++lim]=bj-1; } hash[++lim]=0; sort(t+1,t+1+n);sort(q+1,q+1+cnt);sort(hash+1,hash+1+lim); int j=1; for(int i=1;i<=cnt;i++){ while(j<=n&&t[j].x<=q[i].x){ int y=lower_bound(hash+1,hash+1+lim,t[j].y)-hash; add(y,1); j++; } int y=lower_bound(hash+1,hash+1+lim,q[i].y)-hash; int tmp=sum(y); ans[q[i].id]+=tmp*q[i].tp; } for(int i=1;i<=m;i++) printf("%d\n",ans[i]); return 0; }
相关文章推荐
- 文本域光标操作-selection range
- mac tomcat9
- 文章标题
- MySQL调优系列_日志分析
- 面向对象设计中抽象类与接口的区别
- 技术型问题集合
- android ListView上拉加载更多
- 使用outlook快速步骤功能提高邮件处理效率
- 第16周SHH数据结构-【项目1-验证算法(5)直接选择排序 】
- 新版linux系统设备架构中关于电源管理方式的变更
- [转]strong,weak, retain, assign的区别
- 关于mysql中数据库编码的问题
- WordPress中注册菜单与调用菜单的方法详解
- 关于monkey
- Android中SharedPreferences实现
- Codeforce 467C. George and Job(DP)
- 【实验一】bashrc source nfs tftpd-hpa
- Activity之间的数据交换(简单的数据,类对象,图片)
- 交叉编译使用libjpeg
- 查找excel表最后一行的方法之一