QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#454318#1132. Financial Reportmakrav0 320ms43168kbC++203.1kb2024-06-24 19:23:262024-06-24 19:23:28

Judging History

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

  • [2024-06-24 19:23:28]
  • 评测
  • 测评结果:0
  • 用时:320ms
  • 内存:43168kb
  • [2024-06-24 19:23:26]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

struct segtree {
    int n;
    vector<int> t;
    segtree() = default;
    segtree(int n_) {
        n = n_;
        t.assign(4 * n, 0);
    }

    void upd(int v, int tl, int tr, int p, int vl) {
        if (tl + 1 == tr) {
            t[v] = vl;
            return;
        }
        int tm = (tl + tr) / 2;
        if (p < tm) upd(v * 2, tl, tm, p, vl);
        else upd(v * 2 + 1, tm, tr, p, vl);
        t[v] = max(t[v * 2], t[v * 2 + 1]);
    }

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

    int getr(int v, int tl, int tr, int p, int vl) {
        if (tr <= p || t[v] <= vl) return -1;
        if (tl + 1 == tr) return tl;
        int tm = (tl + tr) / 2;
        int answ = getr(v * 2, tl, tm, p, vl);
        if (answ == -1) return getr(v * 2 + 1, tm, tr, p, vl);
        return answ;
    }
};

signed main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int n, d; cin >> n >> d;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> ord(n);
    for (int i = 0; i < n; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), [&](int i, int j) {
        return a[i] < a[j];
    });
    
    vector<int> pos(n);
    for (int i = 0; i < n; i++) pos[ord[i]] = i;
    vector<int> prv(n, 0);
    prv[ord[0]] = -1;
    for (int i = 1; i < n; i++) {
        if (a[ord[i]] == a[ord[i - 1]]) prv[ord[i]] = prv[ord[i - 1]];
        else prv[ord[i]] = i - 1;
    }
    set<int> st;
    segtree sg_x(n);
    auto add = [&](int i) {
        auto it = st.lower_bound(i);
        int prv = -1, nxt = -1;
        if (it != st.end()) {
            nxt = *it;
        }
        st.insert(i);
        if (st.find(i) != st.begin()) {
            auto it2 = --st.find(i);
            prv = *it2;
        }
        if (nxt == -1) {
            sg_x.upd(1, 0, n, i, 1e9);  
        } else{
            sg_x.upd(1, 0, n, i, nxt - i);
        }
        if (prv != -1) {
            sg_x.upd(1, 0, n, prv, i - prv);
        }
    };
    vector<int> x(n);
    int cur = 0;
    for (int i = 1; i < n; i++) {
        if (prv[ord[i]] == i - 1) {
            for (int j = cur; j < i; j++) {
                add(ord[j]);
            }
            for (int j = cur; j < i; j++) {
                int ans = sg_x.getr(1, 0, n, ord[j], d);
                if (ans == -1) x[j] = n;
                else x[j] = ans;
            }
            cur = i;
        }
    }
    segtree sg(n);
    vector<int> dp(n);
    vector<vector<int>> del(n);
    for (int i = 0; i < n; i++) {
        for (auto &u : del[i]) {
            sg.upd(1, 0, n, pos[u], 0);
        }
        if (prv[i] == -1) dp[i] = 1;
        else {
            dp[i] = sg.get(1, 0, n, 0, prv[i] + 1) + 1;
        }
        sg.upd(1, 0, n, pos[i], dp[i]);
        if (x[i] + d + 1 < n) del[x[i] + d + 1].push_back(pos[i]);
    }
    cout << dp[n - 1] << '\n';

    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 14
Accepted
time: 0ms
memory: 3656kb

input:

1 1
314159265

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

1 1
0

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

1 1
1000000000

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

2 1
299792458 299792458

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3860kb

input:

2 1
141421356 173205080

output:

2

result:

ok single line: '2'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

2 1
244948974 223606797

output:

1

result:

ok single line: '1'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

2 2
299792458 299792458

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

2 2
141421356 173205080

output:

2

result:

ok single line: '2'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

2 2
244948974 223606797

output:

1

result:

ok single line: '1'

Test #10:

score: -14
Wrong Answer
time: 0ms
memory: 3504kb

input:

3 1
500000000 1000000000 0

output:

1

result:

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

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #62:

score: 12
Accepted
time: 52ms
memory: 28804kb

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:

1

result:

ok single line: '1'

Test #63:

score: -12
Wrong Answer
time: 259ms
memory: 43168kb

input:

299971 1
213313757 312061773 790195557 213313757 0 790195557 30936680 832403554 312061773 30936680 0 213313757 329317874 329317874 0 0 329317874 329317874 0 213313757 329317874 790195557 832403554 832403554 329317874 312061773 832403554 832403554 329317874 329317874 312061773 790195557 790195557 790...

output:

2

result:

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

Subtask #5:

score: 0
Wrong Answer

Test #76:

score: 5
Accepted
time: 42ms
memory: 26616kb

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:

1

result:

ok single line: '1'

Test #77:

score: -5
Wrong Answer
time: 320ms
memory: 40392kb

input:

299994 299994
799095588 515641284 851040998 371590609 581412250 114983578 870953189 65883574 114983578 546636247 675572999 416143410 763181943 799095588 564152084 521371792 455808474 799095588 870953189 839155298 684313832 605076527 675572999 219704773 684313832 372618560 875093839 41381734 11498357...

output:

40

result:

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

Subtask #6:

score: 0
Skipped

Dependency #1:

0%