Submission #874371

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

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

vector<int> st;
int len = 1;

int query(int f, int t, int i = 1, int s = 0, int e = len) {
    if (f >= e || t <= s) return  { INT_MIN };
    if (f <= s && e <= t) return st[i];
    return max(query(f, t, i * 2, s, (s + e) / 2), query(f, t, i * 2 + 1, (s + e) / 2, e));
}

void upd(int idx, int val, int i = 1, int s = 0, int e = len) {
    if (idx >= e || idx < s) return;
    if (idx == s && s + 1 == e) {
        st[i] = max(st[i], val); 
        return;
    }
    upd(idx, val, i * 2, s, (s + e) / 2);
    upd(idx, val, i * 2 + 1, (s + e) / 2, e);
    st[i] = max(st[i * 2], st[i * 2 + 1]);
}

int main()
{
    int n, q; cin >> n >> q;
    while (len < n) len *= 2;
    st.resize(2 * len, INT_MIN);
    stack<pair<int, int>> s;
    s.push({ INT_MAX, 0 });
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        while (a >= s.top().first) s.pop();
        upd(s.top().second, s.top().first + a);
        s.push({ a, i + 1 });
    }

    while (q--) {
        int f, t, k; cin >> f >> t >> k;
        cout << (query(f, t + 1) <= k ? 1 : 0) << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 344 KB Output is correct
2 Correct 0 ms 344 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 2662 ms 27056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 227 ms 2900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -