# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
714093 |
2023-03-23T22:15:08 Z |
SlavicG |
Pairs (IOI07_pairs) |
C++17 |
|
326 ms |
98644 KB |
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
#define int long long
const int N = 1e6;
int fen[N];
void modif(int u, int val) {
for(int i = u + 1; i < N; i += i & -i) fen[i] += val;
}
int query(int l, int r) {
int ans = 0;
for(int i = r + 1; i >= 1; i -= i & -i) ans += fen[i];
for(int i = l; i >= 1; i -= i & -i) ans -= fen[i];
return ans;
}
const int K = 500, offset = 200;
int ugh[K][K][K];
void modif(int a, int b, int c, int val) {
for(int i = a + offset; i < K; i += i & -i) {
for(int j = b + offset; j < K; j += j & -j) {
for(int f = c + offset; f < K; f += f & -f) {
ugh[i][j][f] += val;
}
}
}
}
int query(int x1, int y1, int z1, int x2, int y2, int z2) {
x1 += offset, x2 += offset, y1 += offset, y2 += offset, z1 += offset, z2 += offset;
int ans = 0;
for(int i = x2; i >= 1; i -= i & -i) {
for(int j = y2; j >= 1; j -= j & -j) {
for(int k = z2; k >= 1; k -= k & -k) {
ans += ugh[i][j][k];
}
for(int k = z1 - 1; k >= 1; k -= k & -k) {
ans -= ugh[i][j][k];
}
}
for(int j = y1 - 1; j >= 1; j -= j & -j) {
for(int k = z2; k >= 1; k -= k & -k) {
ans -= ugh[i][j][k];
}
for(int k = z1 - 1; k >= 1; k -= k & -k) {
ans += ugh[i][j][k];
}
}
}
for(int i = x1 - 1; i >= 1; i -= i & -i) {
for(int j = y2; j >= 1; j -= j & -j) {
for(int k = z2; k >= 1; k -= k & -k) {
ans -= ugh[i][j][k];
}
for(int k = z1 - 1; k >= 1; k -= k & -k) {
ans += ugh[i][j][k];
}
}
for(int j = y1 - 1; j >= 1; j -= j & -j) {
for(int k = z2; k >= 1; k -= k & -k) {
ans += ugh[i][j][k];
}
for(int k = z1 - 1; k >= 1; k -= k & -k) {
ans -= ugh[i][j][k];
}
}
}
return ans;
}
void solve() {
int b, n, d, m; cin >> b >> n >> d >> m;
if(b == 1) {
vector<int> a(n);
for(int i = 0; i < n; ++i) cin >> a[i];
sort(all(a));
int ans = 0;
for(int i = 0; i < n; ++i) {
int j = upper_bound(all(a), a[i] + d) - a.begin();
ans += j - i - 1;
}
cout << ans << "\n";
} else if(b == 2) {
vector<pair<int, int>> a;
for(int i = 0; i < n; ++i) {
int x, y; cin >> x >> y;
a.pb({x - y, x + y});
}
queue<int> q;
sort(all(a));
int ans = 0;
for(int i = 0; i < n; ++i) {
while(!q.empty() && abs(a[i].first - a[q.front()].first) > d) {
modif(a[q.front()].second, -1);
q.pop();
}
ans += query(a[i].second - d, min(a[i].second + d, N - 2));
q.push(i);
modif(a[i].second, 1);
}
cout << ans << "\n";
} else {
vector<array<int, 4>> a;
for(int i = 0; i < n; ++i) {
int x, y, z; cin >> x >> y >> z;
a.pb({x + y + z, x + y - z, x - y + z, x - y - z});
}
sort(all(a));
queue<int> q;
int ans = 0;
for(int i = 0; i < n; ++i) {
while(!q.empty() && abs(a[i][0] - a[q.front()][0]) > d) {
modif(a[q.front()][1], a[q.front()][2], a[q.front()][3], -1);
q.pop();
}
ans += query(a[i][1] - d, a[i][2] - d, a[i][3] - d, min(a[i][1] + d, K - offset - 1), min(a[i][2] + d, K - offset - 1), min(a[i][3] + d, K - offset - 1));
modif(a[i][1], a[i][2], a[i][3], 1);
q.push(i);
}
cout << ans << "\n";
}
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while(t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1108 KB |
Output is correct |
2 |
Correct |
14 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1108 KB |
Output is correct |
2 |
Correct |
20 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
1108 KB |
Output is correct |
2 |
Correct |
22 ms |
1108 KB |
Output is correct |
3 |
Correct |
26 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
2 ms |
1512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
2512 KB |
Output is correct |
2 |
Correct |
26 ms |
2676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
2428 KB |
Output is correct |
2 |
Correct |
31 ms |
2456 KB |
Output is correct |
3 |
Correct |
38 ms |
2456 KB |
Output is correct |
4 |
Correct |
31 ms |
2512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
3140 KB |
Output is correct |
2 |
Correct |
36 ms |
3576 KB |
Output is correct |
3 |
Correct |
32 ms |
3404 KB |
Output is correct |
4 |
Correct |
32 ms |
3252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
26336 KB |
Output is correct |
2 |
Correct |
23 ms |
27212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
6448 KB |
Output is correct |
2 |
Correct |
121 ms |
7096 KB |
Output is correct |
3 |
Correct |
117 ms |
7444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
265 ms |
64944 KB |
Output is correct |
2 |
Correct |
237 ms |
65688 KB |
Output is correct |
3 |
Correct |
176 ms |
66608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
316 ms |
97240 KB |
Output is correct |
2 |
Correct |
326 ms |
97920 KB |
Output is correct |
3 |
Correct |
226 ms |
98644 KB |
Output is correct |