题目:传送门
题意:在 x 轴上,有 n 场演出,第 i 场在 xi 处,时间 ti 时表演,然后,有一个人,最快移动速度为 v,问你1、在任意处作为起点,最多能观看几场表演;2、在 x = 0 处开始,最多能观看几场表演。
1 <= n <= 1e5
思路: 参考
#include <bits/stdc++.h> #define LL long long #define ULL unsigned long long #define mem(i, j) memset(i, j, sizeof(i)) #define rep(i, j, k) for(int i = j; i <= k; i++) #define dep(i, j, k) for(int i = k; i >= j; i--) #define pb push_back #define make make_pair #define INF INT_MAX #define inf LLONG_MAX #define PI acos(-1) #define fir first #define sec second using namespace std; const int N = 1e6 + 5; const LL mod = 1e9 + 7; LL ksm(LL a, LL b) { LL ans = 1LL; while(b) { if(b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } LL x[N], t[N]; LL tmp[N]; pair < LL, LL > a[N]; void solve() { int n; scanf("%d", &n); rep(i, 1, n) scanf("%lld %lld", &x[i], &t[i]); LL v; scanf("%lld", &v); rep(i, 1, n) { a[i].fir = x[i] + t[i] * v; a[i].sec = -x[i] + t[i] * v; } sort(a + 1, a + 1 + n); int tot = 0; rep(i, 1, n) { int pos = upper_bound(tmp + 1, tmp + 1 + tot, a[i].sec) - tmp; tmp[pos] = a[i].sec; tot = max(tot, pos); } int ans1 = tot; tot = 0; rep(i, 1, n) { if(a[i].fir < 0 || a[i].sec < 0) continue; int pos = upper_bound(tmp + 1, tmp + 1 + tot, a[i].sec) - tmp; tmp[pos] = a[i].sec; tot = max(tot, pos); } int ans2 = tot; printf("%d %d ", ans2, ans1); } int main() { // int _; scanf("%d", &_); // while(_--) solve(); solve(); return 0; }