和上一题差不多的方法。。没什么好说的#include #include #include using namespace std;const int maxn = (5e4 + 10) * 4;#define F(x) ((x) / 3 + ((x) % 3 == 1 ? 0 : tb))#defi...
分类:
其他好文 时间:
2014-10-05 12:26:58
阅读次数:
217
平衡二叉树(Balanced binarytree)是由阿德尔森-维尔斯和兰迪斯(Adelson-Velskii and Landis)于1962年首先提出的,所以又称为AVL树。...
分类:
其他好文 时间:
2014-10-05 11:06:48
阅读次数:
261
You are given a list of cities. Each direct connection between two cities has its transportation cost (an integer bigger than 0). The goal is to find the paths of minimum cost between pairs of cities....
分类:
Web程序 时间:
2014-10-05 01:29:57
阅读次数:
289
2588: Spoj 10628. Count on a treeTime Limit:12 SecMemory Limit:128 MBSubmit:1795Solved:371[Submit][Status]Description给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k)...
分类:
其他好文 时间:
2014-10-04 21:24:17
阅读次数:
274
不妨先把所有要求的素数的对的个数写出来f(2)=u(1)G(2)+u(2)*G(2*2)+u(3)*G(2*3)+.....u(k2)*G(2*k2)f(3)=u(1)G(3)+u(2)*G(2*3)+u(3)*G(3*3)+.....u(k3)*G(3*k3)....f(p)=u(1)G(p)+u...
分类:
其他好文 时间:
2014-10-04 19:24:57
阅读次数:
174
首先,这是一道坑题,我拍了几百组数据都是对的,交上去就WA,原因下面会讲。。。一开始我觉得要链剖,后来ZYH说。。。只要dfs序就可以解题。然后,解法嘛。。。就是每个点到根的链都建成一棵线段树,然后发现会MLE,于是就可持久化了所有线段树。在查询的时候呢,先找出两个点a, b的LCA,不妨叫c,然后...
分类:
其他好文 时间:
2014-10-04 17:38:16
阅读次数:
178
题意:
有三种操作:将区间中的所有数置为x;将区间中的所有数加上x;求区间内所有数的平方和。
分析:
先考虑如果不需要求平方和,只是求和,我们需要维护这些数据:addv-区间内的数共同加上的值;setv-区间内的数都置为的值(setv=INF表示不设置);sumv-区间内的数加上addv之前的值。
但这题求的是平方和,似乎不是很好维护。如果只是set操作,还是很好维护的,那么难点就在于add操作了。考虑如下等式:(x+v)^2=x^2+2xv+v^2,x是add操作之前的数,v是add的数,这是一个数的情况...
分类:
其他好文 时间:
2014-10-03 19:23:05
阅读次数:
250
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* Lis...
分类:
其他好文 时间:
2014-10-03 17:21:45
阅读次数:
167
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* ...
分类:
其他好文 时间:
2014-10-03 15:40:04
阅读次数:
186
Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe...
分类:
其他好文 时间:
2014-10-03 13:39:24
阅读次数:
205