#include<bits/stdc++.h>
#define task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 1e5 + 5;
const ll INF = 1e18 + 5;
int n, d, m;
pair<int, int> point[MAXN];
void Input()
{
cin >> n >> n >> d >> m;
for (int i = 1; i <= n; i++)
{
int x, y;
cin >> x >> y;
point[i] = {x - y + m, x + y};
}
}
struct BIT2D
{
vector<vector<int>> fe, node;
int sz;
void Init(int _sz)
{
sz = _sz;
fe.resize(sz + 5);
node.resize(sz + 5);
}
void fakeAdd(int x, int y)
{
for (; x <= sz; x += x & -x)
node[x].pb(y);
}
void fakeGet(int x, int y)
{
for (; x; x -= x & -x)
node[x].pb(y);
}
void Build()
{
for (int i = 1; i <= sz; i++)
{
sort(node[i].begin(), node[i].end());
fe[i].resize((int)node[i].size() + 5);
}
}
void add(int x, int y, int val)
{
for (; x <= sz; x += x & -x)
{
for (int j = lower_bound(node[x].begin(), node[x].end(), y) - node[x].begin() + 1; j <= node[x].size(); j += j & -j)
{
fe[x][j] += val;
}
}
}
int get(int x, int y)
{
int res = 0;
for (; x; x -= x & -x)
{
for (int j = lower_bound(node[x].begin(), node[x].end(), y) - node[x].begin() + 1; j; j -= j & -j)
{
res += fe[x][j];
}
}
return res;
}
};
void Solve()
{
m *= 2;
m++;
BIT2D bit;
bit.Init(m);
for (int i = 1; i <= n; i++)
{
bit.fakeAdd(point[i].fi, point[i].se);
bit.fakeGet(point[i].fi + d, point[i].se + d);
bit.fakeGet(max(0, point[i].fi - d - 1), point[i].se + d);
bit.fakeGet(point[i].fi + d, max(0, point[i].se - d - 1));
bit.fakeGet(max(0, point[i].fi - d - 1), max(0, point[i].se - d - 1));
}
bit.Build();
ll ans = 0;
for (int i = 1; i <= n; i++)
{
ans += bit.get(point[i].fi + d, point[i].se + d);
ans -= bit.get(max(0, point[i].fi - d - 1), point[i].se + d);
ans -= bit.get(point[i].fi + d, max(0, point[i].se - d - 1));
ans += bit.get(max(0, point[i].fi - d - 1), max(0, point[i].se - d - 1));
bit.add(point[i].fi, point[i].se, 1);
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(task".INP","r"))
{
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
Input();
Solve();
}
Compilation message
pairs.cpp: In member function 'void BIT2D::add(int, int, int)':
pairs.cpp:63:98: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for (int j = lower_bound(node[x].begin(), node[x].end(), y) - node[x].begin() + 1; j <= node[x].size(); j += j & -j)
| ~~^~~~~~~~~~~~~~~~~
pairs.cpp: In function 'int main()':
pairs.cpp:118:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
118 | freopen(task".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
199 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
403 ms |
25288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
218 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
232 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
12720 KB |
Output is correct |
2 |
Runtime error |
31 ms |
25536 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
141 ms |
35784 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
2388 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
171 ms |
63812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
183 ms |
10768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
2132 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
13 ms |
2132 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |