hdu5126 stars
题解:
和二维的比起来差不多。
但是这是四维偏序。
所以搞一下CDQ套CDQ。
CDQ是维度a已经有序,按维度b排序,然后将维度c存入一维数据结构。
所以我们在第一层CDQ中分治处理,将合法的前一半打标记。
然后进入第二层CDQ,处理打标记的点对没打标记的点的影响。
可以说是将两维压成一维。
想法仍然是容斥。
代码:
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- using namespace std;
- #define N 50050
- #define ll long long
- inline int rd()
- {
- int f=,c=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){c=*c+ch-'';ch=getchar();}
- return f*c;
- }
- struct node
- {
- int x,y,z,t,w,k,id;
- int typ;
- node(){}
- node(int x,int y,int t,int w,int k,int i):x(x),y(y),t(t),w(w),k(k),id(i){}
- }p[N<<],tmp[N<<],sec[N<<];
- bool cmpx(node a,node b)
- {
- return a.x<b.x;
- }
- bool cmpid(node a,node b)
- {
- return a.id<b.id;
- }
- int cnt;
- struct PR
- {
- int x,id;
- PR(){}
- PR(int x,int i):x(x),id(i){}
- }Z[N<<];
- bool cmp(PR a,PR b)
- {
- return a.x<b.x;
- }
- int T,Q,typ,tim;
- int kkk[N<<],ct;
- ll ans[N];
- struct BIT
- {
- ll v[N<<];
- void up(int x,ll d)
- {
- if(!x)return ;
- while(x<(N<<))
- v[x]+=d,x+=(x&-x);
- }
- ll down(int x)
- {
- if(!x)return ;
- ll ret = 0ll;
- while(x)
- ret+=v[x],x-=(x&-x);
- return ret;
- }
- }tr;
- void init()
- {
- cnt=ct=;
- tim=;
- }
- void ap(int x,int y,int z,int t,int w,int k)
- {
- cnt++;
- p[cnt] = node(x,y,t,w,k,cnt);
- Z[cnt] = PR(z,cnt);
- }
- void Sort(int l,int r)
- {
- int mid = (l+r)>>;
- int i=l,j=mid+,k=l;
- while(i<=mid&&j<=r)
- {
- while(i<=mid&&tmp[i].y<=tmp[j].y)
- {
- sec[k]=tmp[i];
- i++,k++;
- }
- while(j<=r&&tmp[i].y>tmp[j].y)
- {
- sec[k]=tmp[j];
- j++,k++;
- }
- }
- while(i<=mid)
- {
- sec[k]=tmp[i];
- i++,k++;
- }
- while(j<=r)
- {
- sec[k]=tmp[j];
- j++,k++;
- }
- for(i=l;i<=r;i++)
- tmp[i]=sec[i];
- }
- void cdq2(int l,int r)
- {
- if(l==r)return ;
- int mid = (l+r)>>;
- cdq2(l,mid);cdq2(mid+,r);
- Sort(l,mid);Sort(mid+,r);
- int i,j;
- for(i=l,j=mid+;j<=r;j++)
- {
- while(i<=mid&&tmp[i].y<=tmp[j].y)
- {
- if(tmp[i].typ&&tmp[i].w)tr.up(tmp[i].z,tmp[i].w);
- i++;
- }
- if(kkk[tmp[j].t]&&!tmp[j].typ)ans[kkk[tmp[j].t]]+=1ll*tmp[j].k*tr.down(tmp[j].z);
- }
- for(i=i-;i>=l;i--)
- if(tmp[i].typ&&tmp[i].w)tr.up(tmp[i].z,-tmp[i].w);
- }
- void cdq1(int l,int r)
- {
- if(l==r)return ;
- int mid = (l+r)>>;
- cdq1(l,mid),cdq1(mid+,r);
- sort(p+l,p+mid+,cmpx);
- sort(p+mid+,p+r+,cmpx);
- int i=l,j=mid+,k=l;
- while(i<=mid&&j<=r)
- {
- while(i<=mid&&p[i].x<=p[j].x)
- {
- tmp[k]=p[i],tmp[k].typ=;
- i++,k++;
- }
- while(j<=r&&p[i].x>p[j].x)
- {
- tmp[k]=p[j],tmp[k].typ=;
- j++,k++;
- }
- }
- while(i<=mid)
- {
- tmp[k]=p[i],tmp[k].typ=;
- i++,k++;
- }
- while(j<=r)
- {
- tmp[k]=p[j],tmp[k].typ=;
- j++,k++;
- }
- cdq2(l,r);
- }
- int main()
- {
- T=rd();
- while(T--)
- {
- init();
- Q = rd();
- for(int ax,ay,az,bx,by,bz,i=;i<=Q;i++)
- {
- typ=rd();
- if(typ==)
- {
- ax=rd(),ay=rd(),az=rd();
- ap(ax,ay,az,tim,,);
- }else
- {
- ax=rd(),ay=rd(),az=rd(),bx=rd(),by=rd(),bz=rd();
- tim++,ct++;
- kkk[tim]=ct;
- ax--,ay--,az--;
- ap(ax,ay,az,tim,,-);
- ap(ax,ay,bz,tim,,);
- ap(ax,by,az,tim,,);
- ap(ax,by,bz,tim,,-);
- ap(bx,ay,az,tim,,);
- ap(bx,ay,bz,tim,,-);
- ap(bx,by,az,tim,,-);
- ap(bx,by,bz,tim,,);
- tim++;
- }
- }
- sort(Z+,Z++cnt,cmp);
- for(int las=-,k=,i=;i<=cnt;i++)
- {
- if(las!=Z[i].x)
- {
- las = Z[i].x;
- k++;
- }
- p[Z[i].id].z = k;
- }
- cdq1(,cnt);
- for(int i=;i<=ct;i++)
- printf("%I64d\n",ans[i]);
- for(int i=;i<=ct;i++)
- ans[i]=;
- }
- return ;
- }
hdu5126 stars的更多相关文章
- HDU5126 stars【CDQ分治】*
HDU5126 stars Problem Description John loves to see the sky. A day has Q times. Each time John will ...
- HDU5126 stars(CDQ分治)
传送门 大意: 向三维空间中加点,询问一个三维区间中点的个数. 解题思路: 带修改CDQ,将修改和询问一起插入CDQ分治询问. (询问可以由8个前缀和加减操作实现) 其中第一层CDQ维护x有序. 第二 ...
- HDU5126 stars(cdq分治)
传送门 题意: 先有两种操作,插入和查询,插入操作则插入一个点\((x,y,z)\),查询操作给出两个点\((x_1,y_1,z_1),(x_2,y_2,z_2)\),回答满足\(x_1\leq x\ ...
- [学习笔记]CDQ分治和整体二分
序言 \(CDQ\) 分治和整体二分都是基于分治的思想,把复杂的问题拆分成许多可以简单求的解子问题.但是这两种算法必须离线处理,不能解决一些强制在线的题目.不过如果题目允许离线的话,这两种算法能把在线 ...
- 【HDU5126】 stars k-d树
题目大意:有$m$个操作,分两种:在指定三维坐标内加入一个点,询问指定空间内点的数量. 其中$m≤5*10^{4},1≤x,y,z≤10^9$ 这题几乎就是裸的$k-d$树啊.我们动态维护一棵$k-d ...
- poj 2352 Stars 数星星 详解
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
- POJ 2352 Stars(树状数组)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30496 Accepted: 13316 Descripti ...
- 【POJ-2482】Stars in your window 线段树 + 扫描线
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11706 Accepted: ...
- Java基础之在窗口中绘图——填充星型(StarApplet 2 filled stars)
Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.GeneralPath; @SuppressWarnin ...
随机推荐
- 51nod 1247 可能的路径(gcd)
传送门 题意 略 分析 有以下结论 \(1.(x,y)->(y,x)\) \(2.(x,y)->(a,b)==>(a,b)->(x,y)\) 证明 做如下变换 \((a,b)- ...
- HDU6035:Colorful Tree(树形DP)
传送门 题意 给出一棵最小生成树及每个节点的颜色,询问\(\frac{n(n-1)}2\)条路径的权值和,一条路径的权值为该路径的颜色种数 分析 勉强理解了ftae的做法,但是代码还是不太会,还是太弱 ...
- Codeforces277A 【dfs联通块】
题意: 给出n个人会的语言类型,然后问这n个人里面还需要几个人学习一下语言就可以n个直接互通了.a会1,2,b会2,3,c会4,那么只要C学一下1或者2,或者3就好了...大致就是这个意思. 思路: ...
- 百度编辑器ueditor插件的基本使用
注意:该插件是基于tpframe开发,请在tpframe框架上使用 插件下载地址:https://pan.baidu.com/s/1MOJbd1goQC0Bn5-7HcIdKA 插件下载下来后解压到a ...
- Typora练习测试
目录 一级标题 二级标题 三级标题 一级标题 二级标题 三级标题 这是下划线 删除线 字体加粗ctrl+b 这是倾斜线 1111 牛奶 面包 鸡蛋 包子 蛋糕 测试 牛奶 面包 鸡蛋 电脑 鼠标 键盘 ...
- vs2010中的ADO控件及绑定控件
要在项目中添加某一个ActiveX控件,则该ActiveX控件必须要注册.由于VS2010中,并没有自动注册ADO及ADO数据绑定控件(Microsoft ADO Data Control,Micro ...
- AtCoder Grand Contest 013 E - Placing Squares
题目传送门:https://agc013.contest.atcoder.jp/tasks/agc013_e 题目大意: 给定一个长度为\(n\)的木板,木板上有\(m\)个标记点,距离木板左端点的距 ...
- 接口测试_RESTClient基本使用
火狐浏览器插件RESTClient基本使用. 消息头: Content-Type : application/x-www-form-urlencoded
- 宏 函数 内联函数inline
带参宏有时候可以代替函数作用:优点直接替代,省去函数调用过程的开销:但缺点也是很明显:容易出错,系统不做检查非常容易出错. 改进方案:内联函数:既有带参宏的直接替代(拷贝)的优点,又有系统检查的优点. ...
- PHP使用iconv函数遍历数组转换字符集
/** * 字符串/二维数组/多维数组编码转换 * @param string $in_charset * @param string $out_charset * @param mixed $dat ...