一棵树,求每个结点的子树中有几个数是小于这个数的dfs会进入一个点一次,出一个点一次,中间经过的点都是它的子树中的点,所以,进入的时候统计一遍,出来的时候统计一遍,两个结果相减就可以了纯dfs会爆栈,要模拟栈。不过,不模拟栈也可以过,在网上看到c++可以设置栈的大小,所以把栈空间设置的大一点直接dfs做就可以了View Code #pragma comment(linker,"/STACK:100000000,100000000")#include<cstdio>#include<cstring>const int maxn = 100010;str Read More
posted @ 2012-02-13 20:47
Because Of You
Views(747)
Comments(2)
Diggs(0)
线段树做法,成段求和,单点更新View Code #include<cstdio>#include<cstring>#include<map>#include<algorithm>using namespace std;const int maxn = 50010;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1__int64 sum[maxn<<2];struct node{ int l,r,id;}p[200010];map<int,int> ha Read More
posted @ 2012-02-13 14:32
Because Of You
Views(401)
Comments(0)
Diggs(0)
离线处理询问,即先记录下所有询问用map将当前的值映射到一个下标,如果以前已经映射过了,则在树状数组中取消在上一次的位置的记录再在当前位置加入当前值,这样的话对于每个询问便可以先更新再查询,离线记录结果View Code #include<cstdio>#include<cstring>#include<map>#include<algorithm>using namespace std;const int maxn = 50010;__int64 c[maxn];struct node{ int l,r,id;}p[200010];map< Read More
posted @ 2012-02-13 13:52
Because Of You
Views(610)
Comments(0)
Diggs(0)

浙公网安备 33010602011771号