Submission #609528

#TimeUsernameProblemLanguageResultExecution timeMemory
609528MohamedAliSaidaneMeetings (IOI18_meetings)C++14
19 / 100
2987 ms786432 KiB
#include <bits/stdc++.h>
#include "meetings.h"
    using namespace std;

    typedef long long ll;

    typedef pair<int,int> pii;
    typedef pair<ll,ll> pll;

    typedef vector<int> vi;
    typedef vector<ll> vll;
    typedef vector<pii> vpi;
    typedef vector<pll> vpl;

    #define pb push_back
    #define popb pop_back
    #define all(x) (x).begin(),(x).end()

    #define ff first
    #define ss second

    const ll INF = 1e18;

    const int nax =  1e5 + 4;
    ll sp[nax][20], A[nax];
    int LG[nax];
    int n, q;
    void build()
    {
        for(int i = 0 ; i < n; i++)
            sp[i][0] = A[i];
        for(int j = 1; j < 20; j ++)
            for(int i = 0 ; i + (1 << j) <= n; i ++)
                sp[i][j] = max(sp[i][j - 1], sp[i + (1 << (j-1))][j - 1]);
    }
    ll rmq(int l, int r)
    {
        if(l > r)
            swap(l, r);
        int j = LG[r - l + 1];
        return max(sp[l][j], sp[r - (1 << j) + 1][j]);
    }
    vll minimum_costs(vi H, vi L, vi R)
    {
        n = H.size();
        for(int i = 0  ; i < n; i ++)
            A[i] = H[i];
        q = L.size();
        LG[1] = 0 ;
        for(int i= 2; i < nax;i ++)
            LG[i] = LG[i/2] + 1;
        build();
        ll pref[n][n + 1];
        //cout << 5 << endl;
        for(int i = 0; i < n;i ++)
        {
            pref[i][0] = 0ll;
            //cout << i << '\n';
            for(int j = 0 ; j < n ;j++)
            {
                //cout << pref[i][j] << ' ';
                pref[i][j + 1] = pref[i][j] + rmq(i, j);
            }
            //cout << '\n';
        }
        vll ans(q, INF);
        for(int query = 0; query < q; query ++)
        {
            int l = L[query];
            int r = R[query];
            for(int i = l; i <= r; i ++)
            {
                ans[query] = min(ans[query], pref[i][r + 1] - pref[i][l]);
            }
        }
        return ans;
    }
    /*
    int32_t main()
    {
        int n, q;
        cin >> n >> q;
        vi H(n), L(q), R(q);
        for(int i = 0 ; i < n;i ++)
            cin >> H[i];
        for(int i = 0; i < q; i ++)
            cin >> L[i] >> R[i];
        vll C = minimum_costs(H, L, R);
        for(auto e: C)
            cout << e << '\n';
    }


/*
4 2
2 4 3 5
0 1
2 3
*/

Compilation message (stderr)

meetings.cpp:94:1: warning: "/*" within comment [-Wcomment]
   94 | /*
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...