JOI 2012-2013 問5 Fish
意外と簡単だったので悲しい。
しかし、一瞬だけ見て多倍長?と思って問6にいったのはマズかった。
#define FOR(i, a, b) for (int i = (a);i < (b); ++i) #define REP(i, n) FOR(i, 0, n) typedef long long LL; LL cube[128][128][128]; void create(vector<LL>& a, map<LL, LL>& b, map<LL, LL>& c) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); REP(i, a.size()) { b[a[i]] = i; c[i] = a[i]; } return; } int main() { LL x1[64], y1[64], z1[64]; LL x2[64], y2[64], z2[64]; vector<LL> xs, ys, zs; map<LL, LL> mx, my, mz, mxx, myy, mzz; LL N, K; cin >> N >> K; REP(i, N) { scanf("%lld%lld%lld%lld%lld%lld", x1 + i, y1 + i, z1 + i, x2 + i, y2 + i, z2 + i); xs.push_back(x1[i]); xs.push_back(x2[i]); ys.push_back(y1[i]); ys.push_back(y2[i]); zs.push_back(z1[i]); zs.push_back(z2[i]); } create(xs, mx, mxx); create(ys, my, myy); create(zs, mz, mzz); REP(i, N) FOR(x, mx[x1[i]], mx[x2[i]]) FOR(y, my[y1[i]], my[y2[i]]) FOR(z, mz[z1[i]], mz[z2[i]]) cube[x][y][z]++; LL res = 0; REP(x, 128) REP(y, 128) REP(z, 128) if(cube[x][y][z] >= K) res += (mxx[x+1]-mxx[x])*(myy[y+1]-myy[y])*(mzz[z+1]-mzz[z]); cout << res << endl; }