1. Title Description: Click to open the link
2. Solving ideas: The problem is solved by scanning method. According to the test instructions description, the [L,i] and [i,r] intervals constitute arithmetic progression, so that l[i],r[i] can be used to maintain the furthest length that can be extended from I to the left and right, if D1 and D2 are not equal, then the answer is l[i]*r[i] summation, otherwise r[i).
3. Code:
#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <iostream> #include <algorithm># include<cassert> #include <string> #include <sstream> #include <set> #include <bitset># include<vector> #include <stack> #include <map> #include <queue> #include <deque># include<cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <ctime># Include<cctype> #include <functional>using namespace std; #define ME (s) memset (s,0,sizeof (s)) typedef long Long ll;typedef unsigned int uint;typedef unsigned long long ull;typedef pair <int, int> p;const int N=100000+10;int L[n],r[n];int a[n];int N,d1,d2;int Main () {while (~scanf ("%d%d%d", &n,&d1,&d2)) {for (int i=0;i< ; n;i++) scanf ("%d", &a[i]); for (int i=0;i<n;i++) {if (i==0| | A[i-1]+d1!=a[i]) l[i]=1; else l[i]=l[i-1]+1; } for (int i=n-1;i>=0;i--) { if (i==n-1| | A[I]+D2!=A[I+1]) r[i]=1; else r[i]=r[i+1]+1; } ll Ans=0; if (D1!=D2) {for (int i=0;i<n;i++) ans+= (LL) l[i]*r[i]; } else {for (int i=0;i<n;i++) ans+=r[i]; } printf ("%i64d\n", ans); }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 5400 Arithmetic Sequence (2015-year School competition 9th)