Submission #598932

# Submission time Handle Problem Language Result Execution time Memory
598932 2022-07-19T08:07:20 Z Jomnoi Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
30 / 100
3000 ms 75672 KB
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 1e6 + 5;
const int INF = 1e9 + 7;

int w[MAX_N];

struct A {
    int ma, mi;
    bool ok;

    A operator+(const A &o) const {
        int ma_, mi_;
        bool ok_;
        ok_ = ok | o.ok | (ma > o.mi);
        ma_ = max(ma, o.ma);
        mi_ = min(mi, o.mi);
        return {ma_, mi_, ok_};
    }
}tree[4 * MAX_N];

void build(int idx, int l, int r) {
    if(l == r) {
        tree[idx] = {w[l], w[l], false};
        return;
    }

    int mid = (l + r) / 2;
    build(idx * 2, l, mid);
    build(idx * 2 + 1, mid + 1, r);
    tree[idx] = tree[idx * 2] + tree[idx * 2 + 1];
}

A query(int idx, int l, int r, int ql, int qr) {
    if(r < ql or qr < l) {
        return {0, INF, false};
    }
    if(ql <= l and r <= qr) {
        return tree[idx];
    }

    int mid = (l + r) / 2;
    return query(idx * 2, l, mid, ql, qr) + query(idx * 2 + 1, mid + 1, r, ql, qr);
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int N, M;
    cin >> N >> M;

    int min_w = INF;
    for(int i = 1; i <= N; i++) {
        cin >> w[i];

        min_w = min(min_w, w[i]);
    }

    build(1, 1, N);

    bool sub2 = true;
    vector <tuple <int, int, int>> queries;
    while(M--) {
        int l, r, k;
        cin >> l >> r >> k;

        if(k >= min_w) {
            sub2 = false;
        }

        queries.emplace_back(l, r, k);
    }

    if(sub2 == true) {
        for(auto [l, r, k] : queries) {
            cout << !query(1, 1, N, l, r).ok << '\n';
        }
    }
    else {
        for(auto [l, r, k] : queries) {
            multiset <int> s;
            for(int i = l; i <= r; i++) {
                s.insert(w[i]);
            }

            int ma = 0;
            for(int i = l; i < r; i++) {
                s.erase(s.lower_bound(w[i]));
                auto it = s.lower_bound(w[i]);
                if(it != s.begin()) {
                    ma = max(ma, w[i] + *prev(it));
                }
            }

            cout << (ma <= k) << '\n';
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 3 ms 356 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 15 ms 380 KB Output is correct
7 Correct 16 ms 384 KB Output is correct
8 Correct 22 ms 340 KB Output is correct
9 Correct 9 ms 340 KB Output is correct
10 Correct 19 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 3 ms 356 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 15 ms 380 KB Output is correct
7 Correct 16 ms 384 KB Output is correct
8 Correct 22 ms 340 KB Output is correct
9 Correct 9 ms 340 KB Output is correct
10 Correct 19 ms 340 KB Output is correct
11 Correct 311 ms 488 KB Output is correct
12 Correct 1038 ms 792 KB Output is correct
13 Correct 1221 ms 924 KB Output is correct
14 Correct 2102 ms 968 KB Output is correct
15 Correct 2148 ms 860 KB Output is correct
16 Correct 2899 ms 852 KB Output is correct
17 Correct 1652 ms 696 KB Output is correct
18 Correct 1989 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1371 ms 64588 KB Output is correct
2 Correct 1475 ms 75608 KB Output is correct
3 Correct 1477 ms 75428 KB Output is correct
4 Correct 1565 ms 75672 KB Output is correct
5 Correct 1499 ms 75620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3054 ms 10656 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 3 ms 356 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 15 ms 380 KB Output is correct
7 Correct 16 ms 384 KB Output is correct
8 Correct 22 ms 340 KB Output is correct
9 Correct 9 ms 340 KB Output is correct
10 Correct 19 ms 340 KB Output is correct
11 Correct 311 ms 488 KB Output is correct
12 Correct 1038 ms 792 KB Output is correct
13 Correct 1221 ms 924 KB Output is correct
14 Correct 2102 ms 968 KB Output is correct
15 Correct 2148 ms 860 KB Output is correct
16 Correct 2899 ms 852 KB Output is correct
17 Correct 1652 ms 696 KB Output is correct
18 Correct 1989 ms 852 KB Output is correct
19 Execution timed out 3061 ms 21856 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 3 ms 356 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 15 ms 380 KB Output is correct
7 Correct 16 ms 384 KB Output is correct
8 Correct 22 ms 340 KB Output is correct
9 Correct 9 ms 340 KB Output is correct
10 Correct 19 ms 340 KB Output is correct
11 Correct 311 ms 488 KB Output is correct
12 Correct 1038 ms 792 KB Output is correct
13 Correct 1221 ms 924 KB Output is correct
14 Correct 2102 ms 968 KB Output is correct
15 Correct 2148 ms 860 KB Output is correct
16 Correct 2899 ms 852 KB Output is correct
17 Correct 1652 ms 696 KB Output is correct
18 Correct 1989 ms 852 KB Output is correct
19 Correct 1371 ms 64588 KB Output is correct
20 Correct 1475 ms 75608 KB Output is correct
21 Correct 1477 ms 75428 KB Output is correct
22 Correct 1565 ms 75672 KB Output is correct
23 Correct 1499 ms 75620 KB Output is correct
24 Execution timed out 3054 ms 10656 KB Time limit exceeded
25 Halted 0 ms 0 KB -