Submission #48380

# Submission time Handle Problem Language Result Execution time Memory
48380 2018-05-12T11:21:50 Z BThero Boat (APIO16_boat) C++17
31 / 100
727 ms 524288 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 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 = l[i].fi; j <= r[i].fi; ++j) {
            vv.pb(j);
        }
    }

    sort(all(vv));
    vv.resize(unique(all(vv)) - vv.begin());

    m = vv.size();

    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]);
        }
    }

    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

boat.cpp: In function 'void solve()':
boat.cpp:79:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
boat.cpp:82:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &l[i].fi, &r[i].fi);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
4 Correct 2 ms 576 KB Output is correct
5 Correct 3 ms 576 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 576 KB Output is correct
8 Correct 2 ms 576 KB Output is correct
9 Correct 2 ms 576 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 2 ms 576 KB Output is correct
12 Correct 2 ms 664 KB Output is correct
13 Correct 2 ms 664 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Correct 3 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 664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
4 Correct 2 ms 576 KB Output is correct
5 Correct 3 ms 576 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 576 KB Output is correct
8 Correct 2 ms 576 KB Output is correct
9 Correct 2 ms 576 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 2 ms 576 KB Output is correct
12 Correct 2 ms 664 KB Output is correct
13 Correct 2 ms 664 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Correct 3 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 664 KB Output is correct
21 Correct 61 ms 4796 KB Output is correct
22 Correct 63 ms 4840 KB Output is correct
23 Correct 58 ms 4840 KB Output is correct
24 Correct 65 ms 4864 KB Output is correct
25 Correct 66 ms 4864 KB Output is correct
26 Correct 70 ms 4864 KB Output is correct
27 Correct 69 ms 4864 KB Output is correct
28 Correct 67 ms 4864 KB Output is correct
29 Correct 69 ms 4864 KB Output is correct
30 Correct 87 ms 8488 KB Output is correct
31 Correct 110 ms 8488 KB Output is correct
32 Correct 90 ms 8488 KB Output is correct
33 Correct 86 ms 8488 KB Output is correct
34 Correct 84 ms 8488 KB Output is correct
35 Correct 94 ms 8488 KB Output is correct
36 Correct 100 ms 8488 KB Output is correct
37 Correct 98 ms 8488 KB Output is correct
38 Correct 97 ms 8488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 727 ms 524288 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
4 Correct 2 ms 576 KB Output is correct
5 Correct 3 ms 576 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 576 KB Output is correct
8 Correct 2 ms 576 KB Output is correct
9 Correct 2 ms 576 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 2 ms 576 KB Output is correct
12 Correct 2 ms 664 KB Output is correct
13 Correct 2 ms 664 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Correct 3 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 664 KB Output is correct
21 Correct 61 ms 4796 KB Output is correct
22 Correct 63 ms 4840 KB Output is correct
23 Correct 58 ms 4840 KB Output is correct
24 Correct 65 ms 4864 KB Output is correct
25 Correct 66 ms 4864 KB Output is correct
26 Correct 70 ms 4864 KB Output is correct
27 Correct 69 ms 4864 KB Output is correct
28 Correct 67 ms 4864 KB Output is correct
29 Correct 69 ms 4864 KB Output is correct
30 Correct 87 ms 8488 KB Output is correct
31 Correct 110 ms 8488 KB Output is correct
32 Correct 90 ms 8488 KB Output is correct
33 Correct 86 ms 8488 KB Output is correct
34 Correct 84 ms 8488 KB Output is correct
35 Correct 94 ms 8488 KB Output is correct
36 Correct 100 ms 8488 KB Output is correct
37 Correct 98 ms 8488 KB Output is correct
38 Correct 97 ms 8488 KB Output is correct
39 Runtime error 727 ms 524288 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Halted 0 ms 0 KB -