1 import java.util.*; 2 3 public class SelectOnlys { 4 long S1 = 2 ^ 16; 5 6 7 int whichSeg(long s) { 8 long L = S1; 9 int flag = 0; 10 while (s >= L) { 11 s %= L; 12 flag++; 13 } 14 return flag; 15 } 16 17 Collection<Integer> run(long[] a) { 18 int[] count = new int[2 ^ 16]; 19 Collection<Integer> res = new ArrayList<Integer>(); 20 for (int i = 0; i < a.length; i++) { 21 int seg = whichSeg(a[i]); 22 int rem = (int) (a[i] % S1); 23 24 if ((count[rem] & (1 << (2 * seg))) != 1) { 25 count[rem] |= 1 << (2 * seg); 26 } else if ((count[rem] & (1 << (1 + 2 * seg))) != 1) { 27 count[rem] |= 1 << (1 + 2 * seg); 28 } 29 30 } 31 32 for (int i = 0; i < a.length; i++) { 33 int[] b = {1, 3, 5, 7}; 34 for (int one : b) { 35 if ((count[i] & (1 << one)) != 1 && (count[i] & (1 << (one - 1))) == 1) { 36 res.add((int) (long) (one * S1 + a[i])); 37 } 38 } 39 40 } 41 return res; 42 43 } 44 45 }