Problem:
魚の生息範囲 (Fish)
問題
オーストラリア大陸の西には，広いインド洋が広がっている．海洋研究者である JOI 氏は，インド洋に生息しているある N 種類の魚の性質について研究している．
それぞれの魚の種類に対して，海の中に直方体状の生息範囲が定まっている．魚は境界も含めて生息範囲の中のどの場所にも移動できるが，生息範囲の外に出ることは決してない．海の中の点は，3 つの実数 (x, y, d) によって表される： (x, y, d) は，上空から見たときにある地点を基準にして東に x，北に y 進んだ位置であり，海面からの深さが d の点を表す．ただし，海面は平面であるとする．
JOI 氏は，K 種類以上の魚の生息範囲が重なる場所がどのくらいあるかを知りたい．そのような場所全体の体積を求めるプログラムを作成せよ．
入力
入力は 1 + N 行からなる．
1 行目には，2 つの整数 N, K (1 ≦ K ≦ N ≦ 50) が空白を区切りとして書かれている．これは，魚が N 種類であり，K 種類以上の魚の生息範囲が重なる場所の体積を求めたいことを表す．
続く N 行のうちの i 行目 (1 ≦ i ≦ N) には，6 つの整数 X
i,1
, Y
i,1
, D
i,1
, X
i,2
, Y
i,2
, D
i,2
(0 ≦ X
i,1
＜ X
i,2
≦ 1000000 (= 10
6
)，0 ≦ Y
i,1
＜ Y
i,2
≦ 1000000 (= 10
6
)，0 ≦ D
i,1
＜ D
i,2
≦ 1000000 (= 10
6
)) が書かれている．これは，i 種類目の魚の生息範囲が

8 点 (X
i,1
, Y
i,1
, D
i,1
), (X
i,2
, Y
i,1
, D
i,1
), (X
i,2
, Y
i,2
, D
i,1
), (X
i,1
, Y
i,2
, D
i,1
), (X
i,1
, Y
i,1
, D
i,2
), (X
i,2
, Y
i,1
, D
i,2
), (X
i,2
, Y
i,2
, D
i,2
), (X
i,1
, Y
i,2
, D
i,2
) を頂点とする直方体であることを表す．
出力
K 種類以上の魚の生息範囲が重なる場所全体の体積を 1 行で出力せよ．
入出力例
入力例 1
3 2
30 50 0 50 70 100
10 20 20 70 90 60
40 60 20 90 90 70
出力例 1
49000
入出力例 1 において，例えば，点 (45, 65, 65) は 1 種類目の魚と 3 種類目の魚の生息範囲であるので，条件を満たす場所である．一方，点 (25, 35, 45) は 2 種類目の魚のみの生息範囲であるので，条件を満たす場所ではない．また，魚の生息範囲は下の図のようになっている．点 O は海面上の基準の地点を表す．
入力例 2
1 1
0 0 0 1000000 1000000 1000000
出力例 2
1000000000000000000
問題文と自動審判に使われるデータは、
情報オリンピック日本委員会
が作成し公開している問題文と採点用テストデータです。

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;

int compress(vector<ll>& v, vector<ll>& vs) {
    sort(vs.begin(), vs.end());
    vs.erase(unique(vs.begin(), vs.end()), vs.end());
    for(int i=0; i<v.size(); ++i) {
        v[i] = lower_bound(vs.begin(), vs.end(), v[i]) - vs.begin();
    }
    return vs.size();
}

bool cross(int a1, int b1, int a2, int b2) {
    return a1 <= a2 && a2 <= b1;
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> x(2*N), y(2*N), z(2*N), xs(2*N), ys(2*N), zs(2*N);
    for(int i=0; i<N; ++i) {
        ll x1, y1, z1, x2, y2, z2;
        cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
        x[2*i] = xs[2*i] = x1, x[2*i+1] = xs[2*i+1] = x2;
        y[2*i] = ys[2*i] = y1, y[2*i+1] = ys[2*i+1] = y2;
        z[2*i] = zs[2*i] = z1, z[2*i+1] = zs[2*i+1] = z2;
    }
    int xsize = compress(x, xs);
    int ysize = compress(y, ys);
    int zsize = compress(z, zs);
    ll res = 0;
    for(int i=0; i<xsize-1; ++i) {
        for(int j=0; j<ysize-1; ++j) {
            for(int k=0; k<zsize-1; ++k) {
                int cnt = 0;
                ll x1 = xs[i], x2 = xs[i+1],
                   y1 = ys[j], y2 = ys[j+1],
                   z1 = zs[k], z2 = zs[k+1];
                for(int n=0; n<N; ++n) {
                    ll fx1 = xs[x[2*n]], fx2 = xs[x[2*n+1]];
                    ll fy1 = ys[y[2*n]], fy2 = ys[y[2*n+1]];
                    ll fz1 = zs[z[2*n]], fz2 = zs[z[2*n+1]];
                    if(fx1 <= x1 && x2 <= fx2 && fy1 <= y1 && y2 <= fy2 && fz1 <= z1 && z2 <= fz2) {
                        cnt++;
                    }
                }
                if(cnt >= K) {
                    res += (x2 - x1) * (y2 - y1) * (z2 - z1);
                }
            }
        }
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 70
memory_kb: 3364
final_rank: 12

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,K; cin >> n >> K;
    vector<int> X(n),Y(n),Z(n),XX(n),YY(n),ZZ(n);
    vector<int> x,y,z;
    for (int i = 0; i < n; ++i) {
        cin >> X[i] >> Y[i] >> Z[i];
        cin >> XX[i] >> YY[i] >> ZZ[i];
        x.push_back(X[i]); x.push_back(XX[i]);
        y.push_back(Y[i]); y.push_back(YY[i]);
        z.push_back(Z[i]); z.push_back(ZZ[i]);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    sort(z.begin(), z.end());
    ll res = 0;
    for (int i = 0; i+1 < x.size(); ++i) {
        ll xx = x[i+1] - x[i];
        if (xx == 0) continue;
        for (int j = 0; j+1 < y.size(); ++j) {
            ll yy = y[j+1] - y[j];
            if (yy == 0) continue;
            for (int k = 0; k+1 < z.size(); ++k) {
                ll zz = z[k+1] - z[k];
                if (zz == 0) continue;
                int cnt = 0;
                for (int l = 0; l < n; ++l) {
                    if (X[l] <= x[i] and x[i+1] <= XX[l] and
                        Y[l] <= y[j] and y[j+1] <= YY[l] and
                        Z[l] <= z[k] and z[k+1] <= ZZ[l]) {
                        cnt += 1;
                    }
                }
                if (cnt >= K) res += xx*yy*zz;
            }
        }
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 3464
final_rank: 7

code_snippet: #include<bits/stdc++.h>

using namespace std;

int main(){
    int n, K;
    cin >> n >> K;

    vector<vector<long long> > a(n, vector<long long >(6));

    vector<long long> x, y, z;
    for(int i = 0;i < n;++i){
        cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3] >> a[i][4] >> a[i][5];
        x.push_back(a[i][0]);
        x.push_back(a[i][3]);
        y.push_back(a[i][1]);
        y.push_back(a[i][4]);
        z.push_back(a[i][2]);
        z.push_back(a[i][5]);
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    sort(z.begin(), z.end());
    unique(x.begin(), x.end());
    unique(y.begin(), y.end());
    unique(z.begin(), z.end());
    long long ans = 0;
    for(int i = 0;i < 2*n-1;++i){
        for(int j = 0;j < 2*n-1;++j){
            for(int k = 0;k < 2*n-1;++k){
                int cnt = 0;
                for(int m = 0;m < n;++m){
                    if(a[m][0] <= x[i] && x[i+1] <= a[m][3] && a[m][1] <= y[j] && y[j+1] <= a[m][4] && z[k] >= a[m][2] && z[k+1] <= a[m][5])++cnt;
                }

                if(cnt >= K){
                    ans += (x[i+1] - x[i]) * (y[j+1] - y[j]) * (z[k+1] - z[k]);
                }
            }
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 3152
final_rank: 4

code_snippet: #include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<unordered_map>
#include<stack>
#include<string>
#include<algorithm>
#include<functional>
#include<cstring>
#include<complex>
#include<bitset>
#include<iostream>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
typedef complex<double> C;
#define cx real()
#define cy imag()
const ll INF = 1LL << 60;
const double DINF = 1e30;
const ll mod = 1000000007;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, -1, 0, 1};
const C I = C(0, 1);
const double EPS = 1e-10;
const ll NCK_MAX = 510000;

ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
  if (b == 0) {
    x = 1, y = 0; return a;
  }
  ll q = a/b, g = extgcd(b, a - q*b, x, y);
  ll z = x - q * y;
  x = y;
  y = z;
  return g;
}

ll invmod (ll a, ll m) { // a^-1 mod m
  ll x, y;
  extgcd(a, m, x, y);
  x %= m;
  if (x < 0) x += m;
  return x;
}

ll *fac, *finv, *inv;

void nCk_init(ll mod) {
  fac = new ll[NCK_MAX];
  finv = new ll[NCK_MAX];
  inv = new ll[NCK_MAX];
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < NCK_MAX; i++) {
    fac[i] = fac[i-1] * i % mod;
    inv[i] = mod - inv[mod%i] * (mod / i) % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}

ll nCk(ll n, ll k, ll mod) {
  if (fac == NULL) nCk_init(mod);
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

template <typename T>
class Zip {
public:
  vector<T> d;
  bool flag;
  void init() {
    sort(d.begin(), d.end());
    d.erase(unique(d.begin(), d.end()), d.end());
    flag = false;
  }
  Zip() {
    flag = false;
  }
  void add(T x) {
    d.push_back(x);
    flag = true;
  }
  ll getNum(T x) {
    if (flag) init();
    return lower_bound(d.begin(), d.end(), x) - d.begin();
  }
  ll size() {
    if (flag) init();
    return (ll)d.size();
  }
};

class UnionFind {
  vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
  UnionFind(ll n) : par(n, 1), rank(n, 0) {}
  ll getSize(ll x) {
    return par[find(x)];
  }
  ll find(ll x) {
    if (par[x] > 0) return x;
    return -(par[x] = -find(-par[x]));
  }
  void merge(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[y] += par[x];
      par[x] = -y;
    } else {
      par[x] += par[y];
      par[y] = -x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool isSame(ll x, ll y) {
    return find(x) == find(y);
  }
};


template <typename T>
class SegmentTree {
  ll n;
  vector<T> node;
  function<T(T, T)> fun, fun2;
  bool customChange;
  T outValue, initValue;
public:
  void init(ll num, function<T(T, T)> resultFunction, T init, T out, function<T(T, T)> changeFunction = NULL) {
    // changeFunction: (input, beforevalue) => newvalue
    fun = resultFunction;
    fun2 = changeFunction;
    customChange = changeFunction != NULL;
    n = 1;
    while (n < num) n *= 2;
    node.resize(2 * n - 1);
    fill(node.begin(), node.end(), init);
    outValue = out;
    initValue = init;
  }
  void valueChange(ll num, T value) {
    num += n-1;
    if (customChange) node[num] = fun2(value, node[num]);
    else node[num] = value;
    while (num > 0) num = (num - 1) / 2, node[num] = fun(node[num * 2 + 1], node[num * 2 + 2]);
  }
  T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b)
    if (r == -1) r = n;
    if (a <= l && r <= b) return node[k];
    if (b <= l || r <= a) return outValue;
    ll mid = (l + r) / 2;
    return fun(rangeQuery(a, b, l, mid, 2*k+1), rangeQuery(a, b, mid, r, 2*k+2));
  }
};

template <typename T>
class Graph {
  struct edge { ll to; T cost; };
  struct edge_data { ll from, to; T cost; };

  ll v;
  vector<vector<edge>> e, re;
  vector<edge_data> ed;
  vector<bool> used;
  vector<ll> vs, cmp;
  bool isDirected, isMinasEdge;
public:
  Graph(ll _v, bool _isDirected = true, ll range_add = 0) {
    // range_add 0:no / 1:in / 2:out / 3:in+out
    //_v++;
    v = _v, isDirected = _isDirected; isMinasEdge = false;
    e.resize(v), re.resize(v);
  }
  void add_edge(ll s, ll t, T cost = 1) {
    e[s].push_back((edge){t, cost});
    if (!isDirected) e[t].push_back((edge){s, cost});
    else re[t].push_back((edge){s, cost});
    ed.push_back((edge_data){s, t, cost});
    if (cost < 0) isMinasEdge = true;
  }
  vector<T> dijkstra(ll s) {
    vector<T> d(v, INF);
    d[s] = 0;
    auto edge_cmp = [](const edge& a, const edge& b) { return a.cost > b.cost; };
    priority_queue<edge, vector<edge>, decltype(edge_cmp)> pq(edge_cmp);
    pq.push((edge){s, 0});
    while (!pq.empty()) {
      edge temp = pq.top(); pq.pop();
      if (d[temp.to] < temp.cost) continue;
      for (const edge& next : e[temp.to]) {
        T cost = temp.cost + next.cost;
        if (d[next.to] > cost) {
          d[next.to] = cost;
          pq.push((edge){next.to, cost});
        }
      }
    }
    return d;
  }
  vector<T> bellmanford(ll s) {
    vector<T> d(v, INF);
    d[s] = 0;
    for (ll i = 0; i < v; i++) {
      for (const edge_data& temp : ed) {
        if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost) d[temp.to] = d[temp.from] + temp.cost;
        if (!isDirected && d[temp.to] != INF && d[temp.from] > d[temp.to] + temp.cost) d[temp.from] = d[temp.to] + temp.cost;
      }
    }
    for (ll i = 0; i < v; i++) {
      for (const edge_data& temp : ed) {
        if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost) d[temp.to] = -INF;
        if (!isDirected && d[temp.to] != INF && d[temp.from] > d[temp.to] + temp.cost) d[temp.from] = -INF;
      }
    }
    return d;
  }
  vector<T> shortest_path(ll s) {
    if (isMinasEdge) return bellmanford(s);
    else return dijkstra(s);
  }
  T kruskal() {
    // if (isDirected)
    UnionFind uf(v);
    auto edge_data_cmp = [](const edge_data& a, const edge_data& b) { return a.cost < b.cost; };
    sort(ed.begin(), ed.end(), edge_data_cmp);
    T ans = 0;
    for (const edge_data& temp : ed) {
      if (uf.isSame(temp.from, temp.to)) continue;
      uf.merge(temp.from, temp.to);
      ans += temp.cost;
    }
    return ans;
  }
  void scc_dfs(ll s) {
    used[s] = true;
    for (const edge& i : e[s]) if (!used[i.to]) scc_dfs(i.to);
    vs.push_back(s);
  }
  void scc_rdfs(ll s, ll k) {
    used[s] = true;
    cmp[s] = k;
    for (const edge& i : re[s]) if (!used[i.to]) scc_rdfs(i.to, k);
  }
  vector<ll> scc() {
    used.resize(v);
    fill(used.begin(), used.end(), false);
    cmp.resize(v);
    vs.clear();
    for (ll i = 0; i < v; i++) if (!used[i]) scc_dfs(i);
    used.resize(v);
    fill(used.begin(), used.end(), false);
    ll k = 0;
    for (ll i = vs.size() - 1; i >= 0; i--) if (!used[vs[i]]) scc_rdfs(vs[i], k++);
    return cmp;
  }
};

class RollingHash {
  int base;
  vector<__int128> hash;
  vector<__int128> pw;
  const __int128 hashmod = (1ull << 61) - 1;
public:
  RollingHash(string s, int base = 10007) : base(base), hash(s.length()+1, 0), pw(s.length()+1, 1) {
    for (int i = 0; i < (int)s.length(); i++) {
      hash[i+1] = (hash[i] * base + s[i]) % hashmod;
      pw[i+1] = pw[i] * base % hashmod;
    }
  }
  ll get(ll a, ll b) { // [a, b)
    __int128 tmp = hashmod + hash[b] - hash[a] * pw[b-a] % hashmod;
    if (tmp >= hashmod) tmp -= hashmod;
    return (ll)tmp;
  }
};

ll n, k, x[50], y[50], z[50], x2[50], y2[50], z2[50], ans;

int main() {
  scanf("%lld%lld", &n, &k);
  Zip<ll> zx, zy, zz;
  for (ll i = 0; i < n; i++) {
    scanf("%lld%lld%lld", &x[i], &y[i], &z[i]);
    scanf("%lld%lld%lld", &x2[i], &y2[i], &z2[i]);
    zx.add(x[i]); zx.add(x2[i]);
    zy.add(y[i]); zy.add(y2[i]);
    zz.add(z[i]); zz.add(z2[i]);
  }
  for (ll i = 0; i < n; i++) {
    x[i] = zx.getNum(x[i]); x2[i] = zx.getNum(x2[i]);
    y[i] = zy.getNum(y[i]); y2[i] = zy.getNum(y2[i]);
    z[i] = zz.getNum(z[i]); z2[i] = zz.getNum(z2[i]);
  }
  for (ll i = 0; i < zx.size()-1; i++) {
    for (ll j = 0; j < zy.size()-1; j++) {
      for (ll l = 0; l < zz.size()-1; l++) {
        ll cnt = 0;
        for (ll m = 0; m < n; m++) {
          if (x2[m] <= i or i + 1 <= x[m]) continue;
          if (y2[m] <= j or j + 1 <= y[m]) continue;
          if (z2[m] <= l or l + 1 <= z[m]) continue;
          cnt++;
        }
        if (cnt >= k) {
          ans += (zx.d[i+1]-zx.d[i]) * (zy.d[j+1]-zy.d[j]) * (zz.d[l+1]-zz.d[l]);
        }
      }
    }
  }
  printf("%lld\n", ans);
}
accuracy: 1
time_ms: 40
memory_kb: 3536
final_rank: 8

code_snippet: #pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

random_device rd;
mt19937 mt(rd());


template<class T>
struct Compress {
	std::vector<T> data;
	void add(T x) {
		data.push_back(x);
	}
	void build() {
		std::sort(data.begin(), data.end());
		data.erase(std::unique(data.begin(), data.end()), data.end());
	}

	const int operator[](int x) const {
		return std::lower_bound(data.begin(), data.end(), x) - data.begin();
	}

	const T operator()(int k) const {
		return data[k];
	}
};

int main() {
	int N, K;
	cin >> N >> K;
	vector <pair<tuple<ll, ll, ll>, tuple<ll, ll, ll>>> fish;
	Compress<ll> X, Y, Z;
	vector count(N*2, vector(N*2, vector(N*2, 0)));
	for (int i = 0; i < N; i++) {
		int x1, y1, z1, x2, y2, z2;
		cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
		X.add(x1); Y.add(y1); Z.add(z1);
		X.add(x2); Y.add(y2); Z.add(z2);
		fish.push_back({ {x1,y1,z1},{x2,y2,z2} });
	}
	X.build(); Y.build(); Z.build();
	for (int i = 0; i < N; i++) {
		auto [p1, p2] = fish[i];
		auto [x1, y1, z1] = p1;
		auto [x2, y2, z2] = p2;
		for (int x = X[x1]; x < X[x2]; x++) {
			for (int y = Y[y1]; y < Y[y2]; y++) {
				for (int z = Z[z1]; z < Z[z2]; z++) {
					count[x][y][z]++;
				}
			}
		}
	}
	ll ans = 0;
	for (int x = 0; x < 2 * N; x++)for (int y = 0; y < 2 * N; y++)for (int z = 0; z < 2 * N; z++) {
		if (count[x][y][z] >= K) {
			ans += (X(x + 1) - X(x)) * (Y(y + 1) - Y(y)) * (Z(z + 1) - Z(z));
		}
	}
	cout << ans << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 7348
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<tuple<int, int, int, int, int, int>> zahyo(N);

  vector<long long> X, Y, Z;
  for (int i = 0; i < N; i++) {
    int x1, y1, z1, x2, y2, z2;
    cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
    zahyo[i] = {x1, y1, z1, x2, y2, z2};
    X.push_back(x1), X.push_back(x2);
    Y.push_back(y1), Y.push_back(y2);
    Z.push_back(z1), Z.push_back(z2);
  }

  sort(X.begin(), X.end());
  X.erase(unique(X.begin(), X.end()), X.end());
  sort(Y.begin(), Y.end());
  Y.erase(unique(Y.begin(), Y.end()), Y.end());
  sort(Z.begin(), Z.end());
  Z.erase(unique(Z.begin(), Z.end()), Z.end());

  long long ans = 0;
  // 各ブロックの番号
  for (int x = 0; x < (int)X.size() - 1; x++) {
    for (int y = 0; y < (int)Y.size() - 1; y++) {
      for (int z = 0; z < (int)Z.size() - 1; z++) {
        int cnt = 0;

        for (int i = 0; i < N; i++) {
          auto [x1, y1, z1, x2, y2, z2] = zahyo[i];
          if (x1 <= X[x] && X[x + 1] <= x2 && y1 <= Y[y] && Y[y + 1] <= y2 && z1 <= Z[z] && Z[z + 1] <= z2) cnt++;
        }
        if (cnt >= K) ans += (X[x + 1] - X[x]) * (Y[y + 1] - Y[y]) * (Z[z + 1] - Z[z]);
      }
    }
  }

  cout << ans << endl;

  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3452
final_rank: 6

code_snippet: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i< (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int inf = (1<<30);
ll X1[50]={},X2[50]={},Y1[50]={},Y2[50]={},d1[50]={},d2[50]={};
ll x[100]={},y[100]={},d[100]={};

int main(){
	int n,k;
	cin>>n>>k;
	ll ans=0;
	rep(i,n){
		cin>>X1[i]>>Y1[i]>>d1[i]>>X2[i]>>Y2[i]>>d2[i];
	}
	int xlen=0,ylen=0,dlen=0;
	rep(i,n){
			x[xlen++]=X1[i];x[xlen++]=X2[i];
			y[ylen++]=Y1[i];y[ylen++]=Y2[i];
			d[dlen++]=d1[i];d[dlen++]=d2[i];
	}
	sort(x,x+xlen); sort(y,y+ylen); sort(d,d+dlen);
	for(int i=0; i+1<xlen; i++){
		for(int j=0; j+1<ylen; j++){
			for(int l=0; l+1<dlen; l++){
				int s=0;
				rep(u,n){
					if( X1[u]<=x[i] && X2[u]>=x[i+1] &&
						Y1[u]<=y[j] && Y2[u]>=y[j+1] &&
						d1[u]<=d[l] && d2[u]>=d[l+1]
						){
							s++;
					}
				}
				if(s>=k){
					ans+=(x[i+1]-x[i])*(y[j+1]-y[j])*(d[l+1]-d[l]);
				}
			}
		}
	}
	cout<<ans<<endl;
}
accuracy: 1
time_ms: 50
memory_kb: 3148
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1001001001;
const long long MOD = /**/1000000007;//*/998244353;
const double EPS = 1e-10;

ll imos[222][222][222];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,k;
    cin>>n>>k;
    ll x[n][2],y[n][2],d[n][2];
    vector<ll> vec1,vec2,vec3;
    vec1.emplace_back(0);
    vec1.emplace_back(INF);
    vec2.emplace_back(0);
    vec2.emplace_back(INF);
    vec3.emplace_back(0);
    vec3.emplace_back(INF);
    for(int i=0;i<n;i++){
        cin>>x[i][0]>>y[i][0]>>d[i][0]>>x[i][1]>>y[i][1]>>d[i][1];
        vec1.emplace_back(x[i][0]);
        vec1.emplace_back(x[i][1]);
        vec2.emplace_back(y[i][0]);
        vec2.emplace_back(y[i][1]);
        vec3.emplace_back(d[i][0]);
        vec3.emplace_back(d[i][1]);
    }
    sort(begin(vec1),end(vec1));
    vec1.erase(unique(begin(vec1),end(vec1)),end(vec1));
    sort(begin(vec2),end(vec2));
    vec2.erase(unique(begin(vec2),end(vec2)),end(vec2));
    sort(begin(vec3),end(vec3));
    vec3.erase(unique(begin(vec3),end(vec3)),end(vec3));
    int t1=vec1.size(),t2=vec2.size(),t3=vec3.size();
    for(int i=0;i<n;i++){
        x[i][0]=lower_bound(begin(vec1),end(vec1),x[i][0])-begin(vec1);
        x[i][1]=lower_bound(begin(vec1),end(vec1),x[i][1])-begin(vec1);
        y[i][0]=lower_bound(begin(vec2),end(vec2),y[i][0])-begin(vec2);
        y[i][1]=lower_bound(begin(vec2),end(vec2),y[i][1])-begin(vec2);
        d[i][0]=lower_bound(begin(vec3),end(vec3),d[i][0])-begin(vec3);
        d[i][1]=lower_bound(begin(vec3),end(vec3),d[i][1])-begin(vec3);
        imos[x[i][0]][y[i][0]][d[i][0]]++,imos[x[i][0]][y[i][0]][d[i][1]]--,imos[x[i][0]][y[i][1]][d[i][0]]--,imos[x[i][1]][y[i][0]][d[i][0]]--,imos[x[i][1]][y[i][1]][d[i][0]]++,imos[x[i][1]][y[i][1]][d[i][1]]--,imos[x[i][0]][y[i][1]][d[i][1]]++,imos[x[i][1]][y[i][0]][d[i][1]]++;
    }
    for(int c=0;c<t3;c++){
        for(int a=0;a<t1;a++){
            for(int b=1;b<t2;b++)imos[a][b][c]+=imos[a][b-1][c];
        }
    }
    for(int b=0;b<t2;b++){
        for(int c=0;c<t3;c++){
            for(int a=1;a<t1;a++)imos[a][b][c]+=imos[a-1][b][c];
        }
    }
    for(int a=0;a<t1;a++){
        for(int b=0;b<t2;b++){
            for(int c=1;c<t3;c++)imos[a][b][c]+=imos[a][b][c-1];
        }
    }
    ll ans=0;
    for(int a=0;a<t1-1;a++){
        for(int b=0;b<t2-1;b++){
            for(int c=0;c<t3-1;c++){
                if(imos[a][b][c]>=k)ans+=(vec1[a+1]-vec1[a])*(vec2[b+1]-vec2[b])*(vec3[c+1]-vec3[c]);
            }
        }
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 21488
final_rank: 17

code_snippet: #include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 10000000000000000;
const int intINF = 1000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;

//printf("%.10f\n", n);
typedef pair <ll, ll> P;
ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };

struct status {
	ld ave;
	ld ko;
	ld cost;

	bool operator<(const status& rhs) const { return ave < rhs.ave; };
	bool operator>(const status& rhs) const { return ave > rhs.ave; };
};

ll maze[105][105][105], dis[105][105][105];
signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	//cout << fixed << setprecision(15);
	
	//input
	ll n, ink; cin >> n >> ink;
	vector<ll> x(n * 2), y(n * 2), z(n * 2);
	vector<vector<ll>> v(n, vector<ll>(6));
	rep(i, n) {
		cin >> x[i * 2] >> y[i * 2] >> z[i * 2];
		cin >> x[i * 2 + 1] >> y[i * 2 + 1] >> z[i * 2 + 1];
		v[i][0] = x[i * 2]; v[i][1] = y[i * 2]; v[i][2] = z[i * 2];
		v[i][3] = x[i * 2 + 1]; v[i][4] = y[i * 2 + 1]; v[i][5] = z[i * 2 + 1];
		//x[i * 2].second = 1; y[i * 2].second = 1; z[i * 2].second = 1;
		//x[i * 2 + 1].second = -1; y[i * 2 + 1].second = -1; z[i * 2 + 1].second = -1;
	}

	//座圧
	sort(all(x)); sort(all(y)); sort(all(z));
	map<ll, ll> zaatu1, zaatu2, zaatu3;
	rep(i, 2 * n) {
		zaatu1[x[i]] = i; zaatu2[y[i]] = i; zaatu3[z[i]] = i;
	}

	//dis
	rep(i, 2 * n - 1) {
		rep(j, 2 * n - 1) {
			rep(k, 2 * n - 1) {
				dis[i][j][k] = (x[i + 1] - x[i]) * (y[j + 1] - y[j]) * (z[k + 1] - z[k]);
			}
		}
	}

	//maze
	rep(h, n) {
		for (int i = zaatu1[v[h][0]]; i < zaatu1[v[h][3]]; i++) {
			for (int j = zaatu2[v[h][1]]; j < zaatu2[v[h][4]]; j++) {
				for (int k = zaatu3[v[h][2]]; k < zaatu3[v[h][5]]; k++) {
					maze[i][j][k]++;
				}
			}
		}
	}
	ll ans = 0;
	rep(i, 2 * n) {
		rep(j, 2 * n) {
			rep(k, 2 * n) {
				if (maze[i][j][k] >= ink) { ans += dis[i][j][k]; }
			}
		}
	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 19580
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

/* compress
    (X1,Y1),(X2,Y2)という二点で表されるもの（長方形や直線など）について、行か列の片方（X1とX2 or Y1とY2）を座標圧縮する（副作用）
    返り値: ソートされ重複要素を除いた値
    計算量: O(n log n)
*/
template <typename T>
vector<T> compress(vector<T> &C1, vector<T> &C2, T w = 1000000){
    vector<T> vals;
    ll n = (ll)C1.size();
    rep(i, n){
        vals.push_back(C1[i]);
        vals.push_back(C2[i]);
    }
    // ソート
    sort(vals.begin(), vals.end());
    // 隣り合う重複を削除(unique), 末端のゴミを削除(erase)
    vals.erase(unique(vals.begin(), vals.end()), vals.end());
    return vals;
}

int main(){
    ll n, k;
    ll ans = 0;
    cin >> n >> k;
    vector<ll> X1(n), X2(n), Y1(n), Y2(n), D1(n), D2(n);
    rep(i, n){
        cin >> X1.at(i) >> Y1.at(i) >> D1.at(i) >> X2.at(i) >> Y2.at(i) >> D2.at(i);
    }
    vector<ll> X = compress(X1, X2);
    vector<ll> Y = compress(Y1, Y2);
    vector<ll> D = compress(D1, D2);
    ll w = X.size(), h = Y.size(), s = D.size();


    rep(d, s-1){
        rep(y, h-1){
            rep(x, w-1){
                ll count = 0;
                rep(i, n){
                    if(X1[i] <= X[x] && X[x+1] <= X2[i] && Y1[i] <= Y[y] && Y[y+1] <= Y2[i] && D1[i] <= D[d] && D[d+1] <= D2[i]){
                        count++;
                    }
                }
                if(count >= k){
                    ans += (X[x+1] - X[x]) * (Y[y+1] - Y[y]) * (D[d+1] - D[d]);
                }
            }
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 90
memory_kb: 3176
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

int x[2][55], y[2][55], z[2][55];
vector<int> X, Y, Z;

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	int N, K;
	cin >> N >> K;
	rep(i, N) {
		rep(j, 2) {
			cin >> x[j][i] >> y[j][i] >> z[j][i];
			X.push_back(x[j][i]);
			Y.push_back(y[j][i]);
			Z.push_back(z[j][i]);
		}
	}
	sort(all(X));
	sort(all(Y));
	sort(all(Z));

	int ans = 0;
	rep(i, 2 * N - 1) {
		rep(j, 2 * N - 1) {
			rep(k, 2 * N - 1) {
				int cnt = 0;
				rep(l, N) {
					if(x[0][l] <= X[i] && X[i] < x[1][l] && y[0][l] <= Y[j] && Y[j] < y[1][l] && z[0][l] <= Z[k] && Z[k] < z[1][l]) {
						cnt++;
					}
				}
				if(K <= cnt) {
					int dx = X[i+1] - X[i];
					int dy = Y[j+1] - Y[j];
					int dz = Z[k+1] - Z[k];
					ans += dx * dy * dz;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 3084
final_rank: 14

code_snippet: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  const int L = 1000000;
  int n, k; cin >> n >> k;
  vector<int> x1(n), y1(n), d1(n), x2(n), y2(n), d2(n); REP(i, n) cin >> x1[i] >> y1[i] >> d1[i] >> x2[i] >> y2[i] >> d2[i];
  function<vector<int>(vector<int>&, vector<int>&)> compress = [&](vector<int> &x1, vector<int> &x2) {
    int sz = x1.size();
    vector<int> xs{0, L - 1};
    REP(i, sz) {
      xs.emplace_back(x1[i]);
      if (x2[i] < L) xs.emplace_back(x2[i]);
    }
    sort(ALL(xs));
    xs.erase(unique(ALL(xs)), xs.end());
    return xs;
  };
  vector<int> x = compress(x1, x2), y = compress(y1, y2), d = compress(d1, d2);
  x.emplace_back(L);
  y.emplace_back(L);
  d.emplace_back(L);
  long long ans = 0;
  REP(i, x.size() - 1) REP(j, y.size() - 1) REP(l, d.size() - 1) {
    int kind = 0;
    REP(m, n) {
      if (x1[m] <= x[i] && x[i] < x2[m] && y1[m] <= y[j] && y[j] < y2[m] && d1[m] <= d[l] && d[l] < d2[m]) ++kind;
    }
    if (kind >= k) ans += (long long)(x[i + 1] - x[i]) * (y[j + 1] - y[j]) * (d[l + 1] - d[l]);
  }
  cout << ans << '\n';
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3220
final_rank: 5

code_snippet: #include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;
typedef std::pair<int, int> ipair;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int N;

vector<ll> compress(ll *x1, ll *x2) {
   vector<ll> xs(0);

   for (int i = 0; i < N; i++) {
      xs.push_back(x1[i]);
      xs.push_back(x2[i]);
   }
   
   sort(xs.begin(), xs.end());
   xs.erase(unique(xs.begin(), xs.end()), xs.end());

   return xs;
}

int main() {
   int K;
   cin >> N >> K;
   ll X1[N], Y1[N], Z1[N], X2[N], Y2[N], Z2[N];

   for (int i = 0; i < N; i++) {
      cin >> X1[i] >> Y1[i] >> Z1[i] >> X2[i] >> Y2[i] >> Z2[i];
   }

   vector<ll> XS = compress(X1, X2);
   vector<ll> YS = compress(Y1, Y2);
   vector<ll> ZS = compress(Z1, Z2);
   int XL = XS.size();
   int YL = YS.size();
   int ZL = ZS.size();

   ll ans = 0;
   for (int x = 0; x < XL - 1; x++) {
      for (int y = 0; y < YL - 1; y++) {
         for (int z = 0; z < ZL - 1; z++) {
            int cnt = 0;
            for (int i = 0; i < N; i++) {
               if (X1[i] > XS[x]) continue;
               if (X2[i] < XS[x + 1]) continue;
               if (Y1[i] > YS[y]) continue;
               if (Y2[i] < YS[y + 1]) continue;
               if (Z1[i] > ZS[z]) continue;
               if (Z2[i] < ZS[z + 1]) continue;
               cnt++;
            }
            if (cnt >= K) {
               ans += (XS[x + 1] - XS[x]) * (YS[y + 1] - YS[y]) * (ZS[z + 1] - ZS[z]);
            }
         }
      }
   }
   cout << ans << endl;

   return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3148
final_rank: 3

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;

const int INF = 1e7;
typedef long long ll;

int main(){
    int n, K;
    cin >> n >> K;
    vector<int> ax(n), ay(n), az(n), bx(n), by(n), bz(n), x, y, z;
    for(int i = 0; i < n; i++){
        cin >> ax[i] >> ay[i] >> az[i] >> bx[i] >> by[i] >> bz[i];
        x.push_back(ax[i]), x.push_back(bx[i]);
        y.push_back(ay[i]), y.push_back(by[i]);
        z.push_back(az[i]), z.push_back(bz[i]);
    }
    x.push_back(-INF), x.push_back(INF);
    y.push_back(-INF), y.push_back(INF);
    z.push_back(-INF), z.push_back(INF);
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    sort(z.begin(), z.end());
    x.erase(unique(x.begin(),x.end()),x.end());
    y.erase(unique(y.begin(),y.end()),y.end());
    z.erase(unique(z.begin(),z.end()),z.end());
    int xn = x.size(), yn = y.size(), zn = z.size();
    int imos[xn][yn][zn];
    memset(imos, 0, sizeof(imos));
    for(int i = 0; i < n; i++){
        int ix = lower_bound(x.begin(),x.end(),ax[i])-x.begin();
        int iy = lower_bound(y.begin(),y.end(),ay[i])-y.begin();
        int iz = lower_bound(z.begin(),z.end(),az[i])-z.begin();
        int jx = lower_bound(x.begin(),x.end(),bx[i])-x.begin();
        int jy = lower_bound(y.begin(),y.end(),by[i])-y.begin();
        int jz = lower_bound(z.begin(),z.end(),bz[i])-z.begin();
        imos[ix][iy][iz]++;
        imos[ix][jy][iz]--;
        imos[jx][iy][iz]--;
        imos[jx][jy][iz]++;
        imos[ix][iy][jz]--;
        imos[ix][jy][jz]++;
        imos[jx][iy][jz]++;
        imos[jx][jy][jz]--;
    }

    for(int k = 0; k < zn; k++){
        for(int j = 0; j < yn; j++){
            for(int i = 1; i < xn; i++){
                imos[i][j][k] += imos[i-1][j][k];
            }
        }
    }
    for(int k = 0; k < zn; k++){
        for(int i = 0; i < xn; i++){
            for(int j = 1; j < yn; j++){
                imos[i][j][k] += imos[i][j-1][k];
            }
        }
    }
    for(int i = 0; i < xn; i++){
        for(int j = 0; j < yn; j++){
            for(int k = 1; k < zn; k++){
                imos[i][j][k] += imos[i][j][k-1];
            }
        }
    }

    ll ans = 0;
    for(int i = 0; i < xn; i++){
        for(int j = 0; j < yn; j++){
            for(int k = 0; k < zn; k++){
                if(imos[i][j][k] < K)   continue;
                ans += (ll)(x[i+1]-x[i])*(y[j+1]-y[j])*(z[k+1]-z[k]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 7296
final_rank: 1

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void) {

	int N, K; cin >> N >> K;
	vector<vector<unsigned long long> > fishrange;
	vector<unsigned long long> x, y, d;

	unsigned long long volume = 0;

	for (int i = 0; i < N; i++) {
		vector<unsigned long long> range;
		int x1, y1, d1, x2, y2, d2; cin >> x1 >> y1 >> d1 >> x2 >> y2 >> d2;

		range.push_back(x1); range.push_back(y1); range.push_back(d1);
		range.push_back(x2); range.push_back(y2); range.push_back(d2);

		x.push_back(x1); x.push_back(x2);
		y.push_back(y1); y.push_back(y2);
		d.push_back(d1); d.push_back(d2);

		fishrange.push_back(range);
	}

	sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
	sort(y.begin(), y.end()); y.erase(unique(y.begin(), y.end()), y.end());
	sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end());

	for (int i = 0; i < (x.size() - 1); i++) {
		for (int j = 0; j < (y.size() - 1); j++) {

			for (int t = 0; t < (d.size() - 1); t++) {

				int count = 0;

				for (int s = 0; s < N; s++) {
					if (x[i] >= fishrange[s][0] && x[i + 1] <= fishrange[s][3] &&
						y[j] >= fishrange[s][1] && y[j + 1] <= fishrange[s][4] &&
						d[t] >= fishrange[s][2] && d[t + 1] <= fishrange[s][5])

						count++;
				}

				if (count >= K) volume += (x[i + 1] - x[i])*(y[j + 1] - y[j])*(d[t + 1] - d[t]);

			}
		}
	}

	cout << volume << endl;

	return 0;

}
accuracy: 1
time_ms: 50
memory_kb: 3156
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    vector<vector<long> > fishrange;
    vector<long> xi;
    vector<long> yi;
    vector<long> di;
    unsigned long long n,k,p,checker;
    unsigned long long volume = 0;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        vector<long> v;
        for(int j=0;j<6;j++)
        {
            int h;
            cin>>h;
            v.push_back(h);
        }
        fishrange.push_back(v);
        p = fishrange[i][0];
        xi.push_back(p);
        p = fishrange[i][3];
        xi.push_back(p);
        p = fishrange[i][1];
        yi.push_back(p);
        p = fishrange[i][4];
        yi.push_back(p);
        p = fishrange[i][2];
        di.push_back(p); 
        p = fishrange[i][5];
        di.push_back(p);
        
    }
    sort(xi.begin(),xi.end());
    xi.erase(unique(xi.begin(),xi.end()),xi.end());
    sort(yi.begin(),yi.end());
    yi.erase(unique(yi.begin(),yi.end()),yi.end());
    sort(di.begin(),di.end());
    di.erase(unique(di.begin(),di.end()),di.end());
    
    for(int i=0;i<n*2-1;i++)
    {
        for(int j=0;j<n*2-1;j++)
        {
            for(int l=0;l<n*2-1;l++)
            {
                checker = 0;
                for(int c=0;c<n;c++)
                {
                    if(xi[i]>=fishrange[c][0]&&xi[i+1]<=fishrange[c][3]&&yi[j]>=fishrange[c][1]&&yi[j+1]<=fishrange[c][4]&&di[l]>=fishrange[c][2]&&di[l+1]<=fishrange[c][5])
                    checker++;
                }
                if(checker>=k)
                 volume += (xi[i+1]-xi[i])*(yi[j+1]-yi[j])*(di[l+1]-di[l]);
            }
        }
    }
    
  
    cout<<volume<<endl;
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3140
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    vector<vector<int> > fishrange;
    vector<int> xi;
    vector<int> yi;
    vector<int> di;
    int n,k,p,checker;
    unsigned long long volume = 0;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        vector<int> v;
        for(int j=0;j<6;j++)
        {
            int h;
            cin>>h;
            v.push_back(h);
        }
        fishrange.push_back(v);
        p = fishrange[i][0];
        xi.push_back(p);
        p = fishrange[i][3];
        xi.push_back(p);
        p = fishrange[i][1];
        yi.push_back(p);
        p = fishrange[i][4];
        yi.push_back(p);
        p = fishrange[i][2];
        di.push_back(p); 
        p = fishrange[i][5];
        di.push_back(p);
        
    }
    sort(xi.begin(),xi.end());
    xi.erase(unique(xi.begin(),xi.end()),xi.end());
    sort(yi.begin(),yi.end());
    yi.erase(unique(yi.begin(),yi.end()),yi.end());
    sort(di.begin(),di.end());
    di.erase(unique(di.begin(),di.end()),di.end());
    
    for(int i=0;i<n*2-1;i++)
    {
        for(int j=0;j<n*2-1;j++)
        {
            for(int l=0;l<n*2-1;l++)
            {
                checker = 0;
                for(int c=0;c<n;c++)
                {
                    if(xi[i]>=fishrange[c][0]&&xi[i+1]<=fishrange[c][3]&&yi[j]>=fishrange[c][1]&&yi[j+1]<=fishrange[c][4]&&di[l]>=fishrange[c][2]&&di[l+1]<=fishrange[c][5])
                    checker++;
                }
                if(checker>=k)
                 volume += (xi[i+1]-xi[i])*(yi[j+1]-yi[j])*(di[l+1]-di[l]);
            }
        }
    }
    
  
    cout<<volume<<endl;
    return 0;
}
accuracy: 0.2
time_ms: 40
memory_kb: 3104
final_rank: 20

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
ll dx[4] = {1,0,0,-1};
ll dy[4] = {0,1,-1,0};

#define ARRAY_MAX 55
ll n,k,h,w,d;
ll X1[ARRAY_MAX],X2[ARRAY_MAX],Y1[ARRAY_MAX],Y2[ARRAY_MAX],D1[ARRAY_MAX],D2[ARRAY_MAX];
ll field[ARRAY_MAX*4][ARRAY_MAX*4][ARRAY_MAX*4];
vector<ll> xs,ys,ds,xunzip,yunzip,dunzip;
map<ll,ll> xzip,yzip,dzip;

void compress(vector<ll>& x,map<ll,ll>& zip,vector<ll>& unzip){

    VSORT(x);
    x.erase(unique(x.begin(),x.end()),x.end());
    unzip.resize(x.size());
    REP(i,x.size()){
        zip[x[i]] = i;
        unzip[i] = x[i];
    }
}


int main(){


    cin >> n >> k;
    
    REP(i,n){
        cin >> X1[i] >> Y1[i] >> D1[i] >> X2[i] >> Y2[i] >> D2[i];
        xs.push_back(X1[i]);
        xs.push_back(X2[i]);
        ys.push_back(Y1[i]);
        ys.push_back(Y2[i]);
        ds.push_back(D1[i]);
        ds.push_back(D2[i]);
    }

    compress(xs,xzip,xunzip);
    compress(ys,yzip,yunzip);
    compress(ds,dzip,dunzip);

    w = xzip.size();
    h = yzip.size();
    d = dzip.size();

    REP(i,n){
        field[yzip[Y1[i]]][xzip[X1[i]]][dzip[D1[i]]]++;
        field[yzip[Y1[i]]][xzip[X2[i]]][dzip[D1[i]]]--;
        field[yzip[Y2[i]]][xzip[X1[i]]][dzip[D1[i]]]--;
        field[yzip[Y2[i]]][xzip[X2[i]]][dzip[D1[i]]]++;
        field[yzip[Y1[i]]][xzip[X1[i]]][dzip[D2[i]]]--;
        field[yzip[Y1[i]]][xzip[X2[i]]][dzip[D2[i]]]++;
        field[yzip[Y2[i]]][xzip[X1[i]]][dzip[D2[i]]]++;
        field[yzip[Y2[i]]][xzip[X2[i]]][dzip[D2[i]]]--;
    }
        
    REP(i,h+1)REP(j,w)REP(m,d){//横
        field[i][j+1][m] += field[i][j][m];
    }


    REP(j,w+1)REP(i,h)REP(m,d){//縦
        field[i+1][j][m] += field[i][j][m];
    }

    REP(m,d+1)REP(i,h)REP(j,w){
        field[i][j][m+1] += field[i][j][m];
    }

    ll ans = 0;
    REP(i,h)REP(j,w)REP(m,d){
        if(field[i][j][m] >= k){
            ans += (yunzip[i+1] - yunzip[i])*(xunzip[j+1] - xunzip[j])*(dunzip[m+1] - dunzip[m]);

        }
    }
    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 20916
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> mp;
typedef pair<mp ,int> mypair;
typedef pair<mp,pair<mp,mp> > tri;
typedef long long int ll;
void print(vector<int> a){
	for(int i=0;i<a.size();i++)cout<<a[i]<<' ';
	cout<<endl;
}
void print(vector<mp> a){
	for(int i=0;i<a.size();i++)cout<<" ("<<a[i].first<<" ,"<<a[i].second<<")" ;
	cout<<endl;
}
int main(){
	int n,m;
	cin>>n>>m;
	vector<int> x,y,d;
	vector<mp> mx(n),my(n),md(n);
	for(int i=0;i<n;i++){
		int x1,x2,y1,y2,d1,d2;
		cin>>x1>>y1>>d1>>x2>>y2>>d2;
		x.push_back(x1);
		x.push_back(x2);
		y.push_back(y1);
		y.push_back(y2);
		d.push_back(d1);
		d.push_back(d2);
		mx[i]=mp(x1,x2);
		my[i]=mp(y1,y2);
		md[i] =mp(d1,d2);
	}
	sort(x.begin(),x.end());
	sort(y.begin(),y.end());
	sort(d.begin(),d.end() );
	//cout<<endl;
	//print(x);
	//print(y);
	//print(d);
	//cout<<endl;
	//print(mx);
	//print(my);
	//print(md);
	//cout<<endl;
	//sort(map.begin(),map.end() );
	ll  ans = 0;
	for(int i=0;i<x.size()-1;i++){
			if(x[i]==x[i+1])continue;
		for(int j=0;j<y.size()-1;j++){
				if(y[j]==y[j+1])continue;
			for(int k=0;k<d.size()-1;k++){
				if(d[k]==d[k+1])continue;
				int cnt=0;
				for(int t=0;t<n;t++){
					mp nx = mx[t];
					mp ny = my[t];
					mp nd = md[t];
					
					if(nx.first<=x[i]&&x[i+1]<=nx.second&&
							ny.first<=y[j]&&y[j+1]<=ny.second&&
							nd.first<=d[k]&&d[k+1]<=nd.second){
						cnt++;
					}
				}
				if(cnt>=m){
					ll tmp=(ll( x[i+1]-x[i]))*(ll(y[j+1]-y[j]) )*(ll(d[k+1]-d[k]) );
					//cout<<x[i]<<' '<<y[j]<<' '<<d[k]<<" "<<tmp<<endl;
					ans+=tmp;
				}
			}	
		}
	}
	cout<<ans<<endl;

	return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 3168
final_rank: 15

code_snippet: // #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int X1[210], Y1[210], Z1[210], X2[210], Y2[210], Z2[210];
int rX[210], rY[210], rZ[210];
int sum[210][210][210];
signed main() {
    int N, K; cin >> N >> K;
    map<int, int> cmpx, cmpy, cmpz;

    // int acc[210][210][210];
    for(int i=0; i<N; i++) {
        int x1, y1, z1, x2, y2, z2;
        cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
        cmpx[x1]++; cmpx[x2]++; // cmpx[x2+1]++;
        cmpy[y1]++; cmpy[y2]++; // cmpy[y2+1]++;
        cmpz[z1]++; cmpz[z2]++; // cmpz[z2+1]++;

        X1[i] = x1, Y1[i] = y1, Z1[i] = z1;
        X2[i] = x2, Y2[i] = y2, Z2[i] = z2;
    }

    int idx = 0, idy = 0, idz = 0;
    for(auto &e : cmpx) rX[idx] = e.first, e.second = idx++;
    for(auto &e : cmpy) rY[idy] = e.first, e.second = idy++;
    for(auto &e : cmpz) rZ[idz] = e.first, e.second = idz++;

    for(int i=0; i<N; i++) {
        int lb = cmpz[ Z1[i] ], ub = cmpz[ Z2[i] ];
        for(int z=lb; z<ub; z++) {
            int lx = cmpx[ X1[i] ], rx = cmpx[ X2[i] ];
            int ly = cmpy[ Y1[i] ], ry = cmpy[ Y2[i] ];
            for(int x=lx; x<rx; x++) {
                for(int y=ly; y<ry; y++) {
                    sum[x][y][z]++;
                }
            }
        }
    }

    int ans = 0;
    for(int i=0; i<idx; i++) {
        for(int j=0; j<idy; j++) {
            for(int k=0; k<idz; k++) {
                if(sum[i][j][k] >= K) {
                    int diff_x = rX[i+1] - rX[i];
                    int diff_y = rY[j+1] - rY[j];
                    int diff_z = rZ[k+1] - rZ[k];
                    ans += diff_x * diff_y * diff_z;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 17668
final_rank: 13