Count Subarrays With Length Divisible by Distinct Count?

Revision en1, by bihariforces, 2024-01-02 10:09:05

This is a made up problem, but I was wondering if there is a faster way to solve this.

Given an array $$$A$$$ of length upto $$$10^5$$$, count the number of non-empty subarrays of $$$A$$$ whose length is divisible by the number of distinct elements present in it, i.e. $$$ distinctCount(subarray) \mathrel{|} length(subarray) $$$.

I can't think of any useful optimizations, trying to think with lazy segment trees makes it really complex, my only hope is with either Square-root decomposition, or combining two algorithms for $$$O(N\sqrt{N})$$$ solution.

I was thinking in terms of writing it as $$$length = k * distinctCount$$$ for some integer $$$k$$$, then combining two algorithms for $$$k <> \sqrt{N}$$$, but haven't made much progress.

I am curious so do help me.

Tags implementations, data structures, algorithms

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English bihariforces 2024-01-02 10:09:05 805 Initial revision (published)