Mathison and the exceptional list

4

1 votes
Medium, Segment Trees
Problem

Mathison has practised different operations that can be performed on lists. Unfortunately, he has found a set of operations that he cannot perform efficiently so he asks for your help.

You start with an empty list, on which you perform N operations. In one operation (e,L,R) you add e to the back of the list and print the number of exceptional subarrays with the length between L and R inclusive, in the current version of the list. An exceptional subarray is defined to be a subarray of the list that contains only unique elements (i.e. no two elements share the same value).

Input
The first line of the input file contains one integer, N, representing the number of operations.
Each of the next N lines contains three space-separated integers e L R, representing the element that is added to the list in this step and the minimum/maximum length of a queried subarray.

Output
The output file will contain N lines. The ith line will contain the number of exceptional subarrays with a length between Li and Ri.

Constraints and notes

  • 1N5×105
  • 0e109
  • 1LN
  • 1RN
  • An exceptional substring is a contiguous subsequence of the list that contains only unique elements (i.e. no two elements share the same value).
Time Limit: 1.3
Memory Limit: 256
Source Limit:
Explanation

There is only one exceptional subarray after the first insertion: 1.
There are three exceptional subarrays after the third insertion: [1,2],[2,4],[1,2,4].
There are six exceptional subarrays after the fifth insertion: [1,2],[2,4],[4,2],[2,1],[1,2,4],[4,3,1].
There is only one exceptional subarray after the sixth insertion: [4,2,1,5].

Editor Image

?