跳到正文

题解

题解:P11255 [GDKOI2023 普及组] 淋雨

stripe_python约 5 分钟
原文
文章信息与版本

文章信息

发布
2026年3月5日
收录
2026年8月27日
更新
2026年8月27日
篇幅
约 5 分钟
获赞
1
题目
P11255

版本

  1. v1当前

转化

设第 ii 个雨滴在 tit_i 时间后落地,落地坐标为 pip_i,由物理知识:

  • ti=yivgt_i=\dfrac{y_i}{v_g}。
  • pi=xi+vwtip_i=x_i+v_w t_i。

考虑一个人先接住第 ii 个雨滴,再接住第 jj 个雨滴的充要条件:

  • ti≤tjt_i \le t_j。
  • ∣pi−pj∣≤vc(tj−ti)|p_i - p_j| \le v_c(t_j-t_i)。

对第二个不等式拆开绝对值,则

{pj−pi≤vctj−vctipi−pj≤vctj−vcti  ⟹  {vcti−pi≤vctj−pjvcti+pi≤vctj+pj\left\{\begin{matrix} p_j - p_i \le v_c t_j - v_c t_i \\ p_i - p_j \le v_c t_j - v_c t_i \end{matrix}\right. \implies \left\{\begin{matrix} v_c t_i - p_i \le v_c t_j - p_j \\ v_c t_i + p_i \le v_c t_j + p_j \end{matrix}\right.

令 ui=vcti−pi,vi=vcti+piu_i=v_c t_i-p_i, v_i=v_c t_i + p_i,则上面的不等式变为 {ui≤ujvi≤vj\left\{\begin{matrix} u_i \le u_j \\ v_i \le v_j \end{matrix}\right.,其中

ui=vcvgyi−xi−vwvcvgu_i=\dfrac{v_c}{v_g} y_i-x_i-v_w \dfrac{v_c}{v_g} vi=vcvgyi+xi+vwvcvgv_i=\dfrac{v_c}{v_g} y_i+x_i+v_w \dfrac{v_c}{v_g}

不难发现,不等式两边同乘 vgv_g 是等价变形,于是直接令

ui=(vc−vw)yi−vgxivi=(vc+vw)yi+vgxiu_i=(v_c-v_w)y_i-v_g x_i\\ v_i=(v_c+v_w)y_i+v_g x_i

得到充要条件 {ti≤tjui≤ujvi≤vj\left\{\begin{matrix} t_i \le t_j \\ u_i \le u_j \\ v_i \le v_j \end{matrix}\right.。事实上我们有

{ui≤ujvi≤vj  ⟹  ui+vi≤uj+vj  ⟹  2vcyi≤2vcyj  ⟹  ti≤tj\left\{\begin{matrix} u_i \le u_j \\ v_i \le v_j \end{matrix}\right. \implies u_i + v_i \le u_j + v_j \implies 2v_c y_i \le 2v_c y_j \implies t_i \le t_j

所以不用管 tit_i 这一维,问题被转化成一个二维偏序。

扫描线

现在问题转化为:qq 次询问,每次给定起始点 (u0,v0)(u_0,v_0),在二维平面上寻找若干个点,满足后一个点偏序前一个点,类似于二维限制下的最长不降子序列。

将所有出现的 viv_i 离散化,按 uiu_i 排序后扫描线。在扫描线过程中维护一个支持单点更新、前缀 max 的树状数组。

如果当前遇到的是一个雨滴,我们查询当前能拼接的最大数目,然后加一并插入树状数组。

如果当前遇到的是一个查询,直接查询当前 v0v_0 对应的最大数目。

复杂度 O(nlog⁡n)O(n \log n)。

代码

C++
#define int long long
const int N = 2e5 + 5;

int n, m, vg, vw, vc, ans[N];
struct node {
    int x, y, id, type;
    node(int a = 0, int b = 0, int c = 0, int d = 0) : x(a), y(b), id(c), type(d) {}
} a[N];
vector<int> d;
struct BIT {
    int tr[N];
    void add(int x, int c) {for (; x < N; x += lowbit(x)) tr[x] = max(tr[x], c);}
    int ask(int x) {
        int res = 0;
        for (; x >= 1; x -= lowbit(x)) res = max(res, tr[x]);
        return res;
    }
} T;

void _main() {
    cin >> n >> m >> vg >> vw >> vc;
    for (int i = 1, x, y; i <= n; i++) cin >> x >> y, a[i] = {(vc - vw) * y - vg * x, (vc + vw) * y + vg * x, 0, 0};
    for (int i = 1, x; i <= m; i++) cin >> x, a[i + n] = {-x * vg, x * vg, i, 1};
    for (int i = 1; i <= n + m; i++) d.emplace_back(a[i].y);
    sort(d.begin(), d.end()), d.erase(unique(d.begin(), d.end()), d.end());
    sort(a + 1, a + n + m + 1, [](const node& a, const node& b) -> bool {
        if (a.x != b.x) return a.x > b.x;
        return a.y != b.y ? a.y > b.y : a.type < b.type;
    });
    for (int i = 1; i <= n + m; i++) {
        int idx = d.size() - (lower_bound(d.begin(), d.end(), a[i].y) - d.begin());
        if (a[i].type == 0) T.add(idx, T.ask(idx) + 1);
        else ans[a[i].id] = T.ask(idx);
    }
    for (int i = 1; i <= m; i++) cout << ans[i] << '\n';
} 
原文