Test instructions: give you a sequence, there is a function F (l,r) where AI cannot be an AL ... the function value that is divisible by AR is the number of this AI
Thinking: In turn, the AI's interval satisfies such conditions, and then sums
#include <iostream>#include<vector>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;typedef __int64 LL;Const intMAXN =100002;ConstLL MOD = 1e9 +7; Vector<int> cnt[10005];intLEFT[MAXN], RIGHT[MAXN];intNUM[MAXN],VIS[MAXN];intScan () {intres =0, ch, flag =0; if(ch = getchar ()) = ='-')//judging positive or negativeFlag =1; Else if(Ch >='0'&& CH <='9')//get the full numberres = CH-'0'; while(ch = getchar ()) >='0'&& CH <='9') Res= Res *Ten+ CH-'0'; returnFlag? -res:res;}voidInit () { for(inti =1; I <=10005; ++i) { for(intj =1; J <= I; ++j)if(i% J = =0) Cnt[i].push_back (j); }}intMain () {intN; Init (); while(SCANF ("%d", &n)! =EOF) { for(inti =0; I < n; ++i) Num[i] =Scan (); Memset (left,-1,sizeof(left)); Memset (right,-1,sizeof(right)); memset (Vis,-1,sizeof(Vis)); //GET Left for(inti =0; I < n; ++i) { for(intj =0; J < Cnt[num[i]].size (); ++j) {intTMP =Cnt[num[i]][j]; if(vis[tmp]! =-1&& Num[i]% TMP = =0) { if(Left[i] = =-1) Left[i] = vis[tmp] +1; ElseLeft[i] = max (left[i],vis[tmp]+1); }} Vis[num[i]]=i; } //GET Rightmemset (vis,-1,sizeof(Vis)); for(inti = n1; I >=0; --i) { for(intj =0; J < Cnt[num[i]].size (); ++j) {intTMP =Cnt[num[i]][j]; if(vis[tmp]! =-1&& Num[i]% TMP = =0) { if(Right[i] = =-1) Right[i] = vis[tmp]-1; ElseRight[i] = min (right[i],vis[tmp]-1); }} Vis[num[i]]=i; } for(inti =0; I < n; ++i) {if(Left[i] = =-1) Left[i] =0; if(Right[i] = =-1) Right[i] = n1; } LL ans=0; for(LL i =0; I < n; ++i) {LL L= I-left[i] +1; LL R= Right[i]-i +1; Ans= (ans + L * R)%MOD; } printf ("%i64d\n", ans); }}
HDU 5288 OO ' s Sequence