Hdu 5288 OO ' s Sequence 2015 + Small League a problem

Source: Internet
Author: User

OO ' s SequenceTime limit:4000/2000 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): 1751 Accepted Submission (s): 632


Problem Descriptionoo has got a array a of size n, defined a function f (l,r) represent the number of I (L&LT;=I&LT;=R), t Hat there ' s no J (l<=j<=r,j<>i) satisfy AI mod aj=0,now OO want to know ∑ i = 1 n ∑j=in F (I,J) mod  ( ten 9 +7).

Inputthere is multiple test cases. Please process till EOF.
In each test case:
First Line:an integer n (n<=10^5) indicating the size of array
Second line:contain N numbers ai (0<ai<=10000)

Outputfor each tests:ouput a line contain a number ans.
Sample Input
51 2 3) 4 5

Sample Output
23

Authorfzuacm
Source2015 multi-university Training Contest 1
Recommendwe has carefully selected several similar problems for you:5299 5298 5297 5296 5295 Test instructions is simple: Ask how many AI have satisfied the condition in any interval if According to the test instructions program should write: four-layer loop--(do not timeout to eat the keyboard) although the final optimization to N^2/2 also time-out data is too large
 #include <stdio.h>int main () {int n,i,j,k,kk,a[100050];        while (scanf ("%d", &n)!=eof) {for (i=1; i<=n; i++) scanf ("%d", &a[i]);        Long Long suma=0;                 For (I=1, i<=n; i++) {for (j=i; j<=n; J + +) {for (k=i; k<=j; k++)//equivalent to I                    {int flag=0;                        for (kk=i; KK <= J; kk++)//equivalent to J {if (a[k]%a[kk] = = 0 && k!=kk)                            {flag=1;                        Break                        }} if (flag!=1) {suma++;                    suma%=100000007;            }} printf ("%d%d=%d%d=%d\n", I,j,a[i],a[j],suma);    }} printf ("%i64d\n", Suma); }}
Brain Hole big Open: Change a thought is not test instructions beg is to find those interval can satisfy the AI value exists? Which means that AI can provide several answers.
Defines two arrays L R represents the left and right of the number of I
The position of the number closest to his value and the value is the a[i] factor
So the first number I can provide is the answer (r[i]-i) * (l[i]-i)
In fact, this method has a loophole if I give you 10w 1 program on my knees ╮(╯▽╰)╭ no such data so be assured to do it boldly
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include < math.h>using namespace Std;const int M = 10e5 + 5;const Long mod = 1e9+7;int vis[m],a[m],l[m],r[m];int main () {int n    ;        while (~SCANF ("%d", &n)) {memset (l,0,sizeof (l));        Memset (r,0,sizeof (R));        memset (vis,0,sizeof (VIS));            for (int i = 1;i <= n; ++i) {scanf ("%d", &a[i]);            R[i] = n+1;                    for (int j = a[i];j <= 10000; j+=a[i])//Find the nearest factor {if (Vis[j]) {                    R[VIS[J]] = i;                VIS[J] = 0;        }} Vis[a[i]] = i;        } memset (Vis,0,sizeof (VIS)); for (int i = n;i >= 1;-i) {for (int j = a[i];j <= 10000; J+=a[i]) {if (                    Vis[j]) {L[vis[j]] = i;                VIS[J] = 0;            }} Vis[a[i]] = i;        } long long ans = 0;        for (int i = 1;i <= n; ++i) {ans = ((ans + (long Long) (r[i]-i) * (Long Long) (I-l[i])%mod);    } printf ("%i64d\n", ans); }}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hdu 5288 OO ' s Sequence 2015 + Small League a problem

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.