이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// 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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |