This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 0x3fffffff;
#define all(a) begin(a), end(a)
#define each(i,a) for(auto&& i : a)
#define overload2(_1, _2, name, ...) name
#define rep1(n) for(int i = 0; i < (n); ++i)
#define rep2(i, n) for(int i = 0; i < (n); ++i)
#define rep(...) overload2(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
template<class T, class U> bool chmin(T& a, const U& b){ if(a > b){ a = b; return 1; } return 0; }
template<class T, class U> bool chmax(T& a, const U& b){ if(a < b){ a = b; return 1; } return 0; }
template<int B> struct kDTree{
kDTree *l, *r;
static constexpr int D = 1 << B - 1;
int min[D], max[D], size = 0;
using Array = array<int, D>;
using Iter = typename vector<Array>::iterator;
kDTree(Iter begin, Iter end, int div = 0){
size = end - begin;
each(i, min) i = INF;
each(i, max) i = -INF;
for(auto p = begin; p != end; p++){
auto& a = *p;
rep(D){
chmin(min[i], a[i]);
chmax(max[i], a[i]);
}
}
if(size == 1) return;
auto p = begin + size / 2;
nth_element(begin, p, end, [&](const Array& a, const Array& b){ return a[div] < b[div]; });
div++;
div %= B;
l = new kDTree(begin, p, div);
r = new kDTree(p, end, div);
}
int get(const Array& low, const Array& high){
rep(D) if(min[i] > high[i]) return 0;
rep(D) if(max[i] < low[i]) return 0;
rep(D) if(max[i] > high[i]) return l->get(low, high) + r->get(low, high);
rep(D) if(min[i] < low[i]) return l->get(low, high) + r->get(low, high);
return size;
}
inline int get(const Array& at, int d){
auto low = at, high = at;
each(i, low) i -= d;
each(i, high) i += d;
return get(low, high);
}
};
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int b, n, d, m;
cin >> b >> n >> d >> m;
ll ans = 0;
if(b == 1){
using Tree = kDTree<1>;
vector<Tree::Array> a(n);
each(i, a) each(j, i) cin >> j;
Tree tree(all(a));
each(i, a) ans += tree.get(i, d);
}
else if(b == 2){
using Tree = kDTree<2>;
vector<Tree::Array> a(n);
each(i, a) each(j, i) cin >> j;
each(i, a) i = {i[0] + i[1], i[0] - i[1]};
Tree tree(all(a));
each(i, a) ans += tree.get(i, d);
}
else{
using Tree = kDTree<3>;
vector<Tree::Array> a(n);
each(i, a) rep(j, 3) cin >> i[j];
each(i, a) i = {i[0] + i[1] + i[2], i[0] + i[1] - i[2], i[0] - i[1] + i[2], -i[0] + i[1] + i[2]};
Tree tree(all(a));
each(i, a) ans += tree.get(i, d);
}
ans -= n;
ans /= 2;
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |