# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
48382 | 2018-05-12T11:44:22 Z | BThero | Boat (APIO16_boat) | C++17 | 11 ms | 688 KB |
// Why am I so stupid? :c #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define fi first #define se second typedef long long ll; using namespace std; const int mod = 1e9+7; pair <int, int> l[505]; pair <int, int> r[505]; int fenw[1000005]; int dp[1000005]; int d[1000005]; int rl[1005]; int n, m; void addMod(int &a, int b) { a += b; if (mod <= a) { a -= mod; } } void compress() { vector <int> vv; for (int i = 1; i <= n; ++i) { for (int j = -1; j <= 1; ++j) { vv.pb(l[i].fi + j); vv.pb(r[i].fi + j); } } sort(all(vv)); vv.resize(unique(all(vv)) - vv.begin()); d[m] = 1; m = vv.size(); for (int i = 1; i < m; ++i) { d[i] = vv[i] - vv[i - 1]; } for (int i = 1; i <= n; ++i) { l[i].se = upper_bound(all(vv), l[i].fi) - vv.begin(); r[i].se = upper_bound(all(vv), r[i].fi) - vv.begin(); } } int f(int x) { return x & -x; } int prefSum(int x) { int ret = 0; for (int i = x; i > 0; i -= f(i)) { addMod(ret, fenw[i]); } return ret; } void fenwUpd(int x, int v) { for (int i = x; i <= m; i += f(i)) { addMod(fenw[i], v); } } void solve() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d %d", &l[i].fi, &r[i].fi); } compress(); for (int i = 1; i <= n; ++i) { for (int j = l[i].se; j <= r[i].se; ++j) { dp[j] = 1; } for (int j = l[i].se; j <= r[i].se; ++j) { addMod(dp[j], prefSum(j - 1)); } for (int j = l[i].se; j <= r[i].se; ++j) { fenwUpd(j, dp[j] * 1ll * d[j] % mod); } } printf("%d\n", prefSum(m)); } int main() { #ifdef BThero freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // BThero int tt = 1; while (tt--) { solve(); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 484 KB | Output is correct |
3 | Correct | 3 ms | 484 KB | Output is correct |
4 | Correct | 2 ms | 608 KB | Output is correct |
5 | Correct | 2 ms | 608 KB | Output is correct |
6 | Correct | 2 ms | 608 KB | Output is correct |
7 | Correct | 2 ms | 608 KB | Output is correct |
8 | Correct | 2 ms | 608 KB | Output is correct |
9 | Correct | 2 ms | 608 KB | Output is correct |
10 | Correct | 2 ms | 608 KB | Output is correct |
11 | Correct | 2 ms | 612 KB | Output is correct |
12 | Correct | 3 ms | 612 KB | Output is correct |
13 | Correct | 2 ms | 612 KB | Output is correct |
14 | Correct | 2 ms | 612 KB | Output is correct |
15 | Correct | 2 ms | 664 KB | Output is correct |
16 | Correct | 2 ms | 664 KB | Output is correct |
17 | Correct | 2 ms | 664 KB | Output is correct |
18 | Correct | 2 ms | 664 KB | Output is correct |
19 | Correct | 2 ms | 664 KB | Output is correct |
20 | Correct | 2 ms | 688 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 484 KB | Output is correct |
3 | Correct | 3 ms | 484 KB | Output is correct |
4 | Correct | 2 ms | 608 KB | Output is correct |
5 | Correct | 2 ms | 608 KB | Output is correct |
6 | Correct | 2 ms | 608 KB | Output is correct |
7 | Correct | 2 ms | 608 KB | Output is correct |
8 | Correct | 2 ms | 608 KB | Output is correct |
9 | Correct | 2 ms | 608 KB | Output is correct |
10 | Correct | 2 ms | 608 KB | Output is correct |
11 | Correct | 2 ms | 612 KB | Output is correct |
12 | Correct | 3 ms | 612 KB | Output is correct |
13 | Correct | 2 ms | 612 KB | Output is correct |
14 | Correct | 2 ms | 612 KB | Output is correct |
15 | Correct | 2 ms | 664 KB | Output is correct |
16 | Correct | 2 ms | 664 KB | Output is correct |
17 | Correct | 2 ms | 664 KB | Output is correct |
18 | Correct | 2 ms | 664 KB | Output is correct |
19 | Correct | 2 ms | 664 KB | Output is correct |
20 | Correct | 2 ms | 688 KB | Output is correct |
21 | Incorrect | 11 ms | 688 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 484 KB | Output is correct |
3 | Correct | 3 ms | 484 KB | Output is correct |
4 | Correct | 2 ms | 608 KB | Output is correct |
5 | Correct | 2 ms | 608 KB | Output is correct |
6 | Correct | 2 ms | 608 KB | Output is correct |
7 | Correct | 2 ms | 608 KB | Output is correct |
8 | Correct | 2 ms | 608 KB | Output is correct |
9 | Correct | 2 ms | 608 KB | Output is correct |
10 | Correct | 2 ms | 608 KB | Output is correct |
11 | Correct | 2 ms | 612 KB | Output is correct |
12 | Correct | 3 ms | 612 KB | Output is correct |
13 | Correct | 2 ms | 612 KB | Output is correct |
14 | Correct | 2 ms | 612 KB | Output is correct |
15 | Correct | 2 ms | 664 KB | Output is correct |
16 | Correct | 2 ms | 664 KB | Output is correct |
17 | Correct | 2 ms | 664 KB | Output is correct |
18 | Correct | 2 ms | 664 KB | Output is correct |
19 | Correct | 2 ms | 664 KB | Output is correct |
20 | Correct | 2 ms | 688 KB | Output is correct |
21 | Incorrect | 11 ms | 688 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |