Submission #677892

#TimeUsernameProblemLanguageResultExecution timeMemory
677892Tien_NoobFinancial Report (JOI21_financial)C++17
48 / 100
709 ms144404 KiB
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 3e5;
int a[N + 1], b[N + 1], d, n;
int dp[7001][7001];
void read()
{
    cin >> n >> d;
    for (int i = 1; i <= n; ++ i)
    {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b + 1, b + n + 1);
    for (int i = 1; i <= n; ++ i)
    {
        a[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;
    }
}
deque<int> q[7001];
void Sub3()
{
    memset(dp, -0x3f, sizeof(d));
    for (int i = 0; i < n; ++ i)
    {
        for (int j = 1; j <= n; ++ j)
        {
            while(!q[j].empty() && dp[i][j] >= dp[q[j].back()][j])
            {
                q[j].pop_back();
            }
            while(!q[j].empty() && q[j].front() + d < i + 1)
            {
                q[j].pop_front();
            }
            q[j].push_back(i);
        }
        dp[i + 1][a[i + 1]] = 1;
        for (int j = 1; j < a[i + 1]; ++ j)
        {
            if (q[j].empty())
            {
                continue;
            }
            dp[i + 1][a[i + 1]] = max(dp[i + 1][a[i + 1]], dp[q[j].front()][j] + 1);
        }
        for (int j = a[i + 1]; j <= n; ++ j)
        {
            if (q[j].empty())
            {
                continue;
            }
            dp[i + 1][j] = max(dp[i + 1][j], dp[q[j].front()][j]);
        }
    }
    cout << *max_element(dp[n] + 1, dp[n] + n + 1);
}
void solve()
{
    if (n <= 7000)
    {
        Sub3();
        return ;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        //freopen(TASK".OUT", "w", stdout);
    }
    int t = 1;
    bool typetest = false;
    if (typetest)
    {
        cin >> t;
    }
    for (int __ = 1; __ <= t; ++ __)
    {
        //cout << "Case " << __ << ": ";
        read();
        solve();
    }
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...