Submission #1258921

#TimeUsernameProblemLanguageResultExecution timeMemory
1258921khanhdangiuuBoat (APIO16_boat)C++20
9 / 100
2095 ms328 KiB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pi 3.14159265358979323846 
#define pb push_back
#define ar array

template<typename T, typename cmp = std::greater<T>>
using pq = priority_queue<T, vector<T>, cmp>;

template<typename T, typename cmp = std::less<T>>
using ordered_set = tree<T, __gnu_pbds::null_type, cmp, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

void chay()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define task "Hi"
    freopen(task".INP", "r", stdin);
    freopen(task".OUT", "w", stdout);
}

const int N = 500, INF = numeric_limits<int>::max();
const int block = 600;
const long long INFLL = numeric_limits<ll>::max();
long long M = 1e9+7;

int n, a[N+5], b[N+5];

namespace sub1
{

    bool check()
    {
        bool ok = true;
        for (int i = 1; i <= n; i++)
        {
            if (a[i] != b[i]) ok = false;
        }
        return n <= 500 && ok;
    }

    int dp[N+5];

    void solve()
    {
        dp[0] = 1;
        a[n+1] = INF;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 0; j < i; j++)
            {
                if (a[i] > a[j]) dp[i] += dp[j];
                if (dp[i] >= M) dp[i] -= M;
            }
        }

        int tong = 0;
        for (int i = 1; i <= n; i++)
        {
            tong += dp[i];
            if (tong >= M) tong -= M;
        }
        cout<<tong;
    }
}

namespace sub2
{
    bool check()
    {
        int tong = 0;
        for (int i = 1; i <= n; i++)
        {
            tong += b[i] - a[i];
            if (tong > 1e6) return false;
        }
        return true;
    }

    struct BIT
    {
        int n;
        vector<int> cay;

        BIT(int _n)
        {
            this->n = _n;
            cay.resize(n+1);
        }

        void update(int i, int ss)
        {
            for (; i <= n; i += -i&i)
            {
                cay[i] += ss;
                if (cay[i] >= M) cay[i] -= M;
            }
        }

        int lay(int i)
        {
            int tong = 0;
            for (; i > 0; i -= -i&i)
            {
                tong += cay[i];
                if (tong >= M) tong -= M;
            }
            return tong;
        }
    };

    void solve()
    {
        vector<int> c;
        for (int i = 1; i <= n; i++) 
        {
            c.pb(a[i]);
            c.pb(b[i]);
        }
        c.pb(-INF);
        c.pb(0);
        
        
        vector<int> d = c;
        sort(d.begin(), d.end());
        d.erase(unique(d.begin(), d.end()), d.end());

        unordered_map<int,int> m;
        for (int x : c)
        {
            if (m[x]) continue;
            int id = lower_bound(d.begin(), d.end(), x) - d.begin();
            m[x] = id;
            //cout<<x<<' '<<id<<'\n';
        }

        BIT cay((int)d.size());
        cay.update(m[0], 1);

        int kq = 0;

        for (int i = 1; i <= n; i++)
        {
            int sl = b[i] - a[i] + 1;
            vector<int> v(sl), vt(sl);
            for (int j = a[i]; j <= b[i]; j++)
            {   
                int e = j - a[i];
                vt[e] = m[j];
                v[e] = cay.lay(vt[e]-1); 
                kq += v[e];
                if (kq >= M) kq -= M;
            }

            for (int j = a[i]; j <= b[i]; j++)
            {
                int e = j - a[i];
                cay.update(vt[e], v[e]);
            }
        }
        cout<<kq;
    }
}

void solve()
{
    cin>>n;
    for (int i = 1; i <= n; i++) cin>>a[i]>>b[i];

    //if (sub1::check()) return sub1::solve();
    if (sub2::check()) return sub2::solve();
}
 
signed main ()
{
    //chay();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;   
    //cin>>t; 
    while (t--)
    {
        solve();
    }

    return 0;
}

Compilation message (stderr)

boat.cpp: In function 'void chay()':
boat.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     freopen(task".INP", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
boat.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     freopen(task".OUT", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...