Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <functional>
- #include <algorithm>
- #include <iostream>
- #include <iterator>
- #include <iomanip>
- #include <sstream>
- #include <numeric>
- #include <string>
- #include <vector>
- #include <bitset>
- #include <queue>
- #include <stack>
- #include <map>
- #include <set>
- #include <cstdlib>
- #include <cassert>
- #include <cstring>
- #include <cstdio>
- #include <cmath>
- #include <ctime>
- #include <list>
- using namespace std;
- typedef long long LL;
- typedef long double LD;
- typedef pair<int, int> pii;
- const LD eps = 1e-9;
- const LD pi = acos(-1.0);
- const LL inf = 1e+9;
- #define mp make_pair
- #define pb push_back
- #define X first
- #define Y second
- #define dbg(x) { cerr << #x << " = " << x << endl; }
- // extended template
- #pragma comment(linker, "/STACK:36777216")
- typedef vector<int> vi;
- typedef vector<vi> vvi;
- #define forn(i, n) for (int i = 0; i < n; ++i)
- #define all(a) (a).begin(), (a).end()
- #define rall(a) (a).rbegin(), (a).rend()
- template<typename T> istream & operator >> (istream &, vector<T> &);
- template<typename T> ostream & operator << (ostream &, const vector<T> &);
- #define START clock_t _clock = clock();
- #define END cerr << endl << "time: " << (clock() - _clock) / LD(CLOCKS_PER_SEC) << endl;
- #define NAME "problem"
- vector <vector<vector <LL> > > t;
- void inc(int x, int y, int z, int add)
- {
- for (int i = x; i < t.size(); i = (i | (i + 1)))
- {
- for (int k = y; k < t[0].size(); k = (k | (k + 1)))
- {
- for (int j = z; j < t[0][0].size(); j = (j | (j + 1)))
- {
- t[i][k][j] += add;
- }
- }
- }
- }
- LL sum(int x, int y, int z)
- {
- LL s = 0;
- for (int i = x; i >= 0; i = (i & (i + 1)) - 1)
- {
- for (int k = y; k >= 0; k = (k & (k + 1)) - 1)
- {
- for (int j = z; j >= 0; j = (j & (j + 1)) - 1)
- {
- s += t[i][k][j];
- }
- }
- }
- return s;
- }
- LL sum(int x, int y, int z, int x2, int y2, int z2)
- {
- return sum(x2, y2, z2) - sum(x - 1, y2, z2) - sum(x2, y - 1, z2) - sum(x2, y2, z - 1) + sum(x - 1, y - 1, z2) + sum(x - 1, y2, z - 1) + sum(x2, y - 1, z - 1) - sum(x - 1, y - 1, z - 1) ;
- }
- int main()
- {
- //freopen("input.txt", "r", stdin);
- freopen("stars.in", "r", stdin); freopen("stars.out", "w", stdout);
- int n, m;
- cin >> n;
- t.assign(n, vector <vector<LL> >(n, vector <LL> (n, 0)));
- int t = 0;
- while (cin >> t)
- {
- if (t == 3)
- break;
- if (t == 1)
- {
- int x, y, z, add;
- cin >> x >> y >> z >> add;
- //x--;y--;z--;
- inc(x, y, z, add);
- }
- else
- {
- int x, y, z, x2, y2, z2;
- cin >> x >> y >> z >> x2 >> y2 >> z2;
- cout << sum(x, y, z, x2, y2, z2) << endl;
- }
- }
- return 0;
- }
- /*******************************************
- *******************************************/
- template<typename T> istream & operator >> (istream &is, vector<T> &v)
- {
- forn(i, v.size())
- is >> v[i];
- return is;
- }
- template<typename T> ostream & operator << (ostream &os, const vector<T> &v)
- {
- forn(i, v.size())
- os << v[i] << " ";
- return os;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement