Bzoj 3671 noi2014 random number generator greedy + violent

Source: Internet
Author: User

Question :..... Take a long look.

First, since the Lexicographic Order of the sorted sequence is the smallest, You must select as few numbers as possible.

Then T is 1 ~ The M * n sequence does not exist. (At the beginning, I missed this condition)

Okay, this question is greedy.
Select the minimum point that is not marked each time, and mark both the lower left and the upper right corner (remember to mark the duplicate break, otherwise it will be down)

Note that if two int values are opened for the 5000*5000 array, the limit is increased. Therefore, the T array must be reused.

The Code ran for 38 seconds. However, the area that can be selected for each row must be continuous. You can maintain one L and one R for each row and get the most value for each update. This Code ran for 28 seconds. slow Qaq

# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> # define M 5010 using namespace STD; typedef long ll; int T [M * m], map [m] [m], L [m], R [m]; ll seed, a, B, c, d; int N, m, Q; inline int rand () {return seed = (A * seed % d + B * seed % d + C) % d;} void kill (INT X, int y) {int I; for (I = 1; I <X; I ++) R [I] = min (R [I], y ); for (I I = x + 1; I <= m; I ++) L [I] = max (L [I], Y);} int main () {int I, J, K, X, Y, flag = 0; CIN> seed> A> B> C> D; cin> m> N> q; for (I = 1; I <= m; I ++) R [I] = N; for (I = 1; I <= m * n; I ++) T [I] = I, swap (T [I], t [rand () % I + 1]); for (I = 1; I <= Q; I ++) {scanf ("% d", & X, & Y); swap (T [X], T [y]);} k = 0; for (I = 1; I <= m; I ++) for (j = 1; j <= N; j ++) map [I] [J] = T [++ K]; for (I = 1; I <= m; I ++) for (j = 1; j <= N; j ++) T [map [I] [J] = I <16 | j; for (I = 1; I <= m * N; I ++) {x = T [I]> 16; y = T [I] & 65535; if (y = L [x] & Y <= R [x]) {If (FLAG) putchar (''); flag = 1; printf ("% d", map [x] [Y]); kill (x, y );}}}


Bzoj 3671 noi2014 random number generator greedy + violent

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.