# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
213587 |
2020-03-26T08:23:34 Z |
tatyam |
Pairs (IOI07_pairs) |
C++17 |
|
4000 ms |
15352 KB |
#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 |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
10496 KB |
Output is correct |
2 |
Correct |
40 ms |
10616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
11000 KB |
Output is correct |
2 |
Correct |
49 ms |
11000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
11000 KB |
Output is correct |
2 |
Correct |
64 ms |
11000 KB |
Output is correct |
3 |
Correct |
60 ms |
11000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
236 ms |
11128 KB |
Output is correct |
2 |
Correct |
120 ms |
11132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
533 ms |
11256 KB |
Output is correct |
2 |
Correct |
1674 ms |
11384 KB |
Output is correct |
3 |
Correct |
1240 ms |
11256 KB |
Output is correct |
4 |
Correct |
1177 ms |
11256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
561 ms |
11768 KB |
Output is correct |
2 |
Correct |
1674 ms |
11768 KB |
Output is correct |
3 |
Correct |
755 ms |
11640 KB |
Output is correct |
4 |
Correct |
571 ms |
11640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
523 ms |
15096 KB |
Output is correct |
2 |
Execution timed out |
4099 ms |
15096 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1696 ms |
15352 KB |
Output is correct |
2 |
Execution timed out |
4100 ms |
15352 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4100 ms |
15352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |