Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- private static int[][][] arr = new int[129][129][129];
- private static int n;
- private static void add(int x, int y, int z, int val) {
- for (int i = x; i < n; i = (i | (i + 1)))
- for (int j = y; j < n; j = (j | (j + 1)))
- for (int k = z; k < n; k = (k | (k + 1)))
- arr[i][j][k] += val;
- }
- private static int sum(int x, int y, int z) {
- int result = 0;
- for (int i = x; i >= 0; i = (i & (i+1)) - 1)
- for (int j = y; j >= 0; j = (j & (j+1)) - 1)
- for (int k = z; k >= 0; k = (k & (k+1)) - 1)
- result += arr[i][j][k];
- return result;
- }
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- n = in.nextInt();
- while (true) {
- int q = in.nextInt();
- if (q == 3) break;
- if (q == 2) {
- int res = 0;
- int x1 = in.nextInt();
- int y1 = in.nextInt();
- int z1 = in.nextInt();
- int x2 = in.nextInt();
- int y2 = in.nextInt();
- int z2 = in.nextInt();
- res += sum(x2, y2, z2);
- res -= sum(x1 - 1, y2, z2);
- res -= sum(x2, y1 - 1, z2);
- res -= sum(x2, y2, z1 - 1);
- res += sum(x1 - 1, y1 - 1, z2);
- res += sum(x1 - 1, y2, z1 - 1);
- res += sum(x2, y1 - 1, z1 - 1);
- res -= sum(x1 - 1, y1 - 1, z1 - 1);
- System.out.println(res);
- } else if (q == 1) {
- add(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement