input:interval.in output:interval.out
时间限制: 2000 ms 空间限制: 524288 KB 具体限制
1 #include <bits/stdc++.h> 2 using namespace std; 3 #define mod 1000000007 4 #define ll long long 5 const int N = 300010; 6 int n; 7 int a[N]; 8 int ans1, ans2; 9 int ans[N]; 10 int main() 11 { 12 freopen("interval.in", "r", stdin); 13 freopen("interval.out", "w", stdout); 14 scanf("%d", &n); 15 for (int i = 1; i <= n; i++) 16 scanf("%d", &a[i]); 17 for (int k = 1; k <= n; k++) 18 { 19 int l, r; 20 for (l = k; l >= 1; l--) 21 if(l == 1 || a[l - 1] % a[k] != 0) 22 break; 23 for (r = k; r <= n; r++) 24 if(r == n || a[r + 1] % a[k] != 0) 25 break; 26 if(ans2 < (r - l)) 27 { 28 ans1 = 1; 29 ans[ans1] = l; 30 ans2 = r - l; 31 } 32 else 33 { 34 if(ans2 == (r - l)) 35 { 36 ans[++ans1] = l; 37 } 38 } 39 } 40 sort(ans + 1, ans + 1 + ans1); 41 ans1 = unique(ans + 1, ans + 1 + ans1) - (ans + 1); 42 printf("%d %d ", ans1, ans2); 43 for (int i = 1; i <= ans1; i++) 44 printf("%d ", ans[i]); 45 return 0; 46 }