#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using pint = pair <int, int>;
using tint = array <int, 3>;
int b, n, d, m;
LL ans = 0;
void calc1()
{
vector <int> A(n);
for (int i = 0; i < n; i++) scanf("%d", &A[i]);
sort(A.begin(), A.end());
for (int i = 1, j = 0; i < n; i++){
while (A[i] - A[j] > d) j++;
ans += i - j;
}
}
struct seg1D {
int node[800000], nn = 160000;
void update(int x, int val){
for (x += nn - 1; x > 0; x /= 2) node[x] += val;
}
int query(int L, int R){
int ret = 0;
for (L += nn - 1, R += nn - 1; L <= R; L /= 2, R /= 2){
if (L % 2 == 1) ret += node[L++];
if (R % 2 == 0) ret += node[R--];
}
return ret;
}
};
void calc2()
{
vector <pint> A(n);
for (int i = 0, x, y; i < n; i++){
scanf("%d %d", &x, &y);
A[i] = {x + y, x - y + 75001};
}
sort(A.begin(), A.end());
seg1D tree;
tree.update(A[0].second, 1);
for (int i = 1, j = 0; i < n; i++){
while (A[i].first - A[j].first > d){
tree.update(A[j].second, -1);
j++;
}
ans += tree.query(A[i].second - d, min(A[i].second + d, 160000));
tree.update(A[i].second, 1);
}
}
int s[80][160][160];
void calc3()
{
vector <tint> A(n);
for (int i = 0, x, y, z; i < n; i++){
scanf("%d %d %d", &x, &y, &z);
s[z][x + y][x - y + 80]++;
A[i] = {x, y, z};
}
for (int z = 0; z <= 75; z++){
for (int i = 1; i < 160; i++){
for (int j = 1; j < 160; j++){
s[z][i][j] += s[z][i - 1][j] + s[z][i][j - 1] - s[z][i - 1][j - 1];
}
}
}
for (int i = 0, d1, d2, az; i < n; i++){
d1 = A[i][0] + A[i][1], d2 = A[i][0] - A[i][1] + 75, az = A[i][2];
for (int j = 0; j <= 75; j++){
int dist = d - abs(az - j);
if (dist < 0) continue;
ans += s[j][min(dist + d1, 159)][min(dist + d2, 159)];
ans -= s[j][min(dist + d1, 150)][max(-dist + d2 - 1, 0)];
ans -= s[j][max(-dist + d1 - 1, 0)][min(dist + d2, 159)];
ans += s[j][max(-dist + d1 - 1, 0)][max(-dist + d2 - 1, 0)];
}
ans -= 1;
}
ans /= 2;
}
int main()
{
scanf("%d %d %d %d", &b, &n, &d, &m);
if (b == 1) calc1();
if (b == 2) calc2();
if (b == 3) calc3();
printf("%lld\n", ans);
return 0;
}
Compilation message
pairs.cpp: In function 'void calc1()':
pairs.cpp:12:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | for (int i = 0; i < n; i++) scanf("%d", &A[i]);
| ~~~~~^~~~~~~~~~~~~
pairs.cpp: In function 'void calc2()':
pairs.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
pairs.cpp: In function 'void calc3()':
pairs.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | scanf("%d %d %d", &x, &y, &z);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp: In function 'int main()':
pairs.cpp:90:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | scanf("%d %d %d %d", &b, &n, &d, &m);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
872 KB |
Output is correct |
2 |
Correct |
12 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
852 KB |
Output is correct |
2 |
Correct |
15 ms |
900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
852 KB |
Output is correct |
2 |
Correct |
16 ms |
888 KB |
Output is correct |
3 |
Correct |
15 ms |
924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Incorrect |
2 ms |
3412 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
4436 KB |
Output is correct |
2 |
Correct |
29 ms |
4548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
4436 KB |
Output is correct |
2 |
Correct |
31 ms |
4448 KB |
Output is correct |
3 |
Correct |
28 ms |
4364 KB |
Output is correct |
4 |
Correct |
30 ms |
4436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
4364 KB |
Output is correct |
2 |
Incorrect |
37 ms |
4468 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
7836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
42 ms |
9308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
59 ms |
9256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
119 ms |
9292 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |