You are viewing a single comment's thread. Return to all comments →
import java.util.*; public class Solution { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); BitSet b1 = new BitSet(n); BitSet b2 = new BitSet(n); int m = scan.nextInt(); for (int i=0; i<m; i++) { String opr = scan.next(); int x = scan.nextInt(); int y = scan.nextInt(); if (opr.equalsIgnoreCase("AND")) { if (x == 1 && y == 2) b1.and(b2); if (x == 2 && y == 1) b2.and(b1); } else if (opr.equalsIgnoreCase("OR")) { if (x == 1 && y == 2) b1.or(b2); if (x == 2 && y == 1) b2.or(b1); } else if (opr.equalsIgnoreCase("XOR")) { if (x == 1 && y == 2) b1.xor(b2); if (x == 2 && y == 1) b2.xor(b1); } else if (opr.equalsIgnoreCase("FLIP")) { if (x == 1) b1.flip(y); if (x == 2) b2.flip(y); } else if (opr.equalsIgnoreCase("SET")) { if (x == 1) b1.set(y); if (x == 2) b2.set(y); } else { System.out.println("Invalid operation entered!"); } System.out.println(b1.cardinality() + " " + b2.cardinality()); } scan.close(); } }
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 →