답안 #874381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
874381 2023-11-16T19:59:59 Z Macker Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
2983 ms 69712 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 + 1) <= get<2>(qry[f.second]));
        }
    }

    for (int i = 0; i < q; i++) {
        cout << ans[i] << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2983 ms 69712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 251 ms 7692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -