#include <bits/stdc++.h>
#define ub(x) (x&(-x))
using namespace std;
constexpr int MMAX2 = 75002;
constexpr int MMAX3 = 77;
typedef long long LL;
int Modul (int x) {
if (x < 0) x = -x;
return x;
}
int N, D, M;
void Task_1 () {
cin >> N >> D >> M;
vector <int> V(N);
for (int i = 0; i < N; ++ i )
cin >> V[i];
sort(V.begin(), V.end());
int left = 0;
LL ans = 0;
for (int i = 0; i < N; ++ i ) {
while (left < i && V[left] < V[i] - D) ++ left;
ans += 1LL * (i - left);
}
cout << ans << '\n';
}
int aib[2*MMAX2];
void Update (int pos, int val) {
for (int i = pos; i <= 2 * M; i += ub(i))
aib[i] += val;
}
int Query (int pos) {
int S = 0;
for (int i = pos; i; i -= ub(i))
S += aib[i];
return S;
}
void Task_2 () {
cin >> N >> D >> M;
vector <pair <int, int> > V(N);
for (int i = 0; i < N; ++ i ) {
int x, y;
cin >> x >> y;
V[i].first = x + y;
V[i].second = x - y;
}
sort(V.begin(), V.end());
int left = 0;
LL ans = 0;
for (int i = 0; i < N; ++ i ) {
Update(V[i].second + M, 1);
while (left < i && V[left].first < V[i].first - D) {
Update(V[left].second + M, -1);
++ left;
}
ans += 1LL * (Query(min(2*M, V[i].second + M + D)) - Query(max(0, V[i].second + M - D - 1)) - 1);
}
cout << ans << '\n';
}
struct tridimensional {
int x, y, z;
};
int mat[MMAX3][MMAX3][MMAX3];
void Task_3() {
cin >> N >> D >> M;
vector <tridimensional> V(N);
for (int i = 0; i < N; ++ i ) {
int x, y, z;
cin >> x >> y >> z;
V[i] = {x, y - z + M, y + z};
mat[V[i].x][V[i].y][V[i].z] ++;
}
for (int i = 1; i <= M; ++ i ) {
for (int j = 0; j <= 2*M; ++ j ) {
for (int k = 0; k <= 2*M; ++ k ) {
if (j > 0) mat[i][j][k] += mat[i][j-1][k];
if (k > 0) mat[i][j][k] += mat[i][j][k-1];
if (j > 0 && k > 0) mat[i][j][k] -= mat[i][j-1][k-1];
}
}
}
LL ans = 0;
for (int i = 0; i < N; ++ i ) {
for (int X = 1; X <= M; ++ X ) {
int dist_left = D - Modul(X - V[i].x);
if (dist_left < 0) continue;
int X_st = max(0, V[i].y - dist_left - 1), Y_st = max(0, V[i].z - dist_left - 1);
int X_dr = min(2*M, V[i].y + dist_left), Y_dr = min(2*M, V[i].z + dist_left);
ans += 1LL * (mat[X][X_dr][Y_dr] - mat[X][X_st][Y_dr] - mat[X][X_dr][Y_st] + mat[X][X_st][Y_st]);
}
-- ans;
}
cout << ans / 2 << '\n';
}
void Solve (int B) {
if (B == 1) {
Task_1();
return;
}
if (B == 2) {
Task_2();
return;
}
if (B == 3) {
Task_3();
return;
}
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int B;
cin >> B;
Solve(B);
return 0;
}
# |
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 |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1100 KB |
Output is correct |
2 |
Correct |
12 ms |
1092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
1480 KB |
Output is correct |
2 |
Correct |
17 ms |
1484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
1480 KB |
Output is correct |
2 |
Correct |
18 ms |
1484 KB |
Output is correct |
3 |
Correct |
15 ms |
1484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
844 KB |
Output is correct |
2 |
Correct |
1 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1696 KB |
Output is correct |
2 |
Correct |
20 ms |
1612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1872 KB |
Output is correct |
2 |
Correct |
27 ms |
1876 KB |
Output is correct |
3 |
Correct |
24 ms |
1896 KB |
Output is correct |
4 |
Correct |
26 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
2772 KB |
Output is correct |
2 |
Correct |
30 ms |
2764 KB |
Output is correct |
3 |
Correct |
29 ms |
2756 KB |
Output is correct |
4 |
Correct |
28 ms |
2748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
1996 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
2220 KB |
Output is correct |
2 |
Correct |
19 ms |
2124 KB |
Output is correct |
3 |
Correct |
21 ms |
2084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
3668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
82 ms |
4044 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |