QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#48482#1848. Interval ShuffledykwWA 243ms12648kbC++142.3kb2022-09-13 23:53:282022-09-13 23:53:30

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-13 23:53:30]
  • Judged
  • Verdict: WA
  • Time: 243ms
  • Memory: 12648kb
  • [2022-09-13 23:53:28]
  • Submitted

answer

#include <bits/stdc++.h>

#define debug(...) fprintf(stderr, __VA_ARGS__)

using i64 = long long;

constexpr int N = 2e5 + 5, INF = 0x3f3f3f3f;

void optimize() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

int a[N];
struct {
    int l, r, v, cov;
} tr[N * 4];

#define ls(x) (x * 2)
#define rs(x) (x * 2 + 1)

void pushup(int x) {
    tr[x].v = std::max(tr[ls(x)].v, tr[rs(x)].v);
}

void build(int l, int r, int x = 1) {
    tr[x] = {l, r, a[l], 0};
    if (l == r) {
        return;
    }
    int mid = (l + r) / 2;
    build(l, mid, ls(x));
    build(mid + 1, r, rs(x));
    pushup(x);
}

void update(int x, int v, bool flag = true) {
    if (v < tr[x].cov) {
        return;
    }
    if (flag) {
        tr[x].cov = v;
        tr[x].v = v + 1;
    } else {
        tr[x].cov = tr[x].v = v;
    }
}

void pushdown(int x) {
    if (tr[x].cov) {
        int v1 = tr[ls(x)].v, v2 = tr[rs(x)].v;
        update(ls(x), tr[x].cov, tr[x].v > tr[x].cov && v1 >= v2);
        update(rs(x), tr[x].cov, tr[x].v > tr[x].cov && v2 >= v1);
        tr[x].cov = 0;
    }
}

void modify(int l, int r, int v, int x = 1) {
    if (l <= tr[x].l && tr[x].r <= r) {
        update(x, v, tr[x].v == v);
        return;
    }
    pushdown(x);
    int mid = (tr[x].l + tr[x].r) / 2;
    if (l <= mid) {
        modify(l, r, v, ls(x));
    }
    if (r > mid) {
        modify(l, r, v, rs(x));
    }
    pushup(x);
}

int query(int l, int r, int x = 1) {
    if (l <= tr[x].l && tr[x].r <= r) {
        return tr[x].v;
    }
    pushdown(x);
    int mid = (tr[x].l + tr[x].r) / 2;
    if (l > mid) {
        return query(l, r, rs(x));
    } else if (r <= mid) {
        return query(l, r, ls(x));
    } else {
        return std::max(query(l, r, ls(x)), query(l, r, rs(x)));
    }
}

void pushall(int x = 1) {
    if (tr[x].l == tr[x].r) {
        printf("%d ", tr[x].v);
        return;
    }
    pushdown(x);
    pushall(ls(x));
    pushall(rs(x));
}

int main(void) {
    // optimize();
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
    }
    build(1, n);
    for (int i = 1, l, r; i <= m; ++i) {
        scanf("%d%d", &l, &r);
        int mx = query(l, r);
        modify(l, r, mx);
    }
    pushall();
    return 0;
}

详细

Test #1:

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

input:

4 3
0 1 0 1
2 4
1 3
2 3

output:

2 4 3 2 

result:

ok 4 number(s): "2 4 3 2"

Test #2:

score: -100
Wrong Answer
time: 243ms
memory: 12648kb

input:

188394 182563
1 40 31 12 49 8 30 49 46 22 49 36 11 47 15 32 20 18 11 41 4 49 31 28 14 33 27 3 5 30 23 30 36 42 24 5 35 25 8 21 7 7 0 1 10 34 26 16 15 36 39 4 11 41 34 30 7 40 7 26 27 50 6 4 15 12 20 2 16 45 8 37 12 25 33 3 23 16 13 47 33 40 25 8 29 42 25 34 49 17 1 12 37 7 27 11 44 11 38 6 46 17 35 ...

output:

1 48490 77084 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 83461 8346...

result:

wrong answer 2nd numbers differ - expected: '49137', found: '48490'