Submission #679229

# Submission time Handle Problem Language Result Execution time Memory
679229 2023-01-07T19:42:20 Z bebra Boat (APIO16_boat) C++17
31 / 100
489 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;

#define dbg(x) cerr << #x << ": " << x << endl;


const int MOD = 1e9 + 7;

int add(int a, int b) {
    int res = a + b;
    if (res >= MOD) {
        res -= MOD;
    }
    return res;
}

int mul(long long a, int b) {
    return a * b % MOD;
}

const int MAX_N = 500 + 1;
int a[MAX_N];
int b[MAX_N];
vector<int> dp[MAX_N];


struct FenwickTree {
    vector<int> tree;
    int size;

    FenwickTree(int n) {
        size = n;
        tree.resize(size);
    }

    void update(int pos, int value) {
        for (int i = pos; i < size; i |= i + 1) {
            tree[i] = add(tree[i], value); 
        }
    }

    int query(int pos) {
        int res = 0;
        for (int i = pos; i >= 0; i = (i & (i + 1)) - 1) {
            res = add(res, tree[i]);
        }
        return res;
    }
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> as = {0};
    for (int i = 1; i <= n; ++i) {
        cin >> a[i] >> b[i];
        for (int j = a[i]; j <= b[i]; ++j) {
            as.push_back(j);
        }
    }
    sort(as.begin(), as.end());
    as.resize(unique(as.begin(), as.end()) - as.begin());
    dp[0].assign(1, 1);
    a[0] = -1;
    b[0] = -1;
    FenwickTree pref(as.size());
    pref.update(0, 1);
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        dp[i].resize(b[i] - a[i] + 1);
        int m = dp[i].size();
        int pos = lower_bound(as.begin(), as.end(), a[i]) - as.begin();
        int pos0 = pos;
        for (int j = 0; j < m; ++j) {
            int x = a[i] + j;
            while (as[pos] < x) ++pos;
            dp[i][j] = pref.query(pos - 1);
        }
        for (int j = 0; j < m; ++j) {
            int x = a[i] + j;
            while (as[pos0] < x) ++pos0;
            pref.update(pos0, dp[i][j]);
            ans = add(ans, dp[i][j]);
        }
    }
    cout << ans << '\n';
    return 0;
}

/*
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 58 ms 7092 KB Output is correct
22 Correct 56 ms 7100 KB Output is correct
23 Correct 51 ms 6756 KB Output is correct
24 Correct 56 ms 7328 KB Output is correct
25 Correct 60 ms 7508 KB Output is correct
26 Correct 57 ms 7736 KB Output is correct
27 Correct 58 ms 7884 KB Output is correct
28 Correct 59 ms 7856 KB Output is correct
29 Correct 59 ms 8040 KB Output is correct
30 Correct 73 ms 11908 KB Output is correct
31 Correct 96 ms 11708 KB Output is correct
32 Correct 72 ms 11968 KB Output is correct
33 Correct 71 ms 11564 KB Output is correct
34 Correct 75 ms 11756 KB Output is correct
35 Correct 83 ms 11160 KB Output is correct
36 Correct 82 ms 11532 KB Output is correct
37 Correct 84 ms 11708 KB Output is correct
38 Correct 81 ms 11320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 489 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 58 ms 7092 KB Output is correct
22 Correct 56 ms 7100 KB Output is correct
23 Correct 51 ms 6756 KB Output is correct
24 Correct 56 ms 7328 KB Output is correct
25 Correct 60 ms 7508 KB Output is correct
26 Correct 57 ms 7736 KB Output is correct
27 Correct 58 ms 7884 KB Output is correct
28 Correct 59 ms 7856 KB Output is correct
29 Correct 59 ms 8040 KB Output is correct
30 Correct 73 ms 11908 KB Output is correct
31 Correct 96 ms 11708 KB Output is correct
32 Correct 72 ms 11968 KB Output is correct
33 Correct 71 ms 11564 KB Output is correct
34 Correct 75 ms 11756 KB Output is correct
35 Correct 83 ms 11160 KB Output is correct
36 Correct 82 ms 11532 KB Output is correct
37 Correct 84 ms 11708 KB Output is correct
38 Correct 81 ms 11320 KB Output is correct
39 Runtime error 489 ms 524288 KB Execution killed with signal 9
40 Halted 0 ms 0 KB -