Codeforces 444B DZY Loves FFT (probability)

Source: Internet
Author: User

Codeforces 444B DZY Loves FFT (probability)

Question connection: Codeforces 444B DZY Loves FFT

Generate arrays a and B based on the algorithm of the question, and then calculate the maximum value of a [I] * B [l-I] for each length of l.

Solution: probability problem. If there is a number of the first 30 values in the enumeration, you can directly output the answer. If not, you can find the maximum value at the position where the B array is 1.

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;const int maxn = 1e5;const int s = 30;int n, d, x, rec[maxn+5];int np, pos[maxn+5];int a[maxn+5], b[maxn+5];int get_next () {    return x = (37LL * x + 10007) % 1000000007;}void init_table () {    for (int i = 0; i < n; i++)        a[i] = i + 1;    for (int i = 0; i < n; i++)        swap(a[i], a[get_next() % (i+1)]);    for (int i = 0; i < n; i++)        b[i] = (i < d ? 1 : 0);    for (int i = 0; i < n; i++)        swap(b[i], b[get_next() % (i+1)]);}void init_pos () {    np = 0;    for (int i = 0; i < n; i++) {        if (b[i])            pos[np++] = i;    }    for (int i = 0; i < n; i++)        rec[a[i]] = i;}int main () {    scanf("%d%d%d", &n, &d, &x);    init_table();    init_pos();    for (int i = 0; i < n; i++) {        bool flag = true;        for (int j = n; j >= n-s; j--) {            if (rec[j] <= i && b[i-rec[j]]) {                flag = false;                printf("%d\n", j);                break;            }        }        if (flag) {            int ans = 0;            for (int j = 0; j < np && pos[j] <= i; j++) {                ans = max(ans, a[i-pos[j]]);            }            printf("%d\n", ans);        }    }    return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.