[Explanations] minimum

Title Description

It has a length \ (n-\) sequence, the initial sequence number are all \ (2 ^ {31} -1 \) .

There \ (m \) operations, the \ (I \) operations for the first sequence \ (a_i \) number of modifications to \ (B_i \) .

- recording \ (I \) minimum time after the operation sequence of \ (S_I \) , you need to output \ (\ SUM \ limits_. 1} = {I ^ m S_I \ 10099 Times ^ I \) .

\ (a_i \) and \ (b_i \) is determined by the following methods:

输入整数 \(x_0\)\(x_1\)\(a\)\(b\)\(c\),令 \(x_i=(ax_{i-2}+bx_{i-1}+c) \bmod 2^{32}\quad (i\ge 2)\),则 \(a_i=\left\lfloor\dfrac{x_{2i-1}}{4}\right\rfloor \bmod n\)\(b_i=\left\lfloor\dfrac{x_{2i}}{4}\right\rfloor\)

Input Format

Row seven integer \ (n-\) , \ (m \) , \ (x_0 \) , \ (x_1 \) , \ (A \) , \ (B \) , \ (C \) .

Output Format

A row of integer answer.

data range

Test time limit \ (1000 \ \ mathrm MS {} \) , space constraints \ (256 \ \ mathrm MiB} {\) .

  • For \ (10 \% \) data, \ (. 1 \ n-Le, m \ Le 1000 \) ;
  • For \ (50 \% \) data, \ (. 1 \ n-Le, m \ Le. 5 ^ 10 \) ;
  • For \ (100 \% \) data, \ (. 1 \ Le n-, m \ Le 10 ^. 7 \) , \ (x_0 \) , \ (x_1 \) , \ (A \) , \ (B \) , \ (C \) in \ (\ left [0,2 ^ { 31} -1 \ right) \) uniformly random.

analysis

Note that this problem requires a small operation, so we have to consider some of the more daring approach.

\ (\ Mathtt {10 \ pts} \)

Very simple, recording an array, each modified subsequent scan again violence minimum complexity \ (\ Theta (. 1) - \ Theta (n-) \) , firmly timeout.

\ (\ Mathtt {50 \ pts} \)

It is also very simple, just set a \ (\ mathcal {O} ( \ log n) \) data structure messing line.

\ (\ Mathtt {100 \ pts} \)

The thought of it a little difficult.

According to the data range, we most probably to design a query \ (\ Theta (1) \ ) algorithm. That is a simple modification \ (\ Theta (1) \) , query \ (\ Theta (1) \) .

After the brain plundered it, modify it seems to support, query, modify is \ (\ Theta (1) \ ) is the only violent.

But in general the subject, the cancer will be the topic of design data card violent people, to make it run very unresponsive at query time.

But ...... we found this problem operations are pseudo-randomly generated. Is ......

Consider this algorithm:

Maintenance array \ (A \) , records \ (I \) value of a bit \ (A_i \) .

Review: directly modify \ (A_i \) ;

Inquire:

  • If the position is not where the minimum value, the minimum and update their location.

  • If so, then the minimum update violence.

A pseudo-random nature of changes to the minimum value of the probability \ (\ dfrac {{n-m}} \) , then the complexity of the mathematical expectation of
\ [\ begin {aligned} E (x) & = \ dfrac {m} {n} \ times \ mathcal { O} (n) + \ left (m- \ dfrac {m} {n} \ right) \ times \ mathcal {O} (1) \\ & = \ mathcal {O} ( m) + \ mathcal {O} (m) \\ & = \ mathcal {O} (m) \ end {aligned} \]

By this question.

Code

Incidentally, this question a little card ...... open space long longon the bombing.

#include <cstdio>
#include <climits>
using namespace std;

typedef unsigned int ui;
const int max_n = 10000000;
const ui mul = 10099;

ui nums[max_n];

int main()
{
    int n, m, min_pos = -1;
    ui x0, x1, a, b, c, ans = 0, tk = 1, xt, ai, bi, min_val = INT_MAX;
    
    scanf("%d%d%u%u%u%u%u", &n, &m, &x0, &x1, &a, &b, &c);
    
    for (int i = 0; i < n; i++)
        nums[i] = INT_MAX;
    
    for (int i = 0; i < m; i++)
    {
        ai = (x1 / 4) % n;
        
        xt = a * x0 + b * x1 + c;
        bi = xt / 4, x0 = x1, x1 = xt;
        
        xt = a * x0 + b * x1 + c;
        x0 = x1, x1 = xt;
        
        nums[ai] = bi;
        if (ai == min_pos && bi > min_val)
        {
            min_val = INT_MAX, min_pos = -1;
            for (int i = 0; i < n; i++)
                if (nums[i] < min_val)
                {
                    min_val = nums[i];
                    min_pos = i;
                }
        }
        else if (bi < min_val)
        {
            min_val = bi;
            min_pos = ai;
        }
        
        tk *= mul;
        ans += tk * min_val;
    }
    
    printf("%u\n", ans);
    
    return 0;
}

postscript

This question tells us a very interesting reason - the greater the complexity, the broader the scope of application.

Likewise, a small degree of complexity, the scope will be smaller.

When the problem solving, generally select a suitable algorithm, i.e., within the scope of the subject, and the complexity is better. This question is a good example.

Guess you like

Origin www.cnblogs.com/5ab-juruo/p/solution-20200229-min.html