Submission #1087009

#TimeUsernameProblemLanguageResultExecution timeMemory
1087009ccccFinancial Report (JOI21_financial)C++14
48 / 100
4057 ms6512 KiB
/// YVKNTD
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define f(i, a, b) for(int i = a; i <= b; i++)
#define fr(i, a, b) for(int i = a; i >= b; i--)
#define pii pair <int, int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define in insert
#define vvec vector<vector<int>>
#define Keiiiii ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ___ 1000 * clock() / CLOCKS_PER_SEC

using namespace std;

const int N = 3e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e16;
int n, k, a[N];

void READ()
{
    cin >> n >> k;
    f(i, 1, n) cin >> a[i];
}

struct ST
{
    int st[N * 4];
    void up(int i, int l, int r, int j, int w)
    {
        if(j > r || j < l) return;
        if(l == r) { st[i] = w; return; }
        int mid = (l + r) >> 1;
        up(i << 1, l, mid, j, w);
        up(i << 1 | 1, mid + 1, r, j, w);
        st[i] = min(st[i << 1], st[i << 1 | 1]);
    }

    int get(int i, int l, int r, int x, int y)
    {
        if(x > r || y < l) return 0;
        if(x <= l && r <= y) return st[i];
        int mid = (l + r) >> 1;
        return min(get(i << 1, l, mid, x, y), get(i << 1 | 1, mid + 1, r, x, y));
    }
} f;

void cmprss()
{
    vector <int> z;
    f(i, 1, n) z.eb(a[i]);
    sort(z.begin(), z.end());
    z.resize(unique(z.begin(), z.end()) - z.begin());
    f(i, 1, n) a[i] = lower_bound(z.begin(), z.end(), a[i]) - z.begin() + 1;
}

int dp[N];
void sub3()
{
    int ans = 0;
    f(i, 1, n)
    {
        dp[i] = 1;
        int cnt = 0, mx = 0, ok = 1;
        fr(j, i - 1, 1)
        {
            mx = max(a[j], mx);
            if(a[j] >= a[i]) cnt++;
            else cnt = 0;

            if(cnt >= k) ok = 0;
            if(i - j <= k)
            {
                if(a[i] > a[j]) dp[i] = max(dp[i], dp[j] + 1);
            }
            else if(ok)
            {
                if(a[i] > a[j]) dp[i] = max(dp[i], dp[j] + 1);
            }
        }
        ans = max(ans, dp[i]);
    }
    cout << ans << "\n";
}

void SOLVE()
{
    sub3();
//    k++;
//    cmprss();
//    multiset <int> s;
//    int ans = 0;
//    f(i, 1, n)
//    {
//        if(i > k)
//        {
//            s.erase(s.find(a[i - k]));
//            if(s.find(a[i - k]) == s.end()) f.up(1, 1, n, a[i - k], 0);
//        }
//        s.in(a[i]);
//        int cur = f.get(1, 1, n, 1, a[i] - 1) + 1;
//        f.up(1, 1, n, a[i], cur);
//        ans = max(ans, cur);
//    }
//    cout << ans;
}

signed main()
{
    Keiiiii
    if(fopen("TASK.INP", "r"))
    {
        freopen("TASK.INP", "r", stdin);
        freopen("TASK.OUT", "w", stdout);
    }
    #define TASK "IMPAIR"
    if(fopen(TASK ".INP", "r"))
    {
        freopen(TASK ".INP", "r", stdin);
        freopen(TASK ".OUT", "w", stdout);
    }
    int TEST = 1;
    while(TEST--)
    {
        READ();
        SOLVE();
    }
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
    return 0;
}

///    /\_/\
///   (= ._.)
///   / >  \>

Compilation message (stderr)

Main.cpp:136:1: warning: multi-line comment [-Wcomment]
  136 | ///    /\_/\
      | ^
Main.cpp: In function 'int main()':
Main.cpp:117:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |         freopen("TASK.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:118:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  118 |         freopen("TASK.OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:123:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  123 |         freopen(TASK ".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:124:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  124 |         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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...