Bzoj 2728 hnoi2012 and non-Gaussian deyuan

Source: Internet
Author: User

Given the number of N in the K-bit binary, how many numbers in the [L, R] range can be obtained through these numbers and non-

First, observe the truth table. We have a Nand A = not.

Then there is not (a NAND B) = A and B

We can make all logical operations, such as or

A or B = Not (not A) and (not B ))

A xor B = (A or B) and (a nand B)

Then we can find a property for bitwise operations.

For one or two digits, if the values of the two digits are the same, the final results of the two digits will be the same no matter how they are calculated.

For example, 10 (1010) and 7 (0111), the first and third places are the same, so no matter how the calculation is done, the two are the same.

Then we will handle this:

For each digit, we enumerate each number. If this digit is 0, we take the non-

Then sum all the numbers

This bitwise is 1, so the sum must be 1. For other bitwise, as long as there are two different numbers, this must be 0.

In the final result, all the bits that are the same as this bit are 1, and the rest are 0.

For each bit, Mark deduplication, and then obtain a linear base to ensure that each bit exists and only exists in one number in the linear base.

Get the result of the binary sequence from greedy to greedy.

1 <= L <= r <= 10 ^ 18 in the description of this question, but the seventh point is L = 0.

# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> # define M 1010 using namespace STD; typedef long ll; int N, K; ll digit, L, R, a [m], basis [70], TOT; bool V [70]; ll get_digit (ll x) {If (x =-1) return-1; // pit ratio !!! Ll now = 0, Re = 0; int I; for (I = 1; I <= tot; I ++) if (now | basis [I]) <= x) Now | = basis [I], re | = (1ll <tot-I); Return re;} int main () {// freopen ("NAND. in "," r ", stdin); // reopen (" NAND. out "," W ", stdout); int I, j; ll now; CIN> N> K> L> r; digit = (1ll <K) -1; for (I = 1; I <= N; I ++) scanf ("% LLD", & A [I]); for (I = K-1 ;~ I; I --) if (! V [I]) {now = digit; For (j = 1; j <= N; j ++) if (a [J] & (1ll <I )) now & = A [J]; elsenow & = ~ A [J] & digit; basis [++ tot] = now; For (j = 0; j <= I; j ++) if (now & (1ll <j) V [J] = 1 ;}cout <get_digit (R)-get_digit L-1) <Endl ;}// LLD


Bzoj 2728 hnoi2012 and non-Gaussian deyuan

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.