CSES Distinct Values Queries

I used Mo’s Algorithm for this problem but I am getting TIME LIMIT EXCEEDED for one test case. Rest are getting accepted. This is after doing coordinate compression on the input array.

Here’s my code (starts from line 42): https://cses.fi/paste/ec649550a7cf002116171a/
Problem: https://cses.fi/problemset/task/1734/

Can anyone please have a look and tell me if I am missing anything?

I figured it out. My coordinate compression step was the bottleneck. This one led to all AC https://codeforces.com/blog/entry/84164?#comment-716682