This question is more detail, we first define the state, f [i] represents the processing time to a minimum the number i, in fact, the left edge of the last tube, then these i can not be the place where the cows, because we medals For the left edge
After we discovered monotonicity, in fact, take min + 1, but in the range to be between 2a-2b, so into the queue to be careful when
This time I made the mistake because I regard it as the previous topic and found no restriction here is that the place must be even have to put, because the scope of each tube is even.
#include<iostream> #include<queue> #include<map> #include<vector> #include<cstdio> #include<algorithm> #include<stack> #include<cstring> using namespace std; typedef long long ll; const int N=1e6+7; const int inf=0x3f3f3f3f; int st[N]; struct node{ int l,r; }s[N]; int f[N]; int q[N]; int main(){ int i; int n,m; int l,a,b; cin>>n>>l>>a>>b; for(i=1;i<=n;i++){ cin>>s[i].l>>s[i].r; for(int j=s[i].l+1;j<s[i].r;j++) st[j]=1; } memset(f,0x3f,sizeof f); f[0]=0; int j; int hh=0; int tt=0; q[0]=0; for(int i=2*a;i<=l;i+=2){ while(hh<=tt&&q[hh]<i-2*b) hh++; while(hh<=tt&&f[q[tt]]>=f[i-2*a]) tt--; q[++tt]=i-2*a; if(st[i]) continue; f[i]=f[q[hh]]+1; } if(f[l]<inf/2) cout<<f[l]<<endl; else cout<<-1<<endl; }