#include <bits/stdc++.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
ll min(const ll &a, const ll &b){
return (a < b) ? a : b;
}
ll max(const ll &a, const ll &b){
return (a > b) ? a : b;
}
const ll Mod = 1000000007;
const int maxN = 1e5 + 1;
int n, d, m;
struct TPoint{
int x, y = 0, z = 0;
bool operator < (const TPoint &other){
if (x == other.x){
if (y == other.y) return z < other.z;
return y < other.y;
}
return x < other.x;
}
};
struct TQuery{
int x, y, z, t;
bool operator < (const TQuery &other){
if (x == other.x) return t < other.t;
return x < other.x;
}
};
vector <TQuery> v;
TPoint a[maxN];
struct Node{
Node *l, *r;
int val;
Node(const int &x) : l(nullptr), r(nullptr), val(0){}
};
Node* root[75];
void create(Node *id){
if (!id->l){
id->l = new Node(0);
}
if (!id->r){
id->r = new Node(0);
}
}
void update(Node *id, int l, int r, int i, int x){
if (r < i || l > i) return;
if (l == r){
id->val += x;
return;
}
int m = (l + r) / 2;
create(id);
update(id->l, l, m, i, x);
update(id->r, m + 1, r, i, x);
id->val = id->l->val + id->r->val;
}
int get(Node *id, int l, int r, int i, int j){
if (r < i || l > j) return 0;
if (i <= l && r <= j){
return id->val;
}
int m = (l + r) / 2;
create(id);
return get(id->l, l, m, i, j) + get(id->r, m + 1, r, i, j);
}
void Init(){
int type; cin >> type >> n >> d >> m;
if (type == 1){
for (int i = 1; i <= n; ++i) cin >> a[i].x;
sort(a + 1, a + n + 1);
ll ans = 0;
for (int i = 1; i <= n; ++i){
TPoint tem = {a[i].x - d, 0, 0};
int k = lower_bound(a + 1, a + n + 1, tem) - a;
ans += i - k;
}
cout << ans;
}
if (type == 2){
ll ans = 0;
for (int i = 1; i <= n; ++i){
cin >> a[i].x >> a[i].y;
v.pb({a[i].x - a[i].y, a[i].x + a[i].y, 0, 1});
v.pb({a[i].x - a[i].y + d + 1 , a[i].x + a[i].y, 0, -1});
}
sort(v.begin(), v.end());
root[0] = new Node(0);
for (const auto &i : v){
if (i.t == -1){
update(root[0], 1, 150000, i.y, -1);
}
else{
ans += get(root[0], 1, 150000, max(1, i.y - d), i.y + d);
update(root[0], 1, 150000, i.y, 1);
}
}
cout << ans;
}
if (type == 3){
for (int i = 1; i <= n; ++i) cin >> a[i].x >> a[i].y >> a[i].z;
}
}
int main(){
if (fopen(taskname".txt", "r")){
freopen(taskname".txt", "r", stdin);
}
faster
//freopen(taskname.inp, "r", stdin)
//freopen(taskname.out, "w", stdout)
Init();
}
Compilation message
pairs.cpp: In function 'int main()':
pairs.cpp:125:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
125 | freopen(taskname".txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1496 KB |
Output is correct |
2 |
Correct |
18 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
1492 KB |
Output is correct |
2 |
Correct |
24 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
1492 KB |
Output is correct |
2 |
Correct |
24 ms |
1492 KB |
Output is correct |
3 |
Correct |
31 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2388 KB |
Output is correct |
2 |
Correct |
4 ms |
2388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
5708 KB |
Output is correct |
2 |
Correct |
115 ms |
6232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
128 ms |
5672 KB |
Output is correct |
2 |
Correct |
121 ms |
6392 KB |
Output is correct |
3 |
Correct |
101 ms |
6496 KB |
Output is correct |
4 |
Correct |
103 ms |
6476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
195 ms |
12568 KB |
Output is correct |
2 |
Correct |
165 ms |
14516 KB |
Output is correct |
3 |
Correct |
125 ms |
8196 KB |
Output is correct |
4 |
Correct |
116 ms |
7864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
1364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
1492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
1364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |