You are viewing a single comment's thread. Return to all comments →
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(), m = s.nextInt(); BitSet b1 = new BitSet(n), b2 = new BitSet(n); while (m-- > 0) { String op = s.next(); int i1 = s.nextInt(), i2 = s.nextInt(); switch (op) { case "AND": if (i1 == 1) b1.and(i2 == 1 ? b1 : b2); else b2.and(i2 == 1 ? b1 : b2); break; case "OR": if (i1 == 1) b1.or(i2 == 1 ? b1 : b2); else b2.or(i2 == 1 ? b1 : b2); break; case "XOR": if (i1 == 1) b1.xor(i2 == 1 ? b1 : b2); else b2.xor(i2 == 1 ? b1 : b2); break; case "FLIP": if (i1 == 1) b1.flip(i2); else b2.flip(i2); break; case "SET": if (i1 == 1) b1.set(i2); else b2.set(i2); break; } System.out.println(b1.cardinality() + " " + b2.cardinality()); } } }
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 →