栓Q
by sketchi @ 2023-11-19 15:08:48
@[Anahita](/user/425330) 什么意思?
您能帮我看看吗?
```cpp
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, d, ans, l[500005], r[500005];
struct node{
int x, y;
}a[50005];
bool cmp(node x, node y){
return x.x < y.x;
}
deque<node> q;
signed main(){
cin >> n >> d;
for(int i = 1; i <= n; i++){
cin >> a[i].x >> a[i].y;
}
sort(a + 1, a + n + 1, cmp);
for(int i = 1; i <= n; i++){
while(!q.empty() && q.back().y <= a[i].y){
q.pop_back();
}
q.push_back(a[i]);
while(!q.empty() && q.front().x < a[i].x - d){
q.pop_front();
}
if(q.front().y >= a[i].y * 2){
l[i] = 1;
}
}
while(!q.empty()){
q.pop_front();
}
for(int i = n; i >= 1; i--){
while(!q.empty() && q.back().y <= a[i].y){
q.pop_back();
}
q.push_back(a[i]);
while(!q.empty() && q.front().x < a[i].x - d){
q.pop_front();
}
if(q.front().y >= a[i].y * 2){
r[i] = 1;
}
}
for(int i = 1; i <= n; i++){
ans += (l[i] & r[i]);
}
cout << ans;
return 0;
}
```
by YangXiaopei @ 2024-01-20 15:35:37
@[YangXiaopei](/user/785630)
```cpp
while(!q.empty() && q.front().x < a[i].x - d)
```
你的这个循环的条件可以加一个绝对值,我是这么写的:
```cpp
while(abs(a[i].x - a[s.front()].x) > d) s.pop_front();
```
by Sincerity_Amiya @ 2024-01-26 10:24:55