Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define spc << ' ' <<
- #define spce << ' '
- #define ele << '\n'
- #define el << '\n' <<
- #define INF 99999
- #define AINF -99999
- using namespace std;
- template<typename tmp>
- void output(vector<tmp>& vc, char en) {
- for (tmp x : vc)
- cout x << en;
- }
- template<typename tmp>
- void input(vector<tmp>& vc) {
- for (tmp& x : vc)
- cin >> x;
- }
- int f(int a) {
- return (a & (a + 1));
- }
- int sum(int x, int y, int z, vector<vector<vector<int> > >& t) {
- int res = 0;
- while (x >= 0) {
- int Y = y;
- while (Y >= 0) {
- int Z = z;
- while (Z >= 0) {
- res += t[x][Y][Z];
- Z = f(Z) - 1;
- }
- Y = f(Y) - 1;
- }
- x = f(x) - 1;
- }
- return res;
- }
- void update(int x, int y, int z, int d, vector<vector<vector<int> > >& t) {
- while (x <= t.size()) {
- int Y = y;
- while (Y <= t.size()) {
- int Z = z;
- while (Z <= t.size()) {
- t[x][Y][Z] += d;
- Z = Z | (Z + 1);
- }
- Y = Y | (Y + 1);
- }
- x = x | (x + 1);
- }
- }
- int sum(int x1, int x2, int y1, int y2, int z1, int z2, vector<vector<vector<int> > >& t) {
- return sum(x1, y1, z1, t) - sum(x1, y1, z2 - 1, t) - sum(x2 - 1, y1, z1, t) + sum(x2 - 1, y1, z2 - 1, t) - sum(x1, y2 - 1, z1, t) + sum(x1, y2 - 1, z2 - 1, t) + sum(x2 - 1, y2 - 1, z1, t) - sum(x2 - 1, y2 - 1, z2 - 1, t);
- }
- int main() {
- int a;
- cin >> a;
- if (a % 2)
- ++a;
- vector<vector<vector<int> > > t(a, vector<vector<int>>(a, vector<int>(a, 0)));
- int tmp1, x1, x2, y1, y2, z1, z2, d;
- cin >> tmp1;
- while (tmp1 - 3) {
- if (tmp1 - 1) {
- cin >> x2 >> y2 >> z2 >> x1 >> y1 >> z1;
- cout << sum(x1, x2, y1, y2, z1, z2, t) ele;
- } else {
- cin >> x1 >> y1 >> z1 >> d;
- update(x1, y1, z1, d, t);
- }
- cin >> tmp1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement