We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Triple sum
- Discussions
Triple sum
Triple sum
Sort by
recency
|
220 Discussions
|
Please Login in order to post a comment
Used set to remove duplicates and create order. Put data back into vectors to retrieve indices for upper bound checks.
javascript
My algorithm works as follows:: 1. remove duplicates from all vectors (generate sets, then recreate vectors); note that the vectors are now sorted because std::set is an ordered collection 2. for all elements q in B, find the number of elements r in C such that q <= r using binary search, and store the results in vector. Also, generate a prefix sum of that vector starting from its end. 3. for all elements p in A, find the first element q in B such that p <= q. Simply add all triplets with q' >= q in B, that are now stored in the prefix sum array of B.
JS all pass
Completely unnecessary Treap implementation in C++
This can be solved in 2 lines with python, but why do it when we can implement a binary search tree in C++ ourselves :)
Python:
C++: