#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;
#define ii pair<int, int>
#define f first
#define s second
int b, n, d, m;
struct FT {
vector<int> ft;
int n;
void init(int _n) {
n = _n;
ft.assign(n, 0);
}
void upd(int k, int v) {
while (k <= n) {
ft[k] += v;
k += k&-k;
}
}
int qry(int k) {
k = min(k, n-1);
if (k <= 0) return 0;
int sum = 0;
while (k) {
sum += ft[k];
k -= k&-k;
}
return sum;
}
};
int main() {
cin >> b >> n >> d >> m;
if (b == 1) {
Tree<pair<int, int>> TS;
long long ans = 0;
vector<int> nums;
for (int i = 0; i < n; i++) {
int x; cin >> x;
nums.push_back(x);
}
sort(nums.begin(), nums.end());
int ct = 0;
for (int x : nums) {
ans += ct-TS.order_of_key(make_pair(x-d, 0));
TS.insert(make_pair(x, ct++));
}
cout << ans << endl;
} else if (b == 2) {
vector<ii> nums;
for (int i = 0; i < n; i++) {
int x, y; cin >> x >> y;
nums.push_back(make_pair(x-y, x+y));
}
sort(nums.begin(), nums.end());
int l = 0;
FT ft; ft.init(2*m+1);
long long ans = 0;
for (int r = 0; r < n; r++) {
while (nums[r].f - nums[l].f > d) {
ft.upd(nums[l].s, -1);
l++;
}
ans += ft.qry(nums[r].s+d) - ft.qry(nums[r].s-d-1);
ft.upd(nums[r].s, 1);
}
cout << ans << endl;
} else {
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
7408 KB |
Output is correct |
2 |
Correct |
121 ms |
7408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
155 ms |
7936 KB |
Output is correct |
2 |
Correct |
152 ms |
7788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
157 ms |
7792 KB |
Output is correct |
2 |
Correct |
171 ms |
7788 KB |
Output is correct |
3 |
Correct |
158 ms |
7792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
896 KB |
Output is correct |
2 |
Correct |
2 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
2040 KB |
Output is correct |
2 |
Correct |
73 ms |
2032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
2204 KB |
Output is correct |
2 |
Correct |
82 ms |
2288 KB |
Output is correct |
3 |
Correct |
81 ms |
2288 KB |
Output is correct |
4 |
Correct |
82 ms |
2160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
2920 KB |
Output is correct |
2 |
Correct |
103 ms |
2920 KB |
Output is correct |
3 |
Correct |
104 ms |
2956 KB |
Output is correct |
4 |
Correct |
103 ms |
2924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |