# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
625329 |
2022-08-10T04:32:11 Z |
DeMen100ns |
Pairs (IOI07_pairs) |
C++17 |
|
289 ms |
62008 KB |
//icant
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ar array
const int INF = 1e17;
const int MOD = 998244353;
template<class T, int... Ns> struct BIT {
T val = 0;
void upd(T v) { val += v; }
T query() { return val; }
};
template<class T, int N, int... Ns> struct BIT<T, N, Ns...> {
BIT<T, Ns...> bit[N+1];
template<typename... Args> void upd(int pos, Args... args) {
for (; pos <= N; pos += pos&-pos) bit[pos].upd(args...);
}
template<typename... Args> T sum(int pos, Args... args) {
T res = 0; for (; pos > 0; pos -= pos&-pos) res += bit[pos].query(args...);
return res;
}
template<typename... Args> T query(int l, int r, Args... args) {
return sum(r, args...) - sum(l-1, args...);
}
};
BIT<int, 301, 301, 301> bit2;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int b, n, d, m; cin>>b>>n>>d>>m;
int ans = 0;
if (b == 1) {
vector<int> a(n); for (int &i : a) cin>>i;
sort(a.begin(), a.end());
int lo = 0, hi = 0;
for (int i = 0; i < n; i++) {
while (hi + 1 < n && a[hi+1] - a[i] <= d) hi++;
while (lo < n && a[i] - a[lo] > d) lo++;
ans += hi - lo;
}
} else if (b == 2) {
vector<ar<int,2>> a(n);
for (int i = 0; i < n; i++) {
int x, y; cin>>x>>y;
a[i] = {x+y, x-y};
}
BIT<int, 150001> bit;
sort(a.begin(), a.end());
int lo = 0, hi = -1;
for (int i = 0; i < n; i++) {
while (hi + 1 < n && a[hi+1][0] - a[i][0] <= d) bit.upd(a[++hi][1] + m+1, 1);
while (lo < n && a[i][0] - a[lo][0] > d) bit.upd(a[lo++][1] + m+1, -1);
ans += bit.query(max(1LL, a[i][1] + m+1 - d), min(a[i][1] + m+1 + d, 2*m+1)) - 1;
}
} else {
vector<ar<int,4>> a(n);
for (int i = 0; i < n; i++) {
int x, y, z; cin>>x>>y>>z;
a[i] = {x+y+z, x+y-z, x-y+z, x-y-z};
}
// [-2*m, 2*m] 1 -> -2*m, 4*m+1 -> 2*m
sort(a.begin(), a.end());
int lo = 0, hi = -1;
for (int i = 0; i < n; i++) {
while (hi + 1 < n && a[hi+1][0] - a[i][0] <= d) {
++hi;
bit2.upd(a[hi][1] + 2*m+1, a[hi][2] + 2*m+1, a[hi][3] + 2*m+1, 1);
}
while (lo < n && a[i][0] - a[lo][0] > d) {
bit2.upd(a[lo][1] + 2*m+1, a[lo][2] + 2*m+1, a[lo][3] + 2*m+1, -1);
lo++;
}
ans += bit2.query(max(1LL, a[i][1] + 2*m+1 - d), min(a[i][1] + 2*m+1 + d, 4*m+1),
max(1LL, a[i][2] + 2*m+1 - d), min(a[i][2] + 2*m+1 + d, 4*m+1),
max(1LL, a[i][3] + 2*m+1 - d), min(a[i][3] + 2*m+1 + d, 4*m+1)) - 1;
}
}
cout<<ans/2<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2660 KB |
Output is correct |
2 |
Correct |
16 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
3056 KB |
Output is correct |
2 |
Correct |
18 ms |
3136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
3156 KB |
Output is correct |
2 |
Correct |
19 ms |
3092 KB |
Output is correct |
3 |
Correct |
17 ms |
3156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1508 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
3560 KB |
Output is correct |
2 |
Correct |
27 ms |
3540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3816 KB |
Output is correct |
2 |
Correct |
30 ms |
3796 KB |
Output is correct |
3 |
Correct |
30 ms |
3832 KB |
Output is correct |
4 |
Correct |
29 ms |
3796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
4212 KB |
Output is correct |
2 |
Correct |
33 ms |
4180 KB |
Output is correct |
3 |
Correct |
33 ms |
4180 KB |
Output is correct |
4 |
Correct |
30 ms |
4180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
22740 KB |
Output is correct |
2 |
Correct |
9 ms |
22908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
7464 KB |
Output is correct |
2 |
Correct |
87 ms |
7428 KB |
Output is correct |
3 |
Correct |
60 ms |
7468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
43888 KB |
Output is correct |
2 |
Correct |
203 ms |
44076 KB |
Output is correct |
3 |
Correct |
102 ms |
43872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
289 ms |
62008 KB |
Output is correct |
2 |
Correct |
239 ms |
61932 KB |
Output is correct |
3 |
Correct |
127 ms |
61948 KB |
Output is correct |