Submission #1087740

#TimeUsernameProblemLanguageResultExecution timeMemory
1087740tradzFinancial Report (JOI21_financial)C++14
0 / 100
97 ms13392 KiB
#include <bits/stdc++.h>

#define For(i,a,b) for(int i = a; i <= b; i++)
#define Ford(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define RRH(v) v.resize(unique(all(v)) - v.begin())

using namespace std;
const int  N = 1e6+7;
const int M = 1e9+7;
const ll oo = 3e18;

int n, a[N], d, dp[N];
ii b[N];
int st[N];

void up(int id, int l, int r, int u, int v) {
    if (l > u or r < u) return;
    if (l == r) {
        st[id] = v;
        return;
    }
    int mid = l + r >> 1;
    up(id * 2, l, mid, u, v);
    up(id * 2 + 1, mid + 1, r, u, v);
    st[id] = max(st[id * 2], st[id * 2 + 1]);
}

int get(int id, int l, int r, int u, int v) {
    if (l > v or r < u) return 0;
    if (u <= l and r <= v) return st[id];
    int mid = l + r >> 1;
    return max(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);

    #define TASK ""
    if (fopen (".inp", "r")) {
        freopen (".inp", "r", stdin);
        freopen (".out", "w", stdout);
    }
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    cin >> n >> d;
    For (i, 1, n) cin >> a[i], b[i] = {a[i], i};
    For (i, 1, n) dp[i] = 0;

    sort (b + 1, b + n + 1, [](ii a, ii b) {
        if (a.fi == b.fi) return a.se > b.se;
        return a.fi > b.fi;
    });
    memset(st, 0, sizeof st);
    queue<int> q;
    For (i, 1, n) {
        if (b[i].fi != b[i - 1].fi) {
            while(q.size()) {
                int k = q.front();
                q.pop();
                up(1, 1, n, k, dp[k]);
            }
        }
        int pos = b[i].se;
        dp[pos] = max(dp[i], get(1, 1, n, i + 1, i + d)) + 1;
        q.push(pos);
    }

    while (q.size()) {
        int k = q.front();
        q.pop();
        up(1, 1, n, k, dp[k]);
    }

    cout << get(1, 1, n, 1, n) << '\n';

    return 0;
}


Compilation message (stderr)

Main.cpp: In function 'void up(int, int, int, int, int)':
Main.cpp:27:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   27 |     int mid = l + r >> 1;
      |               ~~^~~
Main.cpp: In function 'int get(int, int, int, int, int)':
Main.cpp:36:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |     int mid = l + r >> 1;
      |               ~~^~~
Main.cpp: In function 'int main()':
Main.cpp:45:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen (".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:46:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         freopen (".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
Main.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         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...