QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#673803#6104. Building BombingstompQWA 1ms7756kbC++232.1kb2024-10-25 10:25:362024-10-25 10:25:36

Judging History

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

  • [2024-10-25 10:25:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7756kb
  • [2024-10-25 10:25:36]
  • 提交

answer

#include <iostream>
#include <map>
using namespace std;
int t[400005][11], lazy[400005][11], a[100005], f[100005][12];
map<int, int> m;
void push(int v, int h) {
    t[v * 2][h] += lazy[v][h];
    t[v * 2 + 1][h] += lazy[v][h];
    lazy[v * 2][h] += lazy[v][h];
    lazy[v * 2 + 1][h] += lazy[v][h];
    lazy[v][h] = 0;
}
void update(int v, int h, int tl, int tr, int l, int r, int x, int fl) {
    if (l > r) return;
    if (tl == l && tr == r) {
        if (fl == 0) t[v][h] = x;
        else {
            t[v][h] += x;
            lazy[v][h] += x;
        }
        return;
    }
    push(v, h);
    int mid = (tl + tr) / 2;
    update(v * 2, h, tl, mid, l, min(r, mid), x, fl);
    update(v * 2 + 1, h, mid + 1, tr, max(l, mid + 1), r, x, fl);
    t[v][h] = min(t[v * 2][h], t[v * 2 + 1][h]);
}
int sum(int v, int h, int tl, int tr, int l, int r) {
    if (l > r) return 1e9;
    if (tl == l && tr == r) {
        return t[v][h];
    }
    int mid = (tl + tr) / 2;
    return min(sum(v * 2, h, tl, mid, l, min(r, mid)), sum(v * 2 + 1, h, mid + 1, tr, max(l, mid + 1), r));
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, l, k, z = 0;
    cin >> n >> l >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        m[a[i]] = 1;
    }
    for (auto &w : m) w.second = ++z;
    for (int i = 1; i <= n; i++) a[i] = m[a[i]];
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= k; j++) {
            update(1, j, 1, z, a[i], a[i], 1e9, 0);
            f[i][j] = 1e9;
        }
    }
    update(1, 1, 1, z, a[l], a[l], 0, 0);
    f[a[l]][1] = 0;
    for (int i = l + 1; i <= n; i++) {
        for (int j = k; j >= 2; j--) {
            int h = sum(1, j - 1, 1, z, 1, a[i]);
            h = min(h, sum(1, j, 1, z, a[i], a[i]));
            update(1, j, 1, z, a[i], a[i], h, 0);
        }
        for (int j = 1; j <= k; j++) {
            update(1, j, 1, z, 1, a[i] - 1, 1, 1);
        }
    }
    int res = sum(1, k, 1, z, 1, z);
    if (res >= 1e6) cout << -1;
    else cout << res;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7644kb

input:

7 2 3
10 30 90 40 60 60 80

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 7652kb

input:

3 2 2
30 20 10

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

score: 0
Accepted
time: 1ms
memory: 7756kb

input:

1 1 1
608954134

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 7592kb

input:

10 5 3
872218248 517822599 163987167 517822599 458534407 142556631 142556631 458534407 458534407 872218248

output:

0

result:

wrong answer 1st numbers differ - expected: '-1', found: '0'