Submission #668382

#TimeUsernameProblemLanguageResultExecution timeMemory
668382danikoynovBoat (APIO16_boat)C++14
31 / 100
2075 ms324404 KiB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 510, maxa = 1e6 + 10;
const ll mod = 1e9 + 7;

int n, a[maxn], b[maxn];
ll dp[maxn], fp[maxa];

void solve()
{
    cin >> n;
    bool diff = false;
    for (int i = 1; i <= n; i ++)
    {
        cin >> a[i] >> b[i];
        if (a[i] != b[i])
            diff = true;
    }

    if (!diff)
    {
        ll ans = 0;
    for (int i = 1; i <= n; i ++)
    {
        dp[i] = 1;
        for (int j = 1; j < i; j ++)
        {
            if (a[i] > a[j])
                dp[i] = (dp[i] + dp[j]) % mod;
        }

        ans = (ans + dp[i]) % mod;
    }
    cout << ans << endl;
    }
    else
    {
        set < int > st;
        for (int i = 1; i <= n; i ++)
            for (int j = a[i]; j <= b[i]; j ++)
            st.insert(j);

        map < int, int > mp;
        int idx = 0;
        for (int cur : st)
            mp[cur] = ++ idx;

        fp[0] = 1;
        for (int i = 1; i <= n; i ++)
        {
            a[i] = mp[a[i]];
            b[i] = mp[b[i]];

            ll sum = 0;
            for (int j = 0; j < a[i]; j ++)
            {
                sum = sum + fp[j];
                if (sum >= mod)
                    sum -= mod;
            }

            ll lsum = sum;
            for (int j = a[i]; j <= b[i]; j ++)
            {

                sum = sum + fp[j];
                if (sum >= mod)
                    sum -= mod;

                fp[j] = (fp[j] + lsum);
                if (fp[j] >= mod)
                    fp[j] -= mod;

                lsum = sum;

            }

            /**for (int j = 0; j < 10; j ++)
                cout << fp[j] << " ";
            cout << endl;*/
        }

        ll ans = 0;
        for (int i = 1; i < maxa; i ++)
        {
            ans = ans + fp[i];
            if (ans >= mod)
                ans -= mod;
        }
        cout << ans << endl;
    }


}

int main()
{
    solve();
    return 0;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...