CF1083D.The Fair Nut's getting crazy
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The Fair Nut has found an array a of n integers. We call subarray l…r a sequence of consecutive elements of an array with indexes from l to r , i.e. al,al+1,al+2,…,ar−1,ar .
No one knows the reason, but he calls a pair of subsegments good if and only if the following conditions are satisfied:
- These subsegments should not be nested. That is, each of the subsegments should contain an element (as an index) that does not belong to another subsegment.
- Subsegments intersect and each element that belongs to the intersection belongs each of segments only once.
For example a=[1,2,3,5,5] . Pairs (1…3;2…5) and (1…2;2…3) ) — are good, but (1…3;2…3) and (3…4;4…5) — are not (subsegment 1…3 contains subsegment 2…3 , integer 5 belongs both segments, but occurs twice in subsegment 4…5 ).
Help the Fair Nut to find out the number of pairs of good subsegments! The answer can be rather big so print it modulo 109+7 .
输入格式
The first line contains a single integer n ( 1≤n≤105 ) — the length of array a .
The second line contains n integers a1,a2,…,an ( −109≤ai≤109 ) — the array elements.
输出格式
Print single integer — the number of pairs of good subsegments modulo 109+7 .
输入输出样例
输入#1
3 1 2 3
输出#1
1
输入#2
5 1 2 1 2 3
输出#2
4
说明/提示
In the first example, there is only one pair of good subsegments: (1…2,2…3) .
In the second example, there are four pairs of good subsegments:
- (1…2,2…3)
- (2…3,3…4)
- (2…3,3…5)
- (3…4,4…5)