Test instructions
See the surface.
Ideas
Preprocess each a[i] to the left and right of the first divisible its position l[i] and r[i], and then calculate the value of the number of contributions to the answer.
Contribution is multiplying the left and right interval lengths
Reference code:
/ * #pragma warning (disable:4786) #pragma comment (linker, "/stack:0x800000") */#include <cassert>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <sstream>#include <iomanip>#include <string>#include <vector>#include <list>#include <set>#include <map>#include <stack>#include <queue>#include <algorithm>#include <iterator>#include <utility>using namespace STD;Template<classT > t _abs (t N) {return(N <0? -N:N); }Template<classT > t _max (t A, T b) {return(! (A < b)? A:B); }Template<classT > t _min (t A, T b) {return(A < B. a:b); }Template<classT > t sq (t x) {returnx * x; }Template<classT > t gcd (t A, T b) {return(b! =0? Gcd<t> (b, a%b): a); }Template<classT > t LCM (t A, T b) {return(A/gcd<t> (A, b) * b); }Template<classT >BOOLInside (t A, T B, t C) {returnA<=b && b<=c; }#define MIN (A, B) ((a) < (b)? (a): (b))#define MAX (A, B) ((a) > (b)? (a): (b))#define F (i, n) for (int (i) =0; (i) < (n); + + (i))#define REP (i, S, T) for (int (i) = (s);(i) <= (t); + + (i))#define UREP (i, S, T) for (int (i) = (s);(i) >= (t);--(i))#define REPOK (i, S, T, O) for (int (i) = (s);(i) <= (t) && (o); + + (i))#define MEM0 (addr) memset ((addr), 0, sizeof ((addr)))#define MP (x, y) make_pair (x, y)#define REV (S, e) reverse (S, e )#define SET (P) memset (pair,-1, sizeof (p))#define CLR (P) memset (p, 0, sizeof (p))#define MEM (P, v) memset (P, V, sizeof (p))#define CPY (d, s) memcpy (d, S, sizeof (s))#define READ (f) freopen (F, "R", stdin)#define WRITE (f) freopen (F, "w", stdout)#define SZ (c) (int) c.size ()#define PB (x) push_back (x)#define FF First#define SS Second#define LL Long Long#define LD long double#define PII pair< int, int >#define PSI pair< string, int >#define LS u << 1#define RS u << 1 | 1#define Lson L, Mid, U << 1#define Rson Mid, R, u << 1 | 1#define DEBUG (x) cout << #x << "=" << x << EndlConst intINF =0x3f3f3f3f;Const DoubleEPS =1e-9;Const intMAXN =1e5+5;Const intMoD =1e9+7;intR[MAXN],L[MAXN];intA[MAXN];STD:: vector<int>pos[10010];intNvoidInit () {Rep (I,0,10005) Pos[i].clear (); Rep (I,0, N-1) {L[i] =0; R[i] = n-1;}}voidSolve () {Rep (I,0, N-1){ for(intj = A[i]; J <=10000; J + = A[i]) {intLen = Pos[j].size (); Rep (K,0, len-1){intx = Pos[j][k];if(x = = i)Continue;Else if(x > I) L[X] = max (l[x],i+1);ElseR[x] = min (r[x],i-1); } } }}intMain () {//read ("In.txt"); while(scanf("%d", &n)!=eof) {init (); Rep (I,0, N-1){scanf("%d", &a[i]); Pos[a[i]].push_back (i); } solve (); ll ans =0; Rep (I,0, N-1){//debug (L[i]); //debug (R[i]);ll L = I-l[i] +1LL ll r = R[i]-i +1LL Ans = (ans + (l * r)% MoD)% MoD; }cout<< ans << Endl; }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hdu 5288 (pretreatment + brute force) OO ' s Sequence