CF145D.Lucky Pair

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Petya has an array a of n integers. The numbers in the array are numbered starting from 1. Unfortunately, Petya has been misbehaving and so, his parents don't allow him play with arrays that have many lucky numbers. It is guaranteed that no more than 1000 elements in the array a are lucky numbers.

Petya needs to find the number of pairs of non-intersecting segments [_l_1;_r_1] and [_l_2;_r_2] (1 ≤ _l_1 ≤ _r_1 < _l_2 ≤ _r_2 ≤ n, all four numbers are integers) such that there's no such lucky number that occurs simultaneously in the subarray a[_l_1.._r_1] and in the subarray a[_l_2.._r_2]. Help Petya count the number of such pairs.

佩佳非常喜欢幸运数字。众所周知,幸运数字是指十进制表示中仅包含幸运数字 4 和 7 的正整数。例如,47、744、4 是幸运数字,而 5、17、467 则不是。

佩佳有一个包含 nn 个整数的数组 aa。数组中的元素编号从 1 开始。不幸的是,佩佳最近表现不好,因此他的父母不允许他玩含有太多幸运数字的数组。题目保证数组 aa 中幸运数字的个数不超过 1000 个。

佩佳需要找出满足如下条件的不相交区间对 [l1;r1][l_1;r_1] 和 [l2;r2][l_2;r_2] 的数量(其中 1 ≤ l1 ≤ r1 < l2 ≤ r2 ≤ n1 \leq l_1 \leq r_1 < l_2 \leq r_2 \leq n,且这四个数均为整数):不存在任何一个幸运数字,它同时出现在子数组 a[l1..r1]a[l_1..r_1] 和子数组 a[l2..r2]a[l_2..r_2] 中。请帮助佩佳计算这样的区间对的数量。

输入格式

The first line contains an integer n (2 ≤ n ≤ 105) — the size of the array a. The second line contains n space-separated integers a__i (1 ≤ a__i ≤ 109) — array a. It is guaranteed that no more than 1000 elements in the array a are lucky numbers.

第一行包含一个整数 nn(2≤n≤1052 \leq n \leq 10^5)—— 数组 aa 的大小。
第二行包含 nn 个以空格分隔的整数 aia_i(1≤ai≤1091 \leq a_i \leq 10^9)—— 数组 aa。
保证数组 aa 中幸运数的个数不超过 1000 个。

输出格式

On the single line print the only number — the answer to the problem.

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

在单行中输出唯一一个数字——即该问题的答案。

请勿在 C++ 中使用 %lld 格式说明符读取或写入 64 位整数。推荐使用 cin、cout 流,或 %I64d 格式说明符。

输入输出样例

  • 输入#1

    4
    1 4 2 4

    输出#1

    9
  • 输入#2

    2
    4 7

    输出#2

    1
  • 输入#3

    4
    4 4 7 7

    输出#3

    9

说明/提示

The subarray a[l..r] is an array that consists of elements a__l, a__l + 1, ..., a__r.

In the first sample there are 9 possible pairs that satisfy the condition: [1, 1] and [2, 2], [1, 1] and [2, 3], [1, 1] and [2, 4], [1, 1] and [3, 3], [1, 1] and [3, 4], [1, 1] and [4, 4], [1, 2] and [3, 3], [2, 2] and [3, 3], [3, 3] and [4, 4].

In the second sample there is only one pair of segments — [1;1] and [2;2] and it satisfies the condition.

子数组 a[l..r]a[l..r] 是由元素 al,al+1,…,ara_l, a_{l+1}, \dots, a_r 构成的数组。

在第一个样例中,共有 9 对满足条件的区间:[1, 1][1, 1] 和 [2, 2][2, 2],[1, 1][1, 1] 和 [2, 3][2, 3],[1, 1][1, 1] 和 [2, 4][2, 4],[1, 1][1, 1] 和 [3, 3][3, 3],[1, 1][1, 1] 和 [3, 4][3, 4],[1, 1][1, 1] 和 [4, 4][4, 4],[1, 2][1, 2] 和 [3, 3][3, 3],[2, 2][2, 2] 和 [3, 3][3, 3],[3, 3][3, 3] 和 [4, 4][4, 4]。

在第二个样例中,只有一对区间满足条件:[1;1][1;1] 和 [2;2][2;2]。

输入解题思路,AI测评打分。不知道怎么写?

首页