reverse为什么挂第六个点,求助
查看原帖
reverse为什么挂第六个点,求助
20562
ivy_uu楼主2023/2/8 21:50

请问:reverse为什么挂第六个点? 倒着写就是AC

#include<bits/stdc++.h>
#define ll long long
#define N 50005
using namespace std;
int n, d, b[N], q[N], c[N];
struct Node{
    int x, h;
}a[N];
bool cmp(Node a, Node b){
    return a.x < b.x;
}
int main(){
    scanf("%d%d",&n,&d);
    for(int i = 1; i <= n; i++){
        scanf("%d%d",&a[i].x, &a[i].h);
    }
    sort(a+1, a+n+1, cmp);
    int h = 1, t = 0;
    for(int i = 1; i <= n; i++){
        while(h <= t && a[i].h >= a[q[t]].h) t--;
        q[++t] = i;
        while(h <= t && a[i].x - a[q[h]].x > d) h++;
        if(a[q[h]].h >= a[i].h*2) b[i] = 1;
    }
    memset(q, 0, sizeof q);
    reverse(a+1, a+n+1);
    h = 1, t = 0;
    for(int i = 1; i <= n; i++){
        while(h <= t && a[i].h >= a[q[t]].h) t--;
        q[++t] = i;
        while(h <= t && a[i].x - a[q[h]].x > d) h++;
        if(a[q[h]].h >= a[i].h * 2) c[i] = 1;//n - i + 1
    }
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        if(c[n - i + 1] && b[i]) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}
2023/2/8 21:50
加载中...