This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
int min[B], max[B], size = 0;
using Array = array<int, B>;
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(B){
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(B) if(min[i] > high[i]) return 0;
rep(B) if(max[i] < low[i]) return 0;
rep(B) if(max[i] > high[i]) return l->get(low, high) + r->get(low, high);
rep(B) 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<4>;
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... |