QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#304347#8006. Dinosaur Bones Diggingucup-team228#WA 11ms53296kbC++173.9kb2024-01-13 18:09:592024-01-13 18:10:00

Judging History

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

  • [2024-01-13 18:10:00]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:53296kb
  • [2024-01-13 18:09:59]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

template <typename T>
struct lazy_segment_tree {
    static const int N = 1e6 + 10;
    const T inf = numeric_limits<T>::max() / 2 - 10;
    const T good_value = 0;
    T a[N], t[4 * N], ch[4 * N];
    T merge(T a, T b) {
        return max(a, b);
    }
    void push(int v, int tl, int tr) {
        if (!ch[v]) {
            return;
        }
        t[v] += ch[v];
        if (tl < tr) {
            ch[v + v] += ch[v];
            ch[v + v + 1] += ch[v];
        }
        ch[v] = 0;
    }
    void update(int l, int r, T x, int v = 1, int tl = 0, int tr = N - 1) {
        push(v, tl, tr);
        if (r < tl || tr < l) return;
        if (l <= tl && tr <= r) {
            ch[v] += x;
            push(v, tl, tr);
            return;
        }
        int tm = (tl + tr) / 2;
        update(l, r, x, v + v, tl, tm);
        update(l, r, x, v + v + 1, tm + 1, tr);

    }
    T get(int l, int r, int v = 1, int tl = 0, int tr = N - 1) {
        push(v, tl, tr);
        if (r < tl || tr < l) return good_value;
        if (l <= tl && tr <= r) return t[v];
        int tm = (tl + tr) / 2;
        T res = merge(get(l, r, v + v, tl, tm), get(l, r, v + v + 1, tm + 1, tr));
        t[v] = merge(t[v + v], t[v + v + 1]);
        return res;
    }
};

lazy_segment_tree<int> tree;

const int N = 1e6 + 10;
int a[N];
int l[N], r[N];
bool alive[N];
vector<int> open[N], close[N];
int id_lef[N], id_rig[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int q;
    cin >> q;
    for (int i = 1; i <= q; i++) {
        cin >> l[i] >> r[i];
    }

    for (int i = 1; i <= q; i++) {
        open[l[i]].push_back(i);
        close[r[i]].push_back(i);
        alive[i] = true;
    }

    multiset<int> right_ends;
    for (int i = 1; i <= n; i++) {
        sort(open[i].begin(), open[i].end(), [&](int x, int y) {
            return r[x] > r[y];
        });

        for (int j : open[i]) {
            if (!right_ends.empty() && *right_ends.rbegin() >= r[j]) {
                alive[j] = false;
            }
            right_ends.insert(r[j]);
        }

        for (int j : close[i]) {
            right_ends.erase(right_ends.find(r[j]));
        }
    }

    vector<pair<int, int>> segs;
    for (int i = 1; i <= q; i++) {
        if (alive[i]) {
            segs.emplace_back(l[i], r[i]);
        }
    }
    sort(segs.begin(), segs.end());
    for (int i = 0; i + 1 < segs.size(); i++) {
        assert(segs[i].first < segs[i + 1].first && segs[i].second < segs[i + 1].second);
    }

    for (int i = 1; i <= n; i++) {
        open[i].clear();
        close[i].clear();
        id_lef[i] = -1;
        id_rig[i] = -1;
    }

    for (int i = 0; i < segs.size(); i++) {
        auto [l, r] = segs[i];
        open[l].push_back(i);
        close[r].push_back(i);
    }
    set<int> ids;
    for (int i = 1; i <= n; i++) {
        for (int j : open[i]) {
            ids.insert(j);
        }
        if (!ids.empty()) {
            id_lef[i] = *ids.begin();
            id_rig[i] = *ids.rbegin();
        }
        for (int j : close[i]) {
            ids.erase(j);
        }
    }

    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 1);
    sort(ord.begin(), ord.end(), [&](int i, int j) {
        return a[i] > a[j];
    });
    ll ans = 0;
    for (int i : ord) {
        if (id_lef[i] != -1) {
            ans = max(ans, 1ll * a[i] * tree.get(id_lef[i], id_rig[i]));
            tree.update(id_lef[i], id_rig[i], 1);
        }
    }
    cout << ans << "\n";

#ifdef LOCAL
    cout << "\nTime elapsed: " << double(clock()) / CLOCKS_PER_SEC << " s.\n";
#endif
}

詳細信息

Test #1:

score: 100
Accepted
time: 8ms
memory: 52460kb

input:

6
3 5 2 7 4 6
2
1 5
3 6

output:

9

result:

ok answer is '9'

Test #2:

score: 0
Accepted
time: 3ms
memory: 53296kb

input:

1
100
1
1 1

output:

0

result:

ok answer is '0'

Test #3:

score: 0
Accepted
time: 11ms
memory: 52448kb

input:

20
451541695 690066663 673479208 448269517 560111835 982439295 929007403 955125568 735150915 829197546 256554877 435297385 348361716 763574893 202875223 881879899 590527232 256896900 31383620 400212120
5
4 8
4 17
11 13
19 20
17 18

output:

4480894680

result:

ok answer is '4480894680'

Test #4:

score: -100
Wrong Answer
time: 8ms
memory: 52468kb

input:

100
310791482 148245051 114541081 918781914 681485137 656214017 226939378 970492592 431199764 162399115 490488808 3059986 487892489 611730708 952388887 418021477 917893766 587279310 363995315 342188612 72531000 156997725 896382592 359419647 144773021 872005978 496280920 65840663 56171913 273988049 6...

output:

23053021803

result:

wrong answer expected '23457460782', found '23053021803'