Submission #733009

#TimeUsernameProblemLanguageResultExecution timeMemory
733009SanguineChameleonBoat (APIO16_boat)C++17
36 / 100
2059 ms340 KiB
#include <bits/stdc++.h> using namespace std; void just_do_it(); int main() { #ifdef KAMIRULEZ freopen("kamirulez.inp", "r", stdin); freopen("kamirulez.out", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); just_do_it(); return 0; } const int maxn = 5e2 + 20; const long long mod = 1e9 + 7; bool flag[maxn]; long long inv[maxn]; long long fact_inv[maxn]; long long cur[maxn]; long long nxt[maxn]; pair<int, int> events[maxn * 2]; int n; void trans() { for (int i = 1; i <= n; i++) { if (flag[i]) { nxt[i] = cur[i] + 1; if (nxt[i] >= mod) { nxt[i] -= mod; } } else { nxt[i] = cur[i]; } } for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (flag[j]) { nxt[j] += cur[i]; if (nxt[j] >= mod) { nxt[j] -= mod; } } } } swap(cur, nxt); } long long choose(int x, int y) { if (x < y) { return 0; } long long res = fact_inv[y]; for (int i = 0; i < y; i++) { res = res * (x - i) % mod; } return res; } void shift(int len) { for (int i = 1; i <= n; i++) { if (flag[i]) { nxt[i] = (cur[i] + len) % mod; } else { nxt[i] = cur[i]; } } for (int i = 1; i <= n; i++) { int cnt = 0; for (int j = i + 1; j <= n; j++) { if (flag[j]) { cnt++; if (flag[i]) { nxt[j] = (nxt[j] + cur[i] * choose(len + cnt - 1, cnt) + choose(len + cnt - 1, cnt + 1)) % mod; } else { nxt[j] = (nxt[j] + cur[i] * choose(len + cnt - 1, cnt)) % mod; } } } } swap(cur, nxt); } void just_do_it() { inv[1] = 1; fact_inv[0] = 1; fact_inv[1] = 1; for (int i = 2; i < maxn; i++) { inv[i] = (mod - mod / i) * inv[mod % i] % mod; fact_inv[i] = fact_inv[i - 1] * inv[i] % mod; } cin >> n; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; events[i * 2 - 1] = make_pair(a, i); events[i * 2] = make_pair(b + 1, -i); } sort(events + 1, events + n * 2 + 1); int cur_t = 0; for (int i = 1; i <= n * 2; i++) { int nxt_t = events[i].first; int id = events[i].second; bool begin_t = (i == 1 || events[i].first != events[i - 1].first); bool end_t = (i == n * 2 || events[i].first != events[i + 1].first); if (begin_t) { if (cur_t < nxt_t - 1) { shift(nxt_t - 1 - cur_t); cur_t = nxt_t - 1; } } if (id > 0) { flag[id] = true; } else { flag[-id] = false; } if (end_t && cur_t == nxt_t - 1) { trans(); cur_t = nxt_t; } } long long res = 0; for (int i = 1; i <= n; i++) { res += cur[i]; res %= mod; } cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...