BZOJ 3704 (GRST of Hao engine oil-maintenance structure greedy solution)
3704: GRSTTime Limit of Hao's oil: 10 Sec Memory Limit: 1024 MB
Submit: 47 Solved: 15
[Submit] [Status] Description
Hao has a good oil, and he is the focus of the legend. Now Hao has obtained a n-long GRST card (in mod 4), which is intended to serve as a birthday gift for oil (not in February ). However, Hao knows that his oil is a god, and as a digital controller, he will only like the specific sequence. But Hao is not afraid. He can use Fiat once (his favorite oil moves) and add all the numbers in a certain range to 1. If a number is 3, then the value after + 1 is 0. However, Hao's magic power is limited. He asked how many times Fiat would be used to reach the final sequence B from initial sequence.
Input
The first line is a positive integer n, indicating the length of GRST.
In the next two rows, n values in each line represent ai bi.
Output
Only a number, that is, how many times Fiat is used at least.
Sample Input3
0 2 1
1 0 2
Sample Output2
HINT
Data scale and conventions
Example: Use Fiat for the interval [1, 2] for the first time. Use Fiat for the second interval [2, 3. N <= 10000000, 0 <= ai, bi <= 3
Source
The number of times per unit % 4 is determined as c1.
If we can only operate on [a, n], then the height of each segment is determined and monotonically increased as c
Split it into d, then d records {0, 1, 2, 3}
Consider the sequence ci, ci + 3, c [I + 2]. Monotonic increasing... Cn. At this time, ans = cn
If changed to ci, ci-1, c [I + 2] -4..cn-4 at this time ans '= ans-3 ([c [I + 1], n] reduces 4, but more [ci, ci])
Analysis of 3, 2, and 1 cases is performed successively to obtain the greedy solution after maintenance.
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Using namespace std; # define For (I, n) for (int I = 1; I <= n; I ++) # define Fork (I, k, n) for (int I = k; I <= n; I ++) # define Rep (I, n) for (int I = 0; I
= 0; I --) # define Forp (x) for (int p = pre [x]; p = next [p]) # define Forpiter (x) for (int & p = iter [x]; p = next [p]) # define Lson (x <1) # define Rson (x <1) + 1) # define MEM (a) memset (a, 0, sizeof (a); # define MEMI (a) memset (a, 127, sizeof ()); # define MEMi (a) memset (a, 128, sizeof (a); # define INF (2139062143) # define F (4) # define MAXN (10000000 + 10) long mul (long a, long B) {return (a * B) % F;} long add (long a, long B) {return (a + B) % F;} long sub (long a, long B) {return (a-B + (a-B) /F * F + F) % F;} int sub (int a, int B) {return (a-B + (a-B)/F * F + F) % F;} typedef long ll; int n, a [MAXN], B [MAXN], c [MAXN], d [MAXN], f [MAXN]; // number of times that sequence a and B are maintained in the I cell c and c split sequence d, f is the height of c/4 int decrease (int h) // h: if the c sequence contains p, p + h, it is maintained as p, the number of magic times reduced by p + H-4 is {int dec_time = 0; For (I, n) if (dec_time
C [I]) c [I] + = 4; d [I] = c [I]-c [I-1]; f [I] = c [I]/4;} // For (I, n) cout <