A12190 | The Fair Nut's getting crazy
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The Fair Nut has found an array $a$ of $n$ integers. We call subarray $l \ldots r$ a sequence of consecutive elements of an array with indexes from $l$ to $r$ , i.e. $a_l, a_{l+1}, a_{l+2}, \ldots, a_{r-1}, a_{r}$ .
No one knows the reason, but he calls a pair of subsegments good if and only if the following conditions are satisfied:
1. 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.
2. 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 \ldots 3; 2 \ldots 5)$ and $(1 \ldots 2; 2 \ldots 3)$ ) — are good, but $(1 \dots 3; 2 \ldots 3)$ and $(3 \ldots 4; 4 \ldots 5)$ — are not (subsegment $1 \ldots 3$ contains subsegment $2 \ldots 3$ , integer $5$ belongs both segments, but occurs twice in subsegment $4 \ldots 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 $10^9+7$ .
No one knows the reason, but he calls a pair of subsegments good if and only if the following conditions are satisfied:
1. 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.
2. 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 \ldots 3; 2 \ldots 5)$ and $(1 \ldots 2; 2 \ldots 3)$ ) — are good, but $(1 \dots 3; 2 \ldots 3)$ and $(3 \ldots 4; 4 \ldots 5)$ — are not (subsegment $1 \ldots 3$ contains subsegment $2 \ldots 3$ , integer $5$ belongs both segments, but occurs twice in subsegment $4 \ldots 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 $10^9+7$ .
输入格式
The first line contains a single integer $n$ ( $1 \le n \le 10^5$ ) — the length of array $a$ .
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $-10^9 \le a_i \le 10^9$ ) — the array elements.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $-10^9 \le a_i \le 10^9$ ) — the array elements.
输出格式
Print single integer — the number of pairs of good subsegments modulo $10^9+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 \ldots 2, 2 \ldots 3)$ .
In the second example, there are four pairs of good subsegments:
- $(1 \ldots 2, 2 \ldots 3)$
- $(2 \ldots 3, 3 \ldots 4)$
- $(2 \ldots 3, 3 \ldots 5)$
- $(3 \ldots 4, 4 \ldots 5)$
In the second example, there are four pairs of good subsegments:
- $(1 \ldots 2, 2 \ldots 3)$
- $(2 \ldots 3, 3 \ldots 4)$
- $(2 \ldots 3, 3 \ldots 5)$
- $(3 \ldots 4, 4 \ldots 5)$
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted