Submission #894037

# Submission time Handle Problem Language Result Execution time Memory
894037 2023-12-27T20:44:07 Z Olympia Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
8 / 100
3000 ms 53884 KB
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <cassert>
using namespace std;
struct Node {
    int mx;
    int mn;
    int val;
    Node () {
        this->mx = INT_MIN, this->mn = INT_MAX, this->val = 0;
    }
};
Node merge (Node left, Node right) {
    Node ans = Node();
    ans.mn = min(left.mn, right.mn);
    ans.mx = max(left.mx, right.mx);
    ans.val = max(left.val, right.val);
    if (left.mx > right.mn) {
        ans.val = max(ans.val, left.mx + right.mn);
    }
    return ans;
}
struct SegmentTree {
    vector<Node> vec;
    vector<int> nodes;
    Node query (int dum, int tl, int tr, int l, int r) {
        if (tl >= l && tr <= r) {
            return vec[dum];
        }
        if (tl > r || tr < l) {
            return {};
        }
        return merge(query(2 * dum + 1, tl, (tl + tr)/2,l, r), query(2 * dum + 2, (tl + tr)/2 + 1, tr, l, r));
    }
    int query (int l, int r) {
        return query(0, 0, (int)vec.size()/2 - 1, l, r).val;
    }
    Node build (int dum, int tl, int tr) {
        if (tl == tr) {
            vec[dum] = Node();
            vec[dum].mn = vec[dum].mx = this->nodes[tl];
            return vec[dum];
        }
        vec[dum] = merge(build(2 * dum + 1, tl, (tl + tr)/2), build(2 * dum + 2, (tl + tr)/2 + 1, tr));
        return vec[dum];
    }
    SegmentTree (vector<int> nodes) {
        this->nodes = nodes;
        int n = nodes.size();
        n = (1 << (int)log2(n)) * 2;
        vec.assign(2 * n, Node());
        while (this->nodes.size() < vec.size()) {
            this->nodes.push_back(0);
        }
        build(0, 0, (int)vec.size()/2 - 1);
    }
};
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, q;
    cin >> n >> q;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    SegmentTree st(v);
    while (q--) {
        int l, r, k;
        cin >> l >> r >> k;
        l--, r--;
        int ans = 0;
        for (int i = l; i <= r; i++) {
            for (int j = i + 1; j <= r; j++) {
                if (v[i] > v[j]) {
                    ans = max(ans, v[i] + v[j]);
                }
            }
        }
        cout << (ans <= k) << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 20 ms 504 KB Output is correct
7 Correct 23 ms 348 KB Output is correct
8 Correct 32 ms 488 KB Output is correct
9 Correct 11 ms 348 KB Output is correct
10 Correct 34 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 20 ms 504 KB Output is correct
7 Correct 23 ms 348 KB Output is correct
8 Correct 32 ms 488 KB Output is correct
9 Correct 11 ms 348 KB Output is correct
10 Correct 34 ms 484 KB Output is correct
11 Correct 1020 ms 608 KB Output is correct
12 Execution timed out 3045 ms 860 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3047 ms 53884 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3059 ms 6356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 20 ms 504 KB Output is correct
7 Correct 23 ms 348 KB Output is correct
8 Correct 32 ms 488 KB Output is correct
9 Correct 11 ms 348 KB Output is correct
10 Correct 34 ms 484 KB Output is correct
11 Correct 1020 ms 608 KB Output is correct
12 Execution timed out 3045 ms 860 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 20 ms 504 KB Output is correct
7 Correct 23 ms 348 KB Output is correct
8 Correct 32 ms 488 KB Output is correct
9 Correct 11 ms 348 KB Output is correct
10 Correct 34 ms 484 KB Output is correct
11 Correct 1020 ms 608 KB Output is correct
12 Execution timed out 3045 ms 860 KB Time limit exceeded
13 Halted 0 ms 0 KB -