跳到正文

题解

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

Inracle约 7 分钟
原文

这是 2026年3月8日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

收录
2026年3月8日
更新
2026年3月8日
篇幅
约 7 分钟
题目
P11255

版本

  1. v2当前
  2. v1

用了一个三维偏序胡上去,题解貌似都是二维?/yun

update on 26.03.06:怎么 tj≥tit_j \ge t_i 这个条件根本不需要啊,哭晕了,大家就看一乐吧。


发现可以只用 (x,t)(x,t) 描述每个雨滴(在哪里、多久降落 yy 轴)。然后考虑离线,先把每个询问视为 (x,0)(x,0) 的、不产生贡献的雨滴就行了。

然后想到 dp,设 dpidp_i 为接到 ii 雨滴后(包括 ii)还能接的最大雨滴数。所以转移时是时光倒流!我们现在从 jj 转移到 ii,意为接了 ii 之后跑到 jj。那么如果有 sv≤t\frac{s}{v}\le t,即 ∣xi−xj∣vc≤tj−ti\frac{|x_i-x_j|}{v_c}\le t_j-t_i,则可以接到,有 dpi←dpj+1dp_i \gets dp_j+1。


分讨上面那个转移条件 ∣xi−xj∣vc≤tj−ti\frac{|x_i-x_j|}{v_c}\le t_j-t_i:

  • 若 xi≥xjx_i \ge x_j,

等价于 xi+tivc≤xj+tjvcx_i + t_i v_c \le x_j+ t_jv_c,列出来是

{tj≥tixj≤xixj+tjvc≥xi+tivc\begin{cases} t_j \ge t_i \\ x_j \le x_i\\ x_j + t_j v_c \ge x_i+ t_iv_c \end{cases}

均满足时可以有 dpi←dpj+1dp_i \gets dp_j+1。

  • 若 xi<xjx_i < x_j,

等价于 tivc−xi≤tjvc−xjt_iv_c - x_i \le t_jv_c - x_j,列出来是

{tj≥tixj≥xitjvc−xj≥tivc−xi\begin{cases} t_j \ge t_i \\ x_j \ge x_i\\ t_jv_c - x_j \ge t_iv_c - x_i \end{cases}

均满足时可以有 dpi←dpj+1dp_i \gets dp_j+1。


用 cdq 做,相当于三维偏序。按 tt 从大到小排序,对于两边再按 xx 排序(从大到小、从小到大分别做一遍),树状数组维护 dp。注意因为是 dp,所以递归顺序是 [l,mi]→[l,r]→[mi+1,r][l,mi]\to[l,r]\to[mi+1,r]。

这样就做完了,时间复杂度 O(nlog⁡2n)O(n \log^2 n)。

C++
#include<bits/stdc++.h>
#define i128 __int128
#define ll long long
#define ull unsigned long long
#define db long double
#define Pii pair<int,int>
#define fi first
#define se second
#define inline
#define f(x,y) fixed<<setprecision(y)<<x
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,rp,stdin),p1==p2)?EOF:*p1++)

using namespace std;
const int N=2e5+10;//询问加修改
const int rp=1e6+10;

int n,q,cnt,c[N<<1],dp[N]; ll vg,vw,vc,b[N<<1];
struct node{ll x,t,id;}p[N];
char buf[rp],*p1=buf,*p2=buf;

inline int read()
{
	int x=0,f=1; char c=0;
	while(!isdigit(c)) {if(c=='-') f=-1; c=gc();}
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=gc();
	return x*f;
}

inline char read_ch()
{
	char c=0;
	while((!isalpha(c))&&(!isdigit(c))) c=gc();
	return c;
}

inline bool cmpt(node q,node w)
{
	if(q.t!=w.t) return q.t>w.t;
	return q.id<w.id;//t 相等时要让 id 大的(询问)排在小的(雨滴)后面,才能转移到
}

inline bool cmpx1(node q,node w) {return q.x<w.x;}
inline bool cmpx2(node q,node w) {return q.x>w.x;}

inline void upd(ll x,int v)
{
	x=cnt-(lower_bound(b+1,b+cnt+1,x)-b)+1;//先离散化再查 BIT
	while(x<=cnt) c[x]=max(c[x],v),x+=x&-x;
}

inline int get(ll x)
{
	x=cnt-(lower_bound(b+1,b+cnt+1,x)-b)+1; int v=0;
	while(x) v=max(v,c[x]),x-=x&-x; return v;
}

inline void del(ll x)
{
	x=cnt-(lower_bound(b+1,b+cnt+1,x)-b)+1;//清空树状数组
	while(x<=cnt) c[x]=0,x+=x&-x;
}

inline void solve(int L,int R)
{
	if(L==R) {dp[p[L].id]=max(dp[p[L].id],1); return;}
	int mi=(L+R)>>1,nw; solve(L,mi);//[l,mi]
	
	sort(p+L,p+mi+1,cmpx1); sort(p+mi+1,p+R+1,cmpx1); nw=L;//x_j \le x_i
	for(int i=mi+1;i<=R;++i)
	{
		while(nw<=mi&&p[nw].x<=p[i].x)
		{
			if(p[nw].id<=n)//确保是真的雨滴
				upd(p[nw].t*vc+p[nw].x,dp[p[nw].id]);
			++nw;
		}
		dp[p[i].id]=max(dp[p[i].id],get(p[i].t*vc+p[i].x)+1);
	}
	--nw; while(nw>=L) del(p[nw].t*vc+p[nw].x),--nw;//清空
	
	sort(p+L,p+mi+1,cmpx2); sort(p+mi+1,p+R+1,cmpx2); nw=L;//x_j \ge x_i
	for(int i=mi+1;i<=R;++i)
	{
		while(nw<=mi&&p[nw].x>=p[i].x)
		{
			if(p[nw].id<=n)//确保是真的雨滴
				upd(p[nw].t*vc-p[nw].x,dp[p[nw].id]);
			++nw;
		}
		dp[p[i].id]=max(dp[p[i].id],get(p[i].t*vc-p[i].x)+1);
	}
	--nw; while(nw>=L) del(p[nw].t*vc-p[nw].x),--nw;//清空
	sort(p+mi+1,p+R+1,cmpt); solve(mi+1,R);//[mi+1,R]
}

signed main()
{
	cin.tie(0)->sync_with_stdio(0);
	cin>>n>>q>>vg>>vw>>vc; int x,y;
	for(int i=1;i<=n;++i) cin>>x>>y,p[i]={x*vg+y*vw,y,i};//这里其实通了分避免小数
	for(int i=1;i<=q;++i) cin>>x,p[i+n]={x*vg,0,i+n};//加入询问
	for(int i=1;i<=n+q;++i)
	{
		b[++cnt]=p[i].t*vc+p[i].x;//可能用到的 BIT 下标
		b[++cnt]=p[i].t*vc-p[i].x;//可能用到的 BIT 下标
	}
	sort(b+1,b+cnt+1); cnt=unique(b+1,b+cnt+1)-b-1;//离散化
	sort(p+1,p+n+q+1,cmpt); solve(1,n+q);
	for(int i=n+1;i<=n+q;++i) cout<<dp[i]-1<<"\n";//输出,要减去自己(假雨滴,实则是询问)
	return 0;
}