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.io.*;importjava.util.*;publicclassSolution{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannerin=newScanner(System.in);intn=in.nextInt();intm=in.nextInt();BitSetb1=newBitSet(n);BitSetb2=newBitSet(n);HashMap<Integer,BitSet>bitSetHM=newHashMap<Integer,BitSet>(){{put(1,b1);put(2,b2);}};for(inti=0;i<m;i++){Stringcmd=in.next();intp=in.nextInt();intq=in.nextInt();switch(cmd){case"AND":bitSetHM.get(p).and(bitSetHM.get(q));break;case"OR":bitSetHM.get(p).or(bitSetHM.get(q));break;case"XOR":bitSetHM.get(p).xor(bitSetHM.get(q));break;case"FLIP":bitSetHM.get(p).flip(q);break;case"SET":bitSetHM.get(p).set(q);break;}System.out.println(bitSetHM.get(1).cardinality()+" "+bitSetHM.get(2).cardinality());if(in.hasNextLine()){in.nextLine();}}in.close();}}
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 →