| 比赛 |
果蝇王邀请赛div1 |
评测结果 |
AAAAAAAAAA |
| 题目名称 |
果蝇炸弹 |
最终得分 |
100 |
| 用户昵称 |
yyswys |
运行时间 |
0.824 s |
| 代码语言 |
C++ |
内存使用 |
17.56 MiB |
| 提交时间 |
2026-08-27 12:04:30 |
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7,inf=1000000000000000010;
int n,a[300010],b[300010],c;
int dp[300010],tr[300010];
int pre[300010];
int top,st[300010];
vector<int> g[300010];
void add(int x,int k){
while(x<=n+1) (tr[x]+=k)%=mod,x+=x&-x;
}
int query(int x){
int s=0;
while(x) (s+=tr[x])%=mod,x-=x&-x;
return s;
}
signed main(){
freopen("bombmine.in","r",stdin);
freopen("bombmine.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>c>>n;
n++;
for(int i=2;i<=n;i++) cin>>a[i]>>b[i];
a[1]=-inf,b[1]=4*inf,a[n+1]=2*inf,b[n+1]=4*inf;
st[++top]=1;
for(int i=2;i<=n+1;i++){
while(top&&a[st[top]]+b[st[top]]<a[i]) top--;
pre[i]=st[top];
while(top&&a[st[top]]+b[st[top]]<a[i]+b[i]) top--;
st[++top]=i;
}
top=0;
st[++top]=n+1;
for(int i=n;i>=1;i--){
while(top&&a[st[top]]-b[st[top]]>a[i]) top--;
g[st[top]].push_back(i);
while(top&&a[st[top]]-b[st[top]]>a[i]-b[i]) top--;
st[++top]=i;
}
add(1,dp[1]=1);
for(int i=2;i<=n+1;i++){
dp[i]=((query(i-1)-query(pre[i]-1))%mod+mod)%mod;
add(i,dp[i]);
for(auto t:g[i]) add(t,mod-dp[t]);
}
cout<<dp[n+1]<<'\n';
return 0;
}