# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
456545 |
2021-08-07T01:10:17 Z |
dutch |
Pairs (IOI07_pairs) |
C++17 |
|
430 ms |
41984 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int LIM = 1e5+1, B = 250;
int b, n, d, ans, x[LIM], y[LIM], z[LIM], F[LIM*3];
int s[80][B][B];
void add(int i, int v){
for(; i<=LIM*3; i+=i&-i) F[i] += v;
}
int get(int i){
int v = 0;
for(; i>=1; i-=i&-i) v += F[i];
return v;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> b >> n >> d >> x[0];
if(b == 1){
for(int i=0; i<n; ++i)
cin >> x[i];
sort(x, x+n);
for(int i=0, j=0; i<n; ++i){
while(j < n && x[j]-x[i]<=d) ++j;
ans += j-i;
}
}
if(b == 2){
array<int, 2> a[n];
for(int i=0; i<n; ++i){
cin >> x[i] >> y[i];
a[i][1] = x[i] + y[i] + LIM;
a[i][0] = x[i] - y[i] + LIM;
}
sort(a, a+n);
for(int i=0; i<n; ++i){
x[i] = a[i][1];
y[i] = a[i][0];
}
int l = 0, r = 0;
for(int i=0; i<n; ++i){
while(r < n && y[r]-y[i] <= d)
add(x[r++], 1);
while(y[i]-y[l] > d)
add(x[l++], -1);
ans += get(x[i]+d) - get(x[i]-d-1);
}
}
if(b == 3){
for(int i=0; i<n; ++i){
cin >> x[n] >> y[n] >> z[i];
x[i] = x[n] + y[n] + 80;
y[i] = x[n] - y[n] + 80;
++s[z[i]][x[i]][y[i]];
}
for(int i=0; i<80; ++i)
for(int j=1; j<B; ++j)
for(int k=1; k<B; ++k)
s[i][j][k] += s[i][j-1][k] + s[i][j][k-1] - s[i][j-1][k-1];
for(int i=0; i<n; ++i){
int fLim = min(z[i]+d, 75LL), diff;
for(int f=max(z[i]-d, 0LL); f<=fLim; ++f){
diff = abs(z[i] - f);
int a1 = max(x[i] - d + diff - 1, 0LL);
int a2 = min(x[i] + d - diff, 249LL);
int b1 = max(y[i] - d + diff - 1, 0LL);
int b2 = min(y[i] + d - diff, 249LL);
ans += s[f][a2][b2] - s[f][a1][b2] - s[f][a2][b1] + s[f][a1][b1];
}
}
}
cout << (ans - n) / (1LL + (b > 1));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1240 KB |
Output is correct |
2 |
Correct |
15 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1228 KB |
Output is correct |
2 |
Correct |
21 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
1216 KB |
Output is correct |
2 |
Correct |
20 ms |
1232 KB |
Output is correct |
3 |
Correct |
20 ms |
1268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1356 KB |
Output is correct |
2 |
Correct |
2 ms |
1356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
3524 KB |
Output is correct |
2 |
Correct |
36 ms |
3620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
3636 KB |
Output is correct |
2 |
Correct |
39 ms |
3528 KB |
Output is correct |
3 |
Correct |
41 ms |
3624 KB |
Output is correct |
4 |
Correct |
40 ms |
3600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
4704 KB |
Output is correct |
2 |
Correct |
47 ms |
5604 KB |
Output is correct |
3 |
Correct |
42 ms |
5572 KB |
Output is correct |
4 |
Correct |
46 ms |
5612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
39408 KB |
Output is correct |
2 |
Correct |
34 ms |
39492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
41836 KB |
Output is correct |
2 |
Correct |
67 ms |
41936 KB |
Output is correct |
3 |
Correct |
80 ms |
41928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
41936 KB |
Output is correct |
2 |
Correct |
390 ms |
41984 KB |
Output is correct |
3 |
Correct |
244 ms |
41948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
271 ms |
41952 KB |
Output is correct |
2 |
Correct |
430 ms |
41924 KB |
Output is correct |
3 |
Correct |
276 ms |
41952 KB |
Output is correct |