• + 1 comment
    import java.util.Scanner;
    import java.util.BitSet;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            int N=scan.nextInt();
            BitSet[] B = new BitSet[] {new BitSet(N), new BitSet(N)};
            
            for(int i=scan.nextInt();i>0;i--) {
                scan.nextLine(); // skip to next line
                
                String op = scan.next();
                int m = scan.nextInt()-1;
                int n = 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());
            }
        }
    }