SHARE
TWEET

Untitled

IzhanVarsky Mar 24th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     private static int[][][] arr = new int[129][129][129];
  6.     private static int n;
  7.  
  8.     private static void add(int x, int y, int z, int val) {
  9.         for (int i = x; i < n; i = (i | (i + 1)))
  10.             for (int j = y; j < n; j = (j | (j + 1)))
  11.                 for (int k = z; k < n; k = (k | (k + 1)))
  12.                     arr[i][j][k] += val;
  13.     }
  14.  
  15.     private static int sum(int x, int y, int z) {
  16.         int result = 0;
  17.         for (int i = x; i >= 0; i = (i & (i+1)) - 1)
  18.             for (int j = y; j >= 0; j = (j & (j+1)) - 1)
  19.                 for (int k = z; k >= 0; k = (k & (k+1)) - 1)
  20.                     result += arr[i][j][k];
  21.         return result;
  22.     }
  23.  
  24.     public static void main(String[] args) {
  25.         Scanner in = new Scanner(System.in);
  26.         n = in.nextInt();
  27.         while (true) {
  28.             int q = in.nextInt();
  29.             if (q == 3) break;
  30.             if (q == 2) {
  31.                 int res = 0;
  32.                 int x1 = in.nextInt();
  33.                 int y1 = in.nextInt();
  34.                 int z1 = in.nextInt();
  35.                 int x2 = in.nextInt();
  36.                 int y2 = in.nextInt();
  37.                 int z2 = in.nextInt();
  38.                 res += sum(x2, y2, z2);
  39.                 res -= sum(x1 - 1, y2, z2);
  40.                 res -= sum(x2, y1 - 1, z2);
  41.                 res -= sum(x2, y2, z1 - 1);
  42.                 res += sum(x1 - 1, y1 - 1, z2);
  43.                 res += sum(x1 - 1, y2, z1 - 1);
  44.                 res += sum(x2, y1 - 1, z1 - 1);
  45.                 res -= sum(x1 - 1, y1 - 1, z1 - 1);
  46.                 System.out.println(res);
  47.             } else if (q == 1) {
  48.                 add(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt());
  49.             }
  50.         }
  51.     }
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top