BZOJ3668[NOI2014] getting up difficulty syndrome

Source: Internet
Author: User

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

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.