Codeforces Round # 574 (Div. 2) E. OpenStreetMap queue] [monotone

I, entitled

  OpenStreetMap 

Second, analysis

  For the two-dimensional space to find the minimum interval, then a lot of nice dimension can not be used here can be used to find monotonous queue.

  A first fixed coordinates, and then one-dimensional monotone queue operation, a maintenance interval length $ b $ minimum, an array may be determined $ ans $.

  For the new array, queue operation monotonously another dimension, find the minimum value of $ a * b $. (As English is poor, it became a point of understanding the meaning of section in the upper left corner when reading the title)

  Write when we must pay attention to the second queue monotonous array of objects is a new array.

Three, AC codes

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 #define ll long long
 5 #define Min(a,b) ((a)>(b)?(b):(a))
 6 #define Max(a,b) ((a)>(b)?(a):(b))
 7 const int maxn = 3e3 + 13;
 8 ll h[maxn][maxn];
 9 ll ans[maxn][maxn];
10 
11 int que[maxn];
12 int ql, qr;
13 
14 int main()
15 {
16     //freopen("input.txt", "r", stdin);
17     int n, m, a, b;
18     int x, y, z;
19     while(scanf("%d%d%d%d", &n, &m, &a, &b) != EOF)
20     {
21         int i, j;
22         ll g0;
23         scanf("%I64d%d%d%d", &g0, &x, &y, &z);
24         for(i = 1; i <= n; i++)
25         {
26             for(j = 1; j <= m; j++)
27             {
28                 h[i][j] = g0;
29                 g0 = (1ll*g0*x + y)%z;
30             }
31         }        
32         for(i = 1; i <= n; i++)
33         {
34             ql = 0, qr = 0;
35             for(j = 1; j <= m; j++)
36             {
37                 while(ql < qr && j - que[ql] >= b)
38                     ql++;
39                 while(ql < qr && h[i][j] <= h[i][que[qr-1]])
40                     qr--;
41                 que[qr++] = j;
42                 ans[i][j] = h[i][que[ql]];
43             }
44         }
45         ll tmp = 0;
46         for(j = b; j <= m; j++)
47         {
48             ql = 0, qr = 0;
49             for(i = 1; i <= n; i++)
50             {
51                 while(ql < qr && i - que[ql] >= a)
52                     ql++;
53                 while(ql < qr && ans[i][j] <= ans[que[qr-1]][j])
54                     qr--;
55                 que[qr++] = i;
56                 if(i >= a)
57                     tmp += ans[que[ql]][j];
58             }
59         }
60         printf("%I64d\n", tmp);
61     }
62     return 0;
63 }

 

Guess you like

Origin www.cnblogs.com/dybala21/p/11327534.html