You are given two separate algorithmic problems.
Given an integer array nums of length n, for each index i compute the number of indices j > i such that nums[j] < nums[i].
nums
(may contain duplicates and negative values)
ans
of length
n
, where
ans[i]
is the count of smaller elements strictly to the right of
i
1 ≤ n ≤ 10^5
,
|nums[i]| ≤ 10^9
O(n log n)
), and be ready to discuss complexity and edge cases.
You are given n integers a1, a2, ..., an (1 ≤ n ≤ 10^5, 0 ≤ ai ≤ 10^9). Define the function
F(i, j) = ai XOR a(i+1) XOR ... XOR aj
for
1 ≤ i ≤ j ≤ n
.
Count the number of index triplets (x, y, z) with 1 ≤ x ≤ y ≤ z ≤ n such that:
F(x, y) XOR F(y, z) > F(x, z)
.
Notes:
XOR
is the bitwise exclusive-or.
O(n^3)
enumeration is not acceptable for the given constraints).