Skip to main content

Posts

Showing posts from October, 2020

October Lunchtime AND Plus OR question solution

 October Lunchtime AND Plus OR  question solution - October Lunchtime AND Plus OR  question solution Read the problem statement carefully- Given an integer  x x , find two non-negative integers  a a  and  b b  such that  ( a ∧ b ) + ( a ∨ b ) = x ( a ∧ b ) + ( a ∨ b ) = x , where  ∧ ∧  is the bitwise AND operation and  ∨ ∨  is the bitwise OR operation. Input The first line of the input contains a single integer  T T  denoting the number of test cases. The description of  T T  test cases follows. The first and only line of each test case contains a single integer  x x . Output If there is no valid pair  ( a , b ) ( a , b ) , print a single line containing the integer  − 1 − 1 . Otherwise, print a single line containing two space-separated integers  a a  and  b b . If there are multiple solutions, you may print any one of them. Constraints 1 ≤ T ≤ 10 5 1 ≤ T ≤ 10 5 1 ≤ x ≤ 10 18 1 ≤ x ≤ 10 18 Subtasks Subtask #1 (30 points): 1 ≤ T ≤ 200 1 ≤ T ≤ 200 1 ≤ x ≤ 200 1 ≤ x ≤ 200 Subtask #2 (70

Playlist CSES Problem Set Solution | Cses sorting and searching problem solution

 Playlist CSES Problem Set Solution-  playlist cses problems solution with code and explanation. Problem statement-  Time limit:  1.00 s   Memory limit:  512 MB You are given a playlist of a radio station since its establishment. The playlist has a total of  n n  songs. What is the longest sequence of successive songs where each song is unique? Input The first input line contains an integer  n n : the number of songs. The next line has  n n  integers  k 1 , k 2 , … , k n k 1 , k 2 , … , k n : the id number of each song. Output Print the length of the longest sequence of unique songs. Constraints 1 ≤ n ≤ 2 ⋅ 10 5 1 ≤ n ≤ 2 ⋅ 10 5 1 ≤ k i ≤ 10 9 1 ≤ k i ≤ 10 9 Example Input: 8 1 2 1 3 2 7 4 2 Output: 5 Solution- this problem can be solved in O(1) time.You should follow the following step  take input in a vector. make two iterator i and j  check weather ith song is already played or not if not insert it into map and update max if max<currans. If ith song  already  played remove all ele