[HDOJ5288] OO ' s Sequence

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5288


Converts the number of intervals from 1 to n that can be divisible by a[i].
Find the nearest A[i] L and R, which can be divisible by a[i], because left or right inevitably contains L and R
If [l,i] has x numbers, [i,r] has y numbers, then A[i's contribution is (x+1) * (y+1)
A[i] The contribution of ANS to the synthesis
The number of nearest a[i] that can be divisible by a[i)

1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <algorithm>5#include <iostream>6#include <cmath>7#include <queue>8#include <map>9#include <stack>Ten#include <list> One#include <vector> A  - using namespacestd; -  theInlineintMaxintAintb) { -     returna > B?a:b; - } -  + Const intMAXN =100010; - Const intMoD =1000000007; + intA[MAXN]; A intS[MAXN]; at intL[MAXN]; - intR[MAXN]; - intN; - Long Longans; -  - voidLeft () { in     intm =0; -memset (s),0,sizeof(s)); to      for(inti = n; I >=1; i--) { +m =Max (M, A[i]); -          for(intj = A[i]; J <= M; j+=A[i]) { the             if(S[j] && L[s[j]] <i) { *L[S[J]] =i; $             }Panax NotoginsengS[a[i]] =i; -         } the     } + } A  the voidRight () { +     intm =0; -memset (s),0,sizeof(s)); $      for(inti =1; I <= N; i++) { $m =Max (M, A[i]); -          for(intj = A[i]; J <= M; j+=A[i]) { -             if(S[j] && r[s[j]] >i) { theR[S[J]] =i; -             }WuyiS[a[i]] =i; the         } -     } Wu } - intMain () { AboutFreopen ("inch","R", stdin); $      while(~SCANF ("%d", &N)) { -Ans =0; -          for(inti =1; I <= N; i++) { -scanf"%d", &a[i]); AL[i] =0; +R[i] = n +1; the         } - Right (); $ Left (); the         //for (int i = 1; I <= n; i++) { the         //printf ("%d%d%d\n", L[i], a[i], r[i]); the         // } the          for(inti =1; I <= N; i++) { -Ans = (ans + ((i-l[i))% mod * (R[i]-i)% MoD)%MoD; in         } theprintf"%i64d\n", ans); the     } About}

[HDOJ5288] OO ' s Sequence

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.