Kuriyama has two arrays: one sorted ascending, one sorted descending. Build prefix sums for both. For type 1 queries (ascending array), use the ascending prefix sums. For type 2 queries (descending array), use descending prefix sums. The trick: the descending array is just the ascending array reversed.
So one prefix array on the sorted input handles both. Query on descending = query on ascending with flipped indices: = . Map carefully.