在開頭插一個(gè)我使用紅黑樹最佳的實(shí)踐案例,ABC 431的第三題
Atcoder ABC Contest 431 (日常)
AtCoder Beginner Contest 251
C - Poem Online Judge
Time Limit: 2 sec / Memory Limit: 1024 MiB
Score : 300 points
Problem Statement
Poem Online Judge (POJ) is an online judge that gives scores to submitted strings.There were N submissions to POJ. In the i-th earliest submission, string Si was submitted, and a score of Ti was given. (The same string may have been submitted multiple times.)Note that POJ may not necessarily give the same score to submissions with the same string.
A submission is said to be an original submission if the string in the submission is never submitted in any earlier submission.
A submission is said to be the best submission if it is an original submission with the highest score. If there are multiple such submissions, only the earliest one is considered the best submission.
Find the index of the best submission.
Constraints
1≤N≤10**5
Si is a string consisting of lowercase English characters.Si has a length between 1 and 10, inclusive.
0≤Ti≤10**9
N and Ti are integers.
Input
Input is given from Standard Input in the following format:
N
S1 T1
S2 T2
?
SN TN
Output
Print the answer.
Atcoder允許使用rbtree gem來解題,且rbtree由c ext實(shí)現(xiàn),速度快
我的解
require "rbtree"
tree = RBTree.new
words = {}
n = gets.to_i
i = 0
n.times do
s, t = gets.split
i += 1
unless words.key?(s)
words[s] = 1
unless tree.has_key?(t.to_i)
tree[t.to_i] = i
end
end
end
puts tree.max[1]
建議Leetcode官方學(xué)習(xí)Atcoder允許調(diào)用rbtree,因?yàn)閍lgorithms gem里的CRBTreeMap存在bug。