P4269 [USACO18FEB]Snow Boots G


思维题。
以地板为序构造链表,再排序,然后删除走不过去的地面。
删除的时候顺便维护最大的跨度,以此判断可行性。
总的来说利用了答案的单调性。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 1e5 + 20;
inline int read()
{
    int x = 0; char ch = getchar(); bool f = false;
    while(!isdigit(ch)) f |= (ch == '-'), ch = getchar();
    while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    return f ? -x : x;
}

int N, B;
struct Node
{
    int val;
    Node *pre, *nxt;
}node[MAXN];

struct boot
{
    int dep, dis, idx, ans;
    inline bool operator >(const boot &rhs) const {
        return dep > rhs.dep;
    }
    inline bool operator <(const boot &rhs) const {
        return idx < rhs.idx;
    }
}b[MAXN];
struct Floor
{
    int dep, idx;
    Node *pos;
    inline bool operator >(const Floor &rhs) const {
        return dep > rhs.dep;
    }
    inline bool operator <(const Floor &rhs) const {
        return idx < rhs.idx;
    }
}f[MAXN];


void build(){
    f[1].pos = &node[1]; node[1].val = 1;
    for(int i = 2; i <= N; i++){
        node[i].pre = &node[i - 1], node[i - 1].nxt = &node[i];
        node[i].val = 1, f[i].pos = &node[i];
    }
}

int main()
{
    cin>>N>>B;
    for(int i = 1; i <= N; i++) f[i] = (Floor){read(), i};
    for(int i = 1; i <= B; i++) 
        b[i].dep = read(), b[i].dis = read(), b[i].idx = i;
    
    build();
    sort(f + 1, f + N + 1, greater<Floor>());
    sort(b + 1, b + B + 1, greater<boot>());

    int p = 1, maxs = 1;
    for(int i = 1; i <= B; i++){
        while(p <= N && f[p].dep > b[i].dep) {
            Node *cur = f[p].pos;
            cur->pre->nxt = cur->nxt;
            cur->nxt->pre = cur->pre;
            maxs = max(maxs, cur->pre->val += cur->val);
            ++p;
        }
        if(maxs > b[i].dis) b[i].ans = 0;
        else b[i].ans = 1;
    }
    sort(b + 1, b + B + 1);
    for(int i = 1; i <= B; i++) printf("%d\n", b[i].ans);
    return 0;
}

转载于:https://www.cnblogs.com/wsmrxc/p/9439965.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值