Guest User

Subset

a guest
Aug 2nd, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. int k = 8;
  2.  
  3. int m = 1 << k;
  4. int bm = m - 1;
  5.  
  6. int[][] cnt = new int[m][m];
  7.  
  8. int q = nextInt();
  9.  
  10. while (--q >= 0) {
  11.     char t = next().charAt(0);
  12.     int s = nextInt();
  13.  
  14.     int x = s >> k;  // first byte
  15.     int y = s & bm;  // second byte
  16.  
  17.     if (t == 'a') {
  18.         for (int i = 0; i < m; i++) {
  19.             if ((i & x) == x) {
  20.                 ++cnt[i][y];
  21.             }
  22.         }      
  23.     } else if (t == 'c') {
  24.         int ans = 0;
  25.         for (int i = 0; i < m; i++) {
  26.             if ((i & y) == i) {
  27.                 ans += cnt[x][i];
  28.             }
  29.         }
  30.         println(ans);
  31.     } else if (t == 'd') {
  32.         for (int i = 0; i < m; i++) {
  33.             if ((i & x) == x) {
  34.                 --cnt[i][y];
  35.             }
  36.         }      
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment