HDU - 5126 stars (CDQ分治)】的更多相关文章

题目链接 给n个操作, 第一种是在x, y, z这个点+1. 第二种询问(x1, y1, z1). (x2, y2, z2)之间的总值. 用一次cdq分治可以将三维变两维, 两次的话就变成一维了, 然后最后一维用树状数组维护. 对于每个询问, 相当于将它拆成8个点. 注意第二次cdq分治的时候l可能小于r. 所以这里的return条件是l <= r而不是l == r. 找了好久... #include <bits/stdc++.h> using namespace std; #defin…
题目链接 题目大意:一共有Q(1<=Q<=50000)组操作,操作分为两种: 1.在x,y,z处添加一颗星星 2.询问以(x1,y1,z1)与(x2,y2,z2)为左上和右下顶点的矩形之间的星星数 所有坐标取值范围均为[1,1e9] 思路:由于坐标取值范围太大(即使离散化后也很大),3维的数组肯定开不下,所以只能另辟蹊径. 解法一(两重CDQ+树状数组,需将z坐标离散化): 1)将每个查询操作拆分为8个(容斥),将所有操作放入一个数组qr中 2)将所有操作按时间排序(其实不用,因为读入的顺序就…
Shell Necklace Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 647    Accepted Submission(s): 287 Problem Description Perhaps the sea‘s definition of a shell is the pearl. However, in my view,…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5126 思路:支持离线,那么我们可以用两次CDQ分治使四维降为二维,降成二维后排个序用树状数组维护下就好了 实现代码: #include<bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; ; int ans[M],c[M]; struct node { int x,y,z; int kind,id; node(){} no…
Sean owns a company and he is the BOSS.The other Staff has one Superior.every staff has a loyalty and ability.Some times Sean will fire one staff.Then one of the fired man’s Subordinates will replace him whose ability is higher than him and has the h…
Mr. Zstu and Mr. Hdu are taking a boring class , Mr. Zstu comes up with a problem to kill time, Mr. Hdu thinks it’s too easy, he solved it very quickly, what about you guys? Here is the problem: Give you two sequences L1,L2,...,Ln and R1,R2,...,Rn. Y…
题目大意:略 题目传送门 四维偏序板子题 把插入操作和询问操作抽象成$(x,y,z,t)$这样的四元组 询问操作拆分成八个询问容斥 此外$x,y,z$可能很大,需要离散 直接处理四维偏序很困难,考虑降维 而$t$这一维有一个神奇的性质,任意两个四元组的$t$互不相同,是最好处理的,所以尽量保证$t$这一维也出现在降维之后的$cdq$分治里 外层把所有四元组按$x$排序,回溯按$t$排序 现在要处理左区间对右区间的影响了,把左区间里的所有四元组打上$0$标记,右区间里的所有四元组打上$1$标记 只…
传送门 大意: 向三维空间中加点,询问一个三维区间中点的个数. 解题思路: 带修改CDQ,将修改和询问一起插入CDQ分治询问. (询问可以由8个前缀和加减操作实现) 其中第一层CDQ维护x有序. 第二层CDQ维护y有序并且将z离线处理完更新答案. 注意要将原数组的辅助数组推入第二层CDQ否则会将顺序毁坏. 代码: #include<cstdio> #include<cstring> #include<algorithm> ; ; struct data{ int t;…
题目传送门 题意:在一个星空中,按着时间会出现一些点,现在john想知道,在某个时间内有多少个星星是的坐标是满足条件的.(x1<=x<=x2, y1 <= y <= y2, z1 <= z <= z2).题解:先简化问题,如果我们就统计出现所有 x <= x2 , y <= y2, z <= z2的点的话,这就是一个4维偏序题. 对于这个统计点数来说, 我们先按照题目给定点的顺序来进行CDQ, 这样在CDQ内只有左边的添加点会对右边的询问点产生影响,然…
Problem Description Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given…