Hdu5288OO's Sequence

Source: Internet
Author: User

Hdu5288OO's Sequence
// Give a sequence
// Define the f (l, r) function as the range [l, r]
// The number ai is not a multiple of any other number aj in this range.
// Calculate the sum of all f (l, r)
// Find the leftmost interval l [I] And rightmost interval r [I] for each number a [I]
// Include a [I] and make a [I] meet the condition as (I-l [I] + 1) * (r [I]-I + 1)
// For each r [I], traverse from left to right
// Pre [I] indicates the last position of I
// For a number a [I], enumerate all its multiples
// Find the corresponding position on the left of the Cluster. r [pre [j] = I-1;
// Similarly, l [I] can be obtained.
# Include
# Include
# Include
Using namespace std;
Const int maxn = 100010;
Const int mod = 1e9 + 7;
Int a [maxn];
Typedef _ int64 ll;
Ll last [maxn];
Ll pre [maxn];
Ll l [maxn];
Ll r [maxn];
Int main ()
{
// Freopen(in.txt, r, stdin );
Int n;
While (~ Scanf (% d, & n ))
{
Memset (last, 0, sizeof (last ));
Memset (pre, 0, sizeof (pre ));
For (ll I = 1; I <= n; I ++)
{
L [I] = 1; r [I] = n;
Scanf (% d, & a [I]);
For (ll j = a [I]; j <maxn/10; j + = a [I])
If (pre [j]! = 0 & r [pre [j] = n)
R [pre [j] = I-1;
Pre [a [I] = I;
}
For (ll I = n; I> = 1; I --)
{
For (ll j = a [I]; j <maxn/10; j + = a [I])
If (last [j]! = 0 & l [last [j] = 1)
L [last [j] = I + 1;
Last [a [I] = I;
}
Ll ans = 0;
For (ll I = 1; I <= n; I ++)
Ans = (ans + (I-l [I] + 1) % mod) * (r [I]-I + 1) % mod) % mod;
Printf (% I64d, ans );
}
Return 0;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.