We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.util.Scanner;importjava.util.BitSet;publicclassSolution{publicstaticvoidmain(String[]args){Scannerscan=newScanner(System.in);intN=scan.nextInt();BitSet[]B=newBitSet[]{newBitSet(N),newBitSet(N)};for(inti=scan.nextInt();i>0;i--){scan.nextLine();// skip to next lineStringop=scan.next();intm=scan.nextInt()-1;intn=scan.nextInt();switch(op){case"AND"->B[m].and(B[n-1]);case"OR"->B[m].or(B[n-1]);case"XOR"->B[m].xor(B[n-1]);case"FLIP"->B[m].flip(n);case"SET"->B[m].set(n);}System.out.printf("%d %d\n",B[0].cardinality(),B[1].cardinality());}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java BitSet
You are viewing a single comment's thread. Return to all comments →