Sort by

recency

|

189 Discussions

|

  • + 0 comments
    import java.util.BitSet;
    import java.util.Scanner;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int n = scanner.nextInt();
            int m = scanner.nextInt();
    
            BitSet bitSet1 = new BitSet(n);
            BitSet bitSet2 = new BitSet(n);
    
            for(int i=0; i<m; i++) {
                String command = scanner.next();
                int index1 = scanner.nextInt();
                int index2 = scanner.nextInt();
                executeBisetCommand(bitSet1, bitSet2, command, index1, index2);
                System.out.println(bitSet1.cardinality() + " " + bitSet2.cardinality());
            }
        }
    
        public static void executeBisetCommand(BitSet bitSet1, BitSet bitSet2, String command, int index1, int index2) {
            BitSet target = (index1 == 1) ? bitSet1 : bitSet2;
            BitSet other = (index1 == 1) ? bitSet2 : bitSet1;
    
            switch (command) {
                case "AND" -> target.and(other);
                case "OR" -> target.or(other);
                case "XOR" -> target.xor(other);
                case "SET" -> target.set(index2);
                case "FLIP" -> target.flip(index2);
            }
        }
    
    }
    
  • + 0 comments

    My attempt:

    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            
            int bitSetSize = sc.nextInt();
            BitSet b1 = new BitSet(bitSetSize);
            BitSet b2 = new BitSet(bitSetSize);
            BitSet[] bitSets = {b1, b2};
            
            int queryCount = sc.nextInt();
            
            for (int i = 0; i < queryCount; i++) {
                String query = sc.next();
                int arg1 = sc.nextInt();
                int arg2 = sc.nextInt();
                switch (query) {
                    case "AND" -> bitSets[arg1 - 1].and(bitSets[arg2 - 1]);
                    case "OR" -> bitSets[arg1 - 1].or(bitSets[arg2 - 1]);
                    case "XOR" -> bitSets[arg1 - 1].xor(bitSets[arg2 - 1]);
                    case "FLIP" -> bitSets[arg1 - 1].flip(arg2);
                    case "SET" -> bitSets[arg1 - 1].set(arg2);
                }
                System.out.println(bitSets[0].cardinality() + " " + bitSets[1].cardinality());
            }
            
            sc.close();
        }
    }
    
  • + 0 comments
    public static void main(String[] args) {
    
            Scanner scnr = new Scanner(System.in);
            Integer N = scnr.nextInt();
            Integer M = scnr.nextInt();
    
            BitSet[] b = new BitSet[] {new BitSet(N), new BitSet(N)};  
    
            for (int i = 0; i < M; i++) {
                String op = scnr.next();
                Integer p1 = scnr.nextInt();
                Integer p2 = scnr.nextInt();
                
                if (op.equals("AND")) {
                    b[p1-1].and(b[p2-1]);
                } else if (op.equals("OR")) {
                    b[p1-1].or(b[p2-1]);
                } else if (op.equals("XOR")) {
                    b[p1-1].xor(b[p2-1]);
                } else if (op.equals("FLIP")) {
                    b[p1-1].flip(p2);
                } else if (op.equals("SET")) {
                    b[p1-1].set(p2);
                }
                System.out.printf("%d %d\n", b[0].cardinality(), b[1].cardinality());
            }
            
            scnr.close();
        }
    
  • + 0 comments

    Best digital marketing agency in varanasi https://sparkinwords.com/web-development/ To develop and grow your business.

  • + 0 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());
            }
        }
    }