• + 0 comments

    Java 8

    public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int length = sc.nextInt();
            BitSet b1 = new BitSet(length);
            BitSet b2 = new BitSet(length);
            
            BitSet [] b = {b1, b2};
            
            int operations = sc.nextInt();
            
            for(int i=0; i<operations; i++) {
                sc.nextLine();
                String operation = sc.next();
                int x = sc.nextInt() - 1;
                int y = sc.nextInt() - 1; 
                if(operation.equals("AND")) {
                    b[x].and(b[y]);
                } else if(operation.equals("OR")) {
                    b[x].or(b[y]);
                } else if(operation.equals("XOR")) {
                    b[x].xor(b[y]);
                } else if(operation.equals("FLIP")) {
                    b[x].flip(y + 1);
                } else if(operation.equals("SET")) {
                    b[x].set(y + 1);
                }
                System.out.println(b1.cardinality() + " " + b2.cardinality());
            }
            sc.close();
        }