// vim: foldmethod=marker
// Sun Jan 12 15:14:50 MSK 2020: START coding
// Sun Jan 12 15:22:10 MSK 2020: DONE coding
// Sun Jan 12 15:26:04 MSK 2020: OK sample
#include <bits/stdc++.h>
using namespace std;
#define llong long long
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )
#define rand __rand
mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); // or mt19937_64
template<class T = int> T rand(T range = numeric_limits<T>::max()) { return (T)(rng() % range); }
/*{{{*/
#define CONCAT_(x, y) x##y
#define CONCAT(x, y) CONCAT_(x, y)
#ifdef LOCAL_DEBUG
int debug = 1;
#define DB(...) stringstream CONCAT(ss, __LINE__); CONCAT(ss, __LINE__) << __VA_ARGS__; debug_block CONCAT(dbbl, __LINE__)(CONCAT(ss, __LINE__).str())
#else
int debug = 0;
#define DB(...)
#endif
int __db_level = 0;
#define clog if (debug) cerr << string(__db_level * 2, ' ')
struct debug_block {
string name;
debug_block(const string& name_): name(name_) { clog << "{ " << name << endl; ++__db_level; }
~debug_block() { --__db_level; clog << "} " << name << endl; }
};
#define deb(...) "[" << #__VA_ARGS__ << "] = [" << __VA_ARGS__ << "]"
#define debln(...) clog << "[" << #__VA_ARGS__ << "] = [" << __VA_ARGS__ << "]" << endl
#define _ << ", " <<
template<class U, class V>
ostream& operator<<(ostream& out, const pair<U, V>& p) { return out << "(" << p.first _ p.second << ")"; }
template<class A, class B>
ostream& operator<<(ostream& out, const tuple<A, B>& t) { return out << "(" << get<0>(t) _ get<1>(t) << ")"; }
template<class A, class B, class C>
ostream& operator<<(ostream& out, const tuple<A, B, C>& t) { return out << "(" << get<0>(t) _ get<1>(t) _ get<2>(t) << ")"; }
template<class T> ostream& operator<<(ostream& out, const vector<T>& container) {
out << "{";
if (len(container)) out << container[0];
rep1(i, len(container) - 1) out _ container[i];
return out << "}";
}
template<class x> vector<typename x::value_type> $v(const x& a) { return vector<typename x::value_type>(a.begin(), a.end()); }
#define ptrtype(x) typename iterator_traits<x>::value_type
template<class u> vector<ptrtype(u)> $v(u a, u b) { return vector<ptrtype(u)>(a, b); }
/*}}}*/
// ACTUAL SOLUTION BELOW ////////////////////////////////////////////////////////////
const llong rem = (llong)(1e9 + 7);
#define maxn 555
int n;
llong a[maxn], b[maxn];
vector<pair<llong, llong>> dp;
int main(void) {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
rep(i, n) {
cin >> a[i] >> b[i];
dp.emplace_back(a[i], 0);
dp.emplace_back(b[i], 0);
dp.emplace_back(b[i] + 1, 0);
}
dp.emplace_back(0, 1);
dp.emplace_back(1, 0);
sort(dp.begin(), dp.end());
dp.resize(unique(dp.begin(), dp.end()) - dp.begin());
debln(dp);
rep(i, n) {
DB(deb(i));
debln(a[i] _ b[i]);
llong cur_s = 0;
rep(f, len(dp) - 1) {
DB(deb(f));
llong length = dp[f + 1].first - dp[f].first;
llong new_s = (cur_s + dp[f].second * length) % rem;
debln(length);
debln(cur_s);
debln(new_s);
debln(dp[f]);
if (dp[f].first >= a[i] and dp[f].first <= b[i]) {
(dp[f].second += cur_s) %= rem;
}
cur_s = new_s;
}
debln(dp);
}
llong ans = 0;
rep1(i, len(dp) - 1) (ans += dp[i].second) %= rem;
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
432 KB |
Output is correct |
5 |
Correct |
4 ms |
392 KB |
Output is correct |
6 |
Correct |
5 ms |
464 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
432 KB |
Output is correct |
9 |
Correct |
5 ms |
476 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
356 KB |
Output is correct |
12 |
Correct |
5 ms |
432 KB |
Output is correct |
13 |
Correct |
5 ms |
388 KB |
Output is correct |
14 |
Correct |
6 ms |
476 KB |
Output is correct |
15 |
Correct |
3 ms |
476 KB |
Output is correct |
16 |
Correct |
3 ms |
396 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
1 ms |
376 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
432 KB |
Output is correct |
5 |
Correct |
4 ms |
392 KB |
Output is correct |
6 |
Correct |
5 ms |
464 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
432 KB |
Output is correct |
9 |
Correct |
5 ms |
476 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
356 KB |
Output is correct |
12 |
Correct |
5 ms |
432 KB |
Output is correct |
13 |
Correct |
5 ms |
388 KB |
Output is correct |
14 |
Correct |
6 ms |
476 KB |
Output is correct |
15 |
Correct |
3 ms |
476 KB |
Output is correct |
16 |
Correct |
3 ms |
396 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
1 ms |
376 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Incorrect |
6 ms |
392 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
432 KB |
Output is correct |
5 |
Correct |
4 ms |
392 KB |
Output is correct |
6 |
Correct |
5 ms |
464 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
432 KB |
Output is correct |
9 |
Correct |
5 ms |
476 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
356 KB |
Output is correct |
12 |
Correct |
5 ms |
432 KB |
Output is correct |
13 |
Correct |
5 ms |
388 KB |
Output is correct |
14 |
Correct |
6 ms |
476 KB |
Output is correct |
15 |
Correct |
3 ms |
476 KB |
Output is correct |
16 |
Correct |
3 ms |
396 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
1 ms |
376 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Incorrect |
6 ms |
392 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |