CF1083D.The Fair Nut's getting crazy
NOI/NOI+/CTSC
通过率:0%
时间限制:4.00s
内存限制:256MB
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.
公平坚果发现了一个包含 n 个整数的数组 a。我们称子数组 l…r 为数组中从下标 l 到 r 的连续元素所构成的序列,即 al,al+1,al+2,…,ar−1,ar。
无人知晓原因,但他将一对子区间称为“好”的,当且仅当满足以下两个条件:
- 这两个子区间不能互相嵌套。也就是说,每个子区间都必须至少包含一个(下标)元素,该元素不属于另一个子区间。
- 这两个子区间相交,且交集中的每个元素在每个子区间中均只出现一次。
例如,设 a=[1,2,3,5,5]。则如下对是“好”的:(1…3; 2…5) 和 (1…2; 2…3);而如下对不是“好”的:(1…3; 2…3)(因为子区间 1…3 包含了子区间 2…3,即发生嵌套),以及 (3…4; 4…5)(因为整数 5 同时属于两个子区间,但在子区间 4…5 中出现了两次)。
请帮助公平坚果计算“好”子区间对的总数!答案可能非常大,请对 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.
第一行包含一个整数 n(1≤n≤105)—— 数组 a 的长度。
第二行包含 n 个整数 a1,a2,…,an(−109≤ai≤109)—— 数组的元素。
输出格式
Print single integer — the number of pairs of good subsegments modulo 109+7.
输出一个整数——好子段对的数量对 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)
在第一个例子中,只有一对好子段:(1…2,2…3)。
在第二个例子中,有四对好子段:
- (1…2,2…3)
- (2…3,3…4)
- (2…3,3…5)
- (3…4,4…5)
输入解题思路,AI测评打分。不知道怎么写?