#include <bits/stdc++.h>
using namespace std;
#define int long long
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 1e18, N = 1e6 + 4, MOD = 1e9 + 7;
int seg[N * 4];
void Update(int l, int r, int pos, int qpos, int qval)
{
if(l == r)
{
seg[pos] = qval;
seg[pos] %= MOD;
return;
}
int mid = (l + r) >> 1;
if(qpos <= mid)
{
Update(l, mid, pos * 2, qpos, qval);
}
else
{
Update(mid + 1, r, pos * 2 + 1, qpos, qval);
}
seg[pos] = seg[pos * 2] + seg[pos * 2 + 1];
seg[pos] %= MOD;
}
int Query(int l, int r, int pos, int ql, int qr)
{
if(ql <= l && r <= qr)
{
return seg[pos];
}
if(ql > r || l > qr)
{
return 0;
}
int mid = (l + r) >> 1;
int ans = Query(l, mid, pos * 2, ql, qr) + Query(mid + 1, r, pos * 2 + 1, ql, qr);
ans %= MOD;
return ans;
}
void Solve()
{
int n;
cin >> n;
vector<pair<int, int> > a(n);
for(int i = 0; i < n; i++)
{
cin >> a[i].first >> a[i].second;
}
Update(0, N, 1, 0, 1);
for(int i = 0; i < n; i++)
{
for(int j = a[i].second; j >= a[i].first; j--)
{
int val = Query(0, N, 1, 0, j - 1);
val %= MOD;
Update(0, N, 1, j, val);
}
}
cout << Query(0, N, 1, 0, N) << "\n";
}
int32_t main()
{
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++)
{
//cout << "Case #" << i << ": ";
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
//cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2016 ms |
340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |