标签:
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #include<iostream> 5 #include<algorithm> 6 using namespace std; 7 const int N = 211100; 8 const int oo = 0x3f3f3f3f; 9 long long al[N], ar[N], as[N], n; // al数组存从左边到这个点一直满足的+d1的数有几个,ar是往右边数满足+d2的有几个。 10 int main() 11 { 12 long long d1, d2, i, ans; 13 while(~scanf("%lld %lld %lld", &n, &d1, &d2)) 14 { 15 for(i = 1; i <= n; i++) 16 scanf("%lld", &as[i]); 17 al[1] = ar[n] = 1; 18 for(i = 2; i <= n; i++) 19 if(as[i] == as[i-1]+d1) 20 al[i] = al[i-1]+1; 21 else al[i] = 1; // 只要间隔,不满足了那么连续的就是1个,它自身 22 for(i = n-1; i >= 1; i--) 23 { 24 if(as[i]+d2 == as[i+1]) 25 ar[i] = ar[i+1]+1; 26 else ar[i] = 1; 27 } 28 ans = 0; 29 for(i = 1; i <= n; i++) 30 { 31 if(d1 == d2) ans += al[i]; // 如果d1,d2相等,al直接相加 32 else ans += al[i]*ar[i]; // if不等,就等于两者相乘,即间隔种类数 33 } 34 printf("%lld\n", ans); 35 } 36 return 0; 37 }
标签:
原文地址:http://www.cnblogs.com/Tinamei/p/4740409.html