今天主要还是做了wfj大神的题,然后被莫比乌斯函数和KDtree虐的死去活来……
主席树的应用十分广泛,要多灵活变通(如树上路径第k大);
终于弄懂了cdq分治,不得不说czh学长的板子还是有些太过于特殊难策,ljq大神的板子还是好写好调些;
左偏树很水,以后写堆就用他了;
莫比乌斯函数没搞懂,不写;
最后的boss,KDtree,真是调了半天TAT。
其实感觉KDtree思想没有那么难,核心就是把一维二叉平衡树拓展到多维,就这么简单,详见《ACM/ICPC算法基础训练教程》;
但是做了上面的例题简直RE疯了啊啊啊!!!没有数据,网上没标程,简直了……到底是哪里错了……
TOJ4072 3D Birds-Shooting Game
链接:http://acm.tju.edu.cn/toj/show.php?pid=4072
中文题面见《ACM/ICPC算法基础训练教程》。附RE代码。
#include<cmath> #include<queue> #include<cstdio> #include<vector> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define N 10010 #define Q 10010 #define MAX 100010 #define ls (x<<1) #define rs ((x<<1)|1) #define mid ((l+r)>>1) #define RG register #define inf 0x3f3f3f3f #define Inf 99999999999999999LL using namespace std; typedef long long LL; bool id; struct node{ int x,y,z; node(){} node(int _x,int _y,int _z):x(_x),y(_y),z(_z){} bool operator == (const node a) const{ return x==a.x&&y==a.y&&z==a.z; } bool operator < (const node a) const{ if(!id){ if(x==a.x) return y<a.y; return x<a.x; } else{ if(y==a.y) return x<a.x; return y<a.y; } } }dot[N]; struct matrix{ node po; int op,big,v,xl,xr,yl,yr; }mat[N]; int T,n,m,ans,xl,xr,yl,yr; pair<int,int> corre[N]; inline int Max(RG const int &a,RG const int &b){return a>b?a:b;} inline int Min(RG const int &a,RG const int &b){return a>b?b:a;} inline void init(){ n=m=ans=xl=xr=yl=yr=0; memset(dot,0,sizeof(dot)); memset(mat,0,sizeof(mat)); } inline bool inside(node a,node b,node c){ return a.x>=b.x&&a.y>=b.y&&a.x<=c.x&&a.y<=c.y; } inline bool intersect(node a,node b,node c,node d){ return !(a.x>d.x||a.y>d.y||b.x<c.x||b.y<c.y); } inline int gi(){ RG int x=0;RG bool flag=0;RG char c=getchar(); while((c<'0'||c>'9')&&c!='-') c=getchar(); if(c=='-') c=getchar(),flag=1; while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar(); return flag?-x:x; } inline void up(RG int x){ mat[x].xl=Min(Min(mat[ls].xl,mat[rs].xl),mat[x].xl); mat[x].yl=Min(Min(mat[ls].yl,mat[rs].yl),mat[x].yl); mat[x].xr=Max(Max(mat[ls].xr,mat[rs].xr),mat[x].xr); mat[x].yr=Max(Max(mat[ls].yr,mat[rs].yr),mat[x].yr); mat[x].big=Max(Max(mat[ls].big,mat[rs].big),mat[x].big); } inline void build(RG int x,RG int l,RG int r,RG int o){ //cout<<x<<' '<<l<<' '<<r<<' '<<o<<endl; if(l>r) return; id=o; nth_element(dot+l,dot+mid,dot+r); mat[x].po=dot[mid],mat[x].op=o; mat[x].v=mat[x].big=dot[mid].z; mat[x].xl=mat[x].xr=dot[mid].x; mat[x].yl=mat[x].yr=dot[mid].y; //cout<<mat[x].v<<endl; if(l==r) return; build(ls,l,mid,o^1); build(rs,mid+1,r,o^1); up(x); //cout<<mat[x].v<<' '<<mat[x].xl<<' '<<mat[x].yl<<' '<<mat[x].xr<<' '<<mat[x].yr<<endl; } inline void query(RG int x,RG int l,RG int r,node ql,node qr){ //cout<<x<<' '<<l<<' '<<r<<endl; if(l>r||mat[x].big<ans) return; if(inside(node(mat[x].xl,mat[x].yl,0),ql,qr)&&inside(node(mat[x].xr,mat[x].yr,0),ql,qr)){ ans=Max(ans,mat[x].big); return; } if(inside(mat[x].po,ql,qr)) ans=Max(ans,mat[x].v); if(l==r) return; if(intersect(ql,qr,node(mat[ls].xl,mat[ls].yl,0),node(mat[ls].xr,mat[ls].yr,0))) query(ls,l,mid,ql,qr); if(intersect(ql,qr,node(mat[rs].xl,mat[rs].yl,0),node(mat[rs].xr,mat[rs].yr,0))) query(rs,mid+1,r,ql,qr); } inline void modify(RG int x,RG int l,RG int r,node goal){ if(l>r) return; if(mat[x].po==goal){ mat[x].v=mat[x].big=-inf; up(x); return; } if(l==r) return; id=mat[x].op; if(goal<mat[x].po) modify(ls,l,mid,goal); else modify(rs,mid+1,r,goal); up(x); } inline void work(){ init(); n=gi(); //cout<<"n="<<n<<endl; for (RG int i=1;i<=n;++i){ dot[i].x=gi();dot[i].y=gi();dot[i].z=gi(); corre[dot[i].z].first=dot[i].x; corre[dot[i].z].second=dot[i].y; } //cout<<"n="<<n<<endl; build(1,1,n,0); //cout<<"n="<<n<<endl; m=gi(); //cout<<m<<endl; for (RG int i=1;i<=m;++i){ ans=-inf; xl=gi();yl=gi();xr=gi();yr=gi(); //cout<<"hh"<<xl<<' '<<yl<<' '<<xr<<' '<<yr<<endl; query(1,1,n,node(xl,yl,0),node(xr,yr,0)); //cout<<"ans="<<ans<<endl; if(ans==-inf) printf("Where are the birds? "); else{ printf("%d %d %d ",corre[ans].first,corre[ans].second,ans); modify(1,1,n,node(corre[ans].first,corre[ans].second,ans)); } //cout<<"hh"<<endl; } } int main(){ T=gi(); while(T--) work(); return 0; }
祝明天YWJ大神题目自己欧一点
得了吧你就一非洲土著。