[USACO14DEC]Cow Jog G【最长反链性质】

题目链接


  求的是跑了T分钟之后的情况,要求是每个跑道都没有被超越现象,问最少的跑道需求数量。

  很明显的就是求一个反链的偏序问题,我们倒过来看,求最长不降序列,于是就可以用树状数组来进行查询了。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#define lowbit(x) ( x&(-x) )
#define pi 3.141592653589793
#define e 2.718281828459045
#define INF 0x3f3f3f3f
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
using namespace std;
typedef unsigned long long ull;
typedef unsigned int uit;
typedef long long ll;
const int maxN = 1e5 + 7;
int N;
ll T, Lsan[maxN];
int trie[maxN] = {0};
void update(int x, int val) { while(x <= N) { trie[x] = max(trie[x], val); x += lowbit(x); } }
int query(int x) { int ans = 0; while(x) { ans = max(trie[x], ans); x -= lowbit(x); } return ans; }
struct node
{
    ll a[2];
    node(int _a=0, int _b=0):a{_a, _b} {}
} t[maxN];
int main()
{
    scanf("%d%lld", &N, &T);
    ll vi;
    for(int i=1; i<=N; i++)
    {
        scanf("%lld%lld", &t[i].a[0], &vi);
        t[i].a[1] = t[i].a[0] + vi * T;
        Lsan[i] = t[i].a[1];
    }
    sort(Lsan + 1, Lsan + N + 1);
    int _UP = (int)(unique(Lsan + 1, Lsan + N + 1) - Lsan - 1);
    for(int i=1; i<=N; i++) t[i].a[1] = lower_bound(Lsan + 1, Lsan + _UP + 1, t[i].a[1]) - Lsan;
    int ans = 1;
    for(int i=N, tmp; i>=1; i--)
    {
        tmp = 1 + query((int)t[i].a[1]);
        ans = max(ans, tmp);
        update(t[i].a[1], tmp);
    }
    printf("%d\n", ans);
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wuliwuliii

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值