QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#671575#1132. Financial ReportWansur#0 4ms55228kbC++232.0kb2024-10-24 13:27:402024-10-24 13:27:41

Judging History

你现在查看的是最新测评结果

  • [2024-10-24 13:27:41]
  • 评测
  • 测评结果:0
  • 用时:4ms
  • 内存:55228kb
  • [2024-10-24 13:27:40]
  • 提交

answer

#include <bits/stdc++.h>
#define ent '\n'
#define int long long

using namespace std;
typedef long long ll;

const int maxn = 1e6 + 12;
const int mod = 998244353;

multiset<int> st[maxn];
int t[maxn * 4];
int suff[maxn];
int dp[maxn];
int a[maxn];
int n, m, k;

void upd(int v, int tl, int tr, int pos) {
    if(tl == tr) {
        t[v] = 0;
        if(st[tl].size() != 0) {
            t[v] = *st[tl].rbegin();
        }
        return;
    }
    int mid = tl + tr >> 1;
    if(pos <= mid) {
        upd(v * 2, tl, mid, pos);
    }
    else {
        upd(v * 2 + 1, mid + 1, tr, pos);
    }
    t[v] = max(t[v * 2], t[v * 2 + 1]);
}

int get(int v, int tl, int tr, int l, int r) {
    if(tl > r || l > tr) return 0;
    if(tl >= l && tr <= r) return t[v];
    int mid = tl + tr >> 1;
    return max(get(v * 2, tl, mid, l, r), get(v * 2 + 1, mid + 1, tr, l, r));
}

void solve() {
    cin >> n >> k;
    vector<int> ord;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        ord.push_back(a[i]);
    }
    sort(ord.begin(), ord.end());
    ord.resize(unique(ord.begin(), ord.end()) - ord.begin());
    for(int i = 1; i <= n; i++) {
        a[i] = lower_bound(ord.begin(), ord.end(), a[i]) - ord.begin() + 1;
    }
    for(int x = n; x; x--) {
        int mx = 0;
        for(int i = x; i <= n; i++) {
           dp[i] = get(1, 1, n, 1, a[i] - 1) + 1;
            st[a[i]].insert(dp[i]);
            upd(1, 1, n, a[i]);
            if(i > k) {
                st[a[i - k]].erase(dp[i - k]);
                upd(1, 1, n, a[i - k]);
            }
            mx = max(mx, dp[i] + suff[i + 1]);
        }
        suff[x] = mx;
        for(int i = 1; i <= n; i++) {
            dp[i] = 0;
            st[i].clear();
        }
        for(int i = 1; i <= n * 4; i++) {
            t[i] = 0;
        }
    }
    cout << suff[1] << '\n';
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
//     cin >> t;
    while(t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 14
Accepted
time: 3ms
memory: 55228kb

input:

1 1
314159265

output:

1

result:

ok single line: '1'

Test #2:

score: 14
Accepted
time: 4ms
memory: 54556kb

input:

1 1
0

output:

1

result:

ok single line: '1'

Test #3:

score: 14
Accepted
time: 3ms
memory: 51756kb

input:

1 1
1000000000

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Wrong Answer
time: 4ms
memory: 54064kb

input:

2 1
299792458 299792458

output:

2

result:

wrong answer 1st lines differ - expected: '1', found: '2'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Time Limit Exceeded

Test #62:

score: 0
Time Limit Exceeded

input:

300000 1
285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 285899902 2...

output:


result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #76:

score: 0
Time Limit Exceeded

input:

300000 300000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 ...

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #1:

0%