avatar
w*2
2
01-06-2016 485+765+131 (NSC)
02-09-2016 收到指纹预约
02-19-2016 打指纹
02-24-2016 765 New Card Is Being Produced
PD 03/2012
avatar
a*u
3
应该是要用interval tree。不过如果其他常见题目还没准备好,可以先不专研这个,
有点太小众了
avatar
d*g
4
恭喜! 同NSC, 指纹打了一个月了,EAD还没有批,不知道是不是指纹出了问题。。。
好担心 D:

【在 w*****2 的大作中提到】
: 01-06-2016 485+765+131 (NSC)
: 02-09-2016 收到指纹预约
: 02-19-2016 打指纹
: 02-24-2016 765 New Card Is Being Produced
: PD 03/2012

avatar
b*5
5
interval tree我知道, 但还是做不出less than O(n^2).

【在 a*****u 的大作中提到】
: 应该是要用interval tree。不过如果其他常见题目还没准备好,可以先不专研这个,
: 有点太小众了

avatar
c*e
6
This is my solution.
first, sort the ids in terms of start time in ascending order
second, sort the ids in terms of end time in descending order
if the interval of one id_A falls into the interval of another id_B, then
the start time of id_A should be after that of id_B, and the end time of id_
B should be after that of id_A.
Therefore, we can use two loops to find out the number of ids that fall into
any given id by searching the ordered id sequences.
Time complexity is O(2log(n)+n^2) ~ O(n^2)
For the given example,
http://discuss.leetcode.com/questions/2274/count-number-of-over
Start time sequence: 1 2 5 4 3
End time sequence: 2 5 3 1 4
output:
3 0
4 0
1 1 //id 4 falls in id 1;
5 2 //id 3,4 fall in id 5;
2 3 //id 5,4,3 fall in id 2
avatar
b*5
7
人家是要小于n^2

id_
into

【在 c*****e 的大作中提到】
: This is my solution.
: first, sort the ids in terms of start time in ascending order
: second, sort the ids in terms of end time in descending order
: if the interval of one id_A falls into the interval of another id_B, then
: the start time of id_A should be after that of id_B, and the end time of id_
: B should be after that of id_A.
: Therefore, we can use two loops to find out the number of ids that fall into
: any given id by searching the ordered id sequences.
: Time complexity is O(2log(n)+n^2) ~ O(n^2)
: For the given example,

avatar
x*y
9
interval tree for sure O(nlogn). Check how interval tree gets log(n) time
for inertion and deletion.
avatar
s*n
10
Not for sure...
如果用>表示包含关系,那么如果是这种情况
i1 > i2 > i3 > ... > in
用interval tree的话查询i1要遍历所有n个叶节点,查询i2要遍历至少n-1个节点。。
。以此类推,一共要访问O(n^2)叶节点。

【在 x***y 的大作中提到】
: interval tree for sure O(nlogn). Check how interval tree gets log(n) time
: for inertion and deletion.

avatar
e*8
11
直接单用interval tree的确不行,但是这种partition tree一般好象都可以augment吧
(就是把解决reporting问题的data structure augment成解决counting问题的data
structure),不过我也没想清楚interval tree对这个问题应该怎么augment..
segment tree倒是可以用,但是又总觉得用segment tree+fenwick tree有点杀鸡焉用
割牛刀的感觉...

【在 s****n 的大作中提到】
: Not for sure...
: 如果用>表示包含关系,那么如果是这种情况
: i1 > i2 > i3 > ... > in
: 用interval tree的话查询i1要遍历所有n个叶节点,查询i2要遍历至少n-1个节点。。
: 。以此类推,一共要访问O(n^2)叶节点。

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。