You are viewing a single comment's thread. Return to all comments →
Very simple solution with a BitSet array:
Scanner s = new Scanner(System.in); int n = s.nextInt(); int m = s.nextInt(); BitSet[] bs = new BitSet[]{new BitSet(n), new BitSet(n)}; for (int i=0; i<m; i++) { String c = s.next().trim(); if ( "AND".equals(c) ) bs[s.nextInt()-1].and(bs[s.nextInt()-1]); else if ( "OR".equals(c) ) bs[s.nextInt()-1].or(bs[s.nextInt()-1]); else if ( "XOR".equals(c) ) bs[s.nextInt()-1].xor(bs[s.nextInt()-1]); else if ( "SET".equals(c) ) bs[s.nextInt()-1].set(s.nextInt()); else if ( "FLIP".equals(c) ) bs[s.nextInt()-1].flip(s.nextInt()); System.out.println(bs[0].cardinality() + " " + bs[1].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 →
Very simple solution with a BitSet array: