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