# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
213607 |
2020-03-26T09:15:51 Z |
tatyam |
Pairs (IOI07_pairs) |
C++17 |
|
4000 ms |
14456 KB |
#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 |
1 |
Correct |
5 ms |
256 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 |
75 ms |
10104 KB |
Output is correct |
2 |
Correct |
67 ms |
10104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
10116 KB |
Output is correct |
2 |
Correct |
73 ms |
10104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
10104 KB |
Output is correct |
2 |
Correct |
92 ms |
10104 KB |
Output is correct |
3 |
Correct |
86 ms |
10232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
282 ms |
10488 KB |
Output is correct |
2 |
Correct |
161 ms |
10488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
578 ms |
10488 KB |
Output is correct |
2 |
Correct |
1707 ms |
10488 KB |
Output is correct |
3 |
Correct |
1307 ms |
10488 KB |
Output is correct |
4 |
Correct |
1251 ms |
10488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
617 ms |
10488 KB |
Output is correct |
2 |
Correct |
1737 ms |
10488 KB |
Output is correct |
3 |
Correct |
785 ms |
10488 KB |
Output is correct |
4 |
Correct |
612 ms |
10488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
450 ms |
14456 KB |
Output is correct |
2 |
Execution timed out |
4101 ms |
14456 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1450 ms |
14456 KB |
Output is correct |
2 |
Execution timed out |
4097 ms |
14456 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4100 ms |
14456 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |