Submission #874380

# Submission time Handle Problem Language Result Execution time Memory
874380 2023-11-16T19:56:53 Z Macker Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
3000 ms 102576 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;
    vector<int> v(n);
    for (auto& i : v) {
        cin >> i;
    }
    while (len < n) len *= 2;
    st.resize(2 * len, INT_MIN);
    vector<bool> ans(q);
    vector<tuple<int, int, int>> qry;
    vector<vector<pair<int, int>>> ls(n+1);
    for (int i = 0; i < q; i++) {
        int f, t, k; cin >> f >> t >> k;
        qry.push_back({ f, t, k });
        ls[t].push_back({ f, i });
    }

    stack<pair<int, int>> s;
    s.push({ INT_MAX, 0 });
    for (int i = 0; i < n; i++) {
        while (v[i] >= s.top().first) s.pop();
        upd(s.top().second, s.top().first + v[i]);
        s.push({ v[i], i + 1});

        for (auto& f : ls[i]) {
            ans[f.second] = (query(f.first, i) <= get<2>(qry[f.second]));
        }
    }

    for (int i = 0; i < q; i++) {
        cout << ans[i] << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2894 ms 86944 KB Output is correct
2 Correct 2959 ms 102540 KB Output is correct
3 Execution timed out 3033 ms 102576 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 236 ms 8828 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 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -