Subject: https://www.lydsy.com/JudgeOnline/problem.php?id=2957
Line segment tree. The slope is recorded at each point, with a single incrementing sequence length (starting at 1).
Each point of the line segment tree records the max and single growth of its own interval. When pushing up, mx [ ls ] is used to determine which son to recurse to.
It should be noted that when the length of the right son can all be added, s [ rs ] cannot be added, because it is not necessarily all on the total single-increment sequence (only the part of rs that is greater than mx[ls]);
Therefore, the contribution of the right son should be the s of the original total interval minus the s of the left son, because the single-increment sequence starts from the leftmost end, and the left son must be all in the total sequence.
#include<iostream> #include<cstdio> #include<cstring> #define ll long long using namespace std; const int N=1e5+5; int n,m,x,s[N<<2]; double z,mx[N<<2]; int dg(int cur,double lm,int l,int r) { if(l==r)return mx[cur]>lm; int ls=(cur<<1),rs=(cur<<1|1); if(mx[ls]<=lm)return dg(rs,lm,((l+r)>>1)+1,r); return dg(ls,lm,l,((l+r)>>1))+s[cur]-s[ls]; } void pushup(int bh,int l,int r) { int ls=(bh<<1),rs=(bh<<1|1); mx[bh]=mx[ls];s[bh]=s[ls]; if(mx[rs]<=mx[ls])return; mx[bh]=mx[rs]; // printf(" ()l=%d r=%d mx=%lf\n",l,r,mx[bh]); s[bh]+=dg(rs,mx[ls],((l+r)>>1)+1,r); } void add(int bh,int l,int r) { int mid=((l+r)>>1); if(l==r){ mx[bh]=z;s[bh]=1;//bh,不是l // printf("l=%d r=%d mx=%lf s=%d\n",l,r,mx[bh],s[bh]); return; } if(x<=mid)add(bh<<1,l,mid); else add(bh<<1|1,mid+1,r); pushup (bh, l, r); // printf("l=%d r=%d mx=%lf s=%d\n",l,r,mx[bh],s[bh]); } int main() { scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) { scanf("%d%lf",&x,&z);z/=x; add(1,1,n); printf("%d\n",s[1]); } return 0; }