답안 #48381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48381 2018-05-12T11:37:03 Z BThero Boat (APIO16_boat) C++17
0 / 100
2 ms 376 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) {
        vv.pb(l[i].fi);
        vv.pb(r[i].fi);
    }

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

    m = vv.size();
    d[m] = 1;

    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

boat.cpp: In function 'void solve()':
boat.cpp:85:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
boat.cpp:88: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);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -