#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <bitset>
#include <math.h>
#include <fstream>
#include <iomanip>
#include <functional>
#include <numeric>
#include <chrono>
#include <random>
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using pb = pair<bool, bool>;
using vpb = vector<pb>;
using vvpb = vector<vpb>;
using vi = vector<int>;
using vvi = vector<vi>;
using pi = pair<int, int>;
using vpi = vector<pi>;
const ll inf = (ll)5e9;
const ll mod = (ll)(1e9 + 7);
#define FAST ios_base::sync_with_stdio(0)
#define FASTIN cin.tie(0)
#define FASTOUT cout.tie(0)
#define upmin(a, b) (a) = min((a), (b))
#define upmax(a, b) (a) = max((a), (b))
#define pr(x) cout << x << endl
#define prv(v) for(auto it : v) cout << it << " "; cout << endl;
#define prvv(v) for(auto it : v) { for(auto it2 : it) cout << it2 << " "; cout << endl; } cout << endl;
#define spr(x) cout << x << " "
//#define DBG_FLAG (1) // toggle to switch between bebug mode and solution mode
#ifdef DBG_FLAG
#define wpr(x) cout << #x << " = " << (x) << endl;
#define wprv(v) cout << #v << ": " << endl; for(auto it : v) cout << it << " "; cout << endl;
#define wprvv(v) cout << #v << ": " << endl; for(auto it : v) { for(auto it2 : it) cout << it2 << " "; cout << endl; } cout << endl;
#define wspr(x) cout << #x << ": " << x << " "
#endif
#ifndef DBG_FLAG
#define wpr(x)
#define wprv(v)
#define wprvv(v)
#define wspr(x)
#endif
#define rep(i, s, e) for(ll i = s; i < e; i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
const ll maxV = 1e6;
/*
Solution:
We've seen a slow solution so far:
We start with: [1, 0, 0, 0, ...]
And then each time we increase the current segment with all the values smaller than it.
If we make point compression, we'll get disinct segments. Shouldn't be too complicated.
*/
ll n;
vll a, b;
//vll dp;
//map<ll, ll> dp;
vll v;
void solve()
{
cin >> n;
a.resize(n), b.resize(n), v.resize(3 * n);
rep(i, 0, n) {
cin >> a[i] >> b[i];
v[3 * i] = a[i], v[3 * i + 1] = b[i], v[3*i + 2] = b[i] + 1;
}
v.push_back(0);
v.push_back(inf);
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
wprv(v);
rep(i, 0, n) {
a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
b[i] = lower_bound(v.begin(), v.end(), b[i]) - v.begin();
}
vll dp(v.size(), 0);
dp[0] = 1;
rep(i, 0, n) {
ll sum = 0;
rep(j, 0, a[i]) {
sum += (dp[j] * (v[j+1] - v[j])) % mod;
sum %= mod;
}
wpr(sum);
rep(j, a[i], b[i] + 1) {
wpr(j);
ll add = dp[j] * (v[j+1] - v[j]);
dp[j] = (dp[j] + sum) % mod;
sum += add;
sum %= mod;
}
wprv(dp);
}
ll ans = 0;
rep(i, 0, dp.size()-(ll)1) {
ans = (ans + dp[i] * (v[i+1] - v[i])) % mod;
}
/*
for (const auto& it : dp) {
ans = (ans + it.second) % mod;
}
*/
ans = (ans - 1 + mod) % mod;
pr(ans);
}
int main()
{
FAST;
FASTIN; FASTOUT;
solve();
}
/*
2
1 2
2 3
*/
Compilation message
boat.cpp: In function 'void solve()':
boat.cpp:76:38: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'long long unsigned int' [-Wsign-compare]
76 | #define rep(i, s, e) for(ll i = s; i < e; i++)
......
139 | rep(i, 0, dp.size()-(ll)1) {
| ~~~~~~~~~~~~~~~~~~~~~
boat.cpp:139:2: note: in expansion of macro 'rep'
139 | rep(i, 0, dp.size()-(ll)1) {
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |