| 记录编号 |
618248 |
评测结果 |
AAAAAAAAAA |
| 题目名称 |
果蝇炸弹 |
最终得分 |
100 |
| 用户昵称 |
终焉折枝 |
是否通过 |
通过 |
| 代码语言 |
C++ |
运行时间 |
0.249 s |
| 提交时间 |
2026-08-27 22:30:58 |
内存使用 |
8.59 MiB |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include<algo/debug.h>
#else
#define debug(...) 42
#endif
using ll = long long;
using f64 = double;
using f128 = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
#define pb push_back
#define mk make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)((x).size())
#define ciallo(x) cerr << (x) << '\n';
template <typename T, typename U>
inline bool chmin(T& a, const U& b){return (b < a ? a = b, true : false);}
template <typename T, typename U>
inline bool chmax(T& a, const U& b){return (a < b ? a = b, true : false);}
namespace IO {
const int BUF = 1 << 21;
char ibuf[BUF], *p1 = ibuf, *p2 = ibuf;
char obuf[BUF], *p3 = obuf;
inline char gc(){
return p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++;
}
inline void pc(char c){
if(p3 - obuf == BUF){
fwrite(obuf, 1, BUF, stdout);
p3 = obuf;
}
*p3 ++ = c;
}
inline void flush(){
if(p3 != obuf){
fwrite(obuf, 1, p3 - obuf, stdout);
p3 = obuf;
}
}
template<typename T>
inline bool read(T &x){
x = 0;
int f = 1;
char c = gc();
while(c < '0' || c > '9'){
if(c == '-') f = -1;
if(c == EOF) return false;
c = gc();
}
while(c >= '0' && c <= '9'){
x = (x << 3) + (x << 1) + (c ^ 48);
c = gc();
}
x *= f;
return true;
}
template<typename T>
inline void write(T x){
if(x < 0){
pc('-');
x = -x;
}
static int s[35], top = 0;
do{
s[++ top] = x % 10;
x /= 10;
}while(x);
while(top) pc(s[top --] + '0');
}
struct Flusher{
~Flusher(){ flush(); }
} flusher;
}
using IO::read;
using IO::write;
using IO::pc;
const int P = 1e9 + 7;
const int N = 3 * 1e5 + 5;
int n;
ll a[N], r[N];
int R[N], ans[N];
int stk[N], tp = 0;
ll sv[N];
int tr[N];
inline int lowbit(int x){
return x & (-x);
}
inline void add(int x, int k){
while(x){
tr[x] += k;
tr[x] -= (tr[x] >= P ? P : 0);
x -= lowbit(x);
}
}
inline int qry(int x){
int res = 0;
while(x <= n + 1){
res += tr[x];
res -= (res >= P ? P : 0);
x += lowbit(x);
}
return res;
}
int head[N], nxt[N], to[N], tot = 0;
inline void add_q(int u, int v){
nxt[++ tot] = head[u];
to[tot] = v;
head[u] = tot;
}
void solve(){
a[0] = -3000000000000000000LL, a[n + 1] = 3000000000000000000LL;
r[n + 1] = a[n + 1];
for(int i = 1;i <= n;i ++){
read(a[i]);
read(r[i]);
ll v = a[i] + r[i];
r[i] = a[i] - r[i];
while(tp > 0 && sv[tp] < a[i]) tp --;
int l = (tp == 0 ? 0 : stk[tp]);
if(l - 1 >= 0){
add_q(l - 1, i);
}
while(tp > 0 && sv[tp] <= v) tp --;
tp ++;
stk[tp] = i;
sv[tp] = v;
}
tp = 0;
for(int i = n;i >= 1;i --){
ll v = r[i];
while(tp > 0 && sv[tp] > a[i]) tp --;
if(tp == 0) R[i] = n + 1;
else R[i] = stk[tp];
while(tp > 0 && sv[tp] >= v) tp --;
tp ++;
stk[tp] = i;
sv[tp] = v;
}
R[0] = n + 1;
ans[0] = 1;
for(int i = 0;i <= n;i ++){
if(ans[i]) add(R[i], ans[i]);
int sum = qry(i + 1);
ans[i + 1] += sum;
ans[i + 1] -= (ans[i + 1] >= P ? P : 0);
for(int e = head[i]; e; e = nxt[e]){
int v = to[e];
int s = qry(v);
ans[v] -= s;
ans[v] += (ans[v] < 0 ? P : 0);
}
}
write(ans[n + 1]);
pc('\n');
}
int main(){
#ifdef LOCAL
//freopen("test.txt", "r", stdin);
#endif
int c; read(c);
read(n);
solve();
#ifdef LOCAL
cout << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n ";
#endif
return 0;
}