From high to low enumeration expected should be the ans highest bit as far as possible to take one. If the number of the highest bit is O, you can get 1 direct update ans Otherwise determine if the bit 1 will burst m will not be added.
#include <cstdio> #include <cstring> #include <cctype> #include <algorithm> using namespace std; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) #define CLR (x,c) memset (X,c, sizeof (x)) int read () {int X=0;char c=getchar (); while (!isdigit (c)) C=getchar (); while (IsDigit (c)) x=x*10+c-' 0 ', C=getchar (); return x; } const int nmax=1e5+5; struct node{int p,x;}; Node Ns[nmax]; int main () {int n=read (), M=read (); Char s[5]; Rep (i,1,n) {scanf ("%s", s); Ns[i].x=read (); if (s[0]== ' A ') ns[i].p=0; else if (s[0]== ' O ') Ns[i].p=1;else ns[i].p=2; } int u,v,tp,ans=0,res=0; Dwn (j,30,0) {tp= (1<<j), u=0,v= (1<<J); Rep (i,1,n) {if (ns[i].p==0) u&= (NS[I].X&TP), v&= (NS[I].X&TP); else if (ns[i].p==1) u|= (NS[I].X&TP), v|= (NS[I].X&TP); else u^= (NS[I].X&TP), v^= (NS[I].X&TP); } if (U) ans+=tp; else if (!u&&v) {if (res+tp<=m) ANS+=TP,RES+=TP; }} printf ("%d\n", ans); return 0; }
3668: [Noi2014] Get up difficulty syndrome time limit:10 Sec Memory limit:512 MB
submit:1755 solved:962
[Submit] [Status] [Discuss] Description
21st century, many people have a strange disease: Get up difficulty syndrome, its clinical manifestations are: Get up hard, get up after the bad spirit. As a young sunshine good teenager, ATM has been insisting on the struggle against getting out of trouble syndrome. By studying the relevant literature, he found the cause of the disease: in the depths of the Pacific Ocean, there is a dragon named DRD, which holds the essence of sleep, can arbitrarily prolong everyone's sleep time. It is because of the activities of DRD, get up difficulty syndrome intensified, at an alarming rate in the world spread. To eradicate the disease, the ATM decided to go to the seabed and destroy the dragon.after all the hardships, the ATM finally came to the place where DRD, ready to start a very arduous battle. DRD has a very special skill, and his defensive warfare line is capable of using certain calculations to change the damage he receives. Specifically, DRD's defensive front is made up of N -Fan defensive doors. Each guard gate consists of an op op and a parameter T, where the operation must be one of the Or,xor,and, and the parameter must be a nonnegative integer. If the attack has not yet passed through the guard Gate, the attack damage will change to x op t. The final DRD is hurt by the opponent's initial attack x in turn through all the n -door defensive doors . due to the limited ATM level, his initial attack can only be an integer between 0 and m (i.e. his initial attack can only be selected in 0,1,...,m , but the attack after the defensive gate is not subject to m restrictions). In order to conserve energy, he hopes that by choosing the right initial attack to make his attack drd the most damage, please help him to calculate how much his attack can damage DRD.
Input
The 1th line contains 2 integers, followed by n,m, to indicate that the DRD has N-Fan guard gates, and the initial attack power of the ATM is an integer between 0 and M. The next n lines, in turn, represent each of the defensive doors. Each row consists of a string op and a non-negative integer t, separated by a space, and the OP is in front, and the OP represents the action of the defensive gate, and T represents the corresponding parameter. n<=10^5
Output
An integer line that represents the maximum amount of damage that DRD is exposed to by an ATM attack.
Sample Input3 10
and 5
OR 6
XOR 7Sample Output1
HINT "Sample Description 1"
The initial attack power that the ATM can choose is 0,1,..., 10.
Assuming initial attack damage is 4, the final attack is calculated as follows
4 and 5 = 4
4 OR 6 = 6
6 XOR 7 = 1
Similarly, we can calculate that the initial attack is 1,3,5,7,9 when the final attack is 0, the initial attack is 0,2,4,6,8,10 when the final attack is 1, so an ATM attack at most causes the DRD to receive a damage value of 1.
0<=m<=10^9
0<=t<=10^9
Must be one of the Or,xor,and
"Operation Interpretation"
In the subject, the player needs to convert the number to binary before the calculation. If the two-digit binary length of the operation is different, the first 0 to the same length. The or is a bitwise OR operation, processing two binary numbers of the same length, two corresponding bits as long as one is 1, then the result value of the bit is 1, otherwise 0. XOR performs a logical XOR or operation on a bitwise XOR or operation, with each bit of the equivalent long binary mode or binary number. If the two corresponding bits are different (dissimilar), the result value of the bit is 1, otherwise the bit is 0. And for bitwise and operations, processing two binary numbers of the same length, two corresponding bits are 1, the result value of this bit is 1, otherwise 0.
For example, we use the decimal number 5 and the decimal number 3 respectively for Or,xor and and operations, the following results can be obtained:
0101 (decimal 5) 0101 (decimal 5) 0101 (decimal 5)
OR 0011 (decimal 3) XOR 0011 (decimal 3) and 0011 (decimal 3)
= 0111 (decimal 7) = 0110 (decimal 6) = 0001 (decimal 1) Source [Submit] [Status] [Discuss]
bzoj3668: [Noi2014] Get up difficulty syndrome