Submission #874358

# Submission time Handle Problem Language Result Execution time Memory
874358 2023-11-16T17:48:04 Z Macker Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
2782 ms 58920 KB
#include <iostream> // #include <fstream>
#include <vector>
#include <list>
#include <algorithm>
#include <math.h>
#include <tuple>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <climits>
#include <cassert>

using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()

struct node {
    int min, max, mxinv;
};
vector<node> st;
int len = 1;

node query(int f, int t, int i = 1, int s = 0, int e = len) {
    if (f >= e || t <= s) return  { INT_MAX, INT_MIN, INT_MIN };
    if (f <= s && e <= t) return st[i];
    node l = query(f, t, i * 2, s, (s + e) / 2);
    node r = query(f, t, i * 2 + 1, (s + e) / 2, e);
    node res;
    res.min = min(l.min, r.min);
    res.max = max(l.max, r.max);
    res.mxinv = max(l.max - r.min, max(l.mxinv, r.mxinv));

    return res;
}

int main()
{
    int n, q; cin >> n >> q;
    while (len < n) len *= 2;
    st.resize(2 * len, { INT_MAX, INT_MIN, INT_MIN });

    for (int i = len; i < len + n; i++) {
        int a; cin >> a;
        st[i] = { a, a, 0 };
    }
    for (int i = len - 1; i > 0; i--) {
        node l = st[i * 2], r = st[i * 2 + 1];
        st[i].min = min(l.min, r.min);
        st[i].max = max(l.max, r.max);
        st[i].mxinv = max(l.max - r.min, max(l.mxinv, r.mxinv));
    }

    while (q--) {
        int f, t, k; cin >> f >> t >> k;
        cout << (query(f - 1, t).mxinv <= k ? 1 : 0) << endl;
    }
}
# 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 Incorrect 1 ms 348 KB Output isn't correct
4 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 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2782 ms 58920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 226 ms 5724 KB Output isn't correct
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 Incorrect 1 ms 348 KB Output isn't correct
4 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 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -