BZOJ3668[NOI2014] getting up difficulty syndrome
Test instructions
Ask for a number from 0 to M, so that it is the largest after n operations. Operation three kinds: &t, |t, ^t,t for the given number in the operation. n≤100000,m,t≤1000000000
Exercises
First find out the number of 0 after n operations, and then for each bits less than or equal to M from big to small consider if this is 1 is better than 0, if good to make this 1 and let M minus this bits. Because the bits of 1 after n operations is as large as possible, it is correct to consider from the big to the small.
Code:
1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineMAXN 2000005 #defineInc (I,J,K) for (int i=j;i<=k;i++)6 using namespacestd;7 8InlineintRead () {9 CharCh=getchar ();intf=1, x=0;Ten while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} One while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); A returnf*x; - } - Chars[5];intopt[maxn],p[maxn],ans,n,m; the intMain () { -N=read (); M=read (); ans=0; -Inc (I,1, N) { -scanf"%s", s);if(s[0]=='A') opt[i]=0;if(s[0]=='O') opt[i]=1;if(s[0]=='X') opt[i]=2; p[i]=read (); + } -Inc (I,1, N) { + if(opt[i]==0) ans&=p[i];if(opt[i]==1) Ans|=p[i];if(opt[i]==2) ans^=P[i]; A } at for(intI= -; i>=0; i--){ - intk=1<<i;if(k>m)Continue; -Inc (J,1, N) { - if(opt[j]==0) k&=p[j];if(opt[j]==1) K|=p[j];if(opt[j]==2) k^=P[j]; - } - if(! (ans& (1<<i) && (k& (1<<i)) ans|= (1<<i), m-= (1<<i); in } -printf"%d", ans); to}
20160629
BZOJ3668[NOI2014] getting up difficulty syndrome