JZ junior OJ 2292. [noip universal group 1] interval

Title Description

A sequence of length N a [1], a [2] ... a [N]. For a comprising a [L], a [L + 1] ... a [R] interval [L, R], that if there is a small position W a [K] satisfies all of the numbers are within the interval a [K] multiples, then this interval is legal, and the range of values ​​for the RL, otherwise this section is not legitimate. Now small W would like to know the value of the maximum range value of all legitimate interval is how much, and you have to tell him the left end point of these intervals (if there are multiple intervals equal to the maximum value, then you need to tell him all the left end points) .
 

Entry

A first line number N, the number of values.
The second row of the N positive integers separated by spaces, represents a [1], a [2 ] ... a [N].
 

Export

The first two row numbers x, y, respectively, and a maximum value of the maximum number of the value interval.
The second line of several integers separated by spaces, from small to large maximum output value of the left point range.
 

Sample input

Sample input [1] 
. 5 
. 4. 3. 6. 6. 9 
 
[Sample Input 2] 
30 
1,515,330,930,271,151,520 10 25 30 15 30 20 is 1,525,510,207,716,277,287
 
 

Sample Output

[1] Sample Output 
1. 3 
2 
 [2] Output Sample 
1 13 is 
. 9
 
 

Data range limit

For 30% of the data satisfies N <= 30, a [i ] <= 50
data for 70%, satisfies N <= 3000, a [i ] <= 2000
to 100% of the data satisfies N <= 300000, a [i] <= 2000000
 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                  years [years1 ++] = l;
37              }
 38          }
 39      }
 40      sort (age + 1 , and + 1 + years1);
41      years 1 = single (year + 1 , year + 1 + years 1) - (year + 1 );
42      printf ( " % d% d \ n " , years1, ans2);
43      for ( int i = 1 ; i <= years1; i ++)
44         printf("%d ", ans[i]);
45     return 0;
46 }

Guess you like

Origin www.cnblogs.com/anbujingying/p/11317259.html