제출 #255259

#제출 시각아이디문제언어결과실행 시간메모리
255259karmaHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
100 / 100
2025 ms113364 KiB
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
//#define int         int64_t

using namespace std;

const int N = int(1e6) + 7;
const int M = N << 2;
const int inf = 2e9 + 1;
typedef pair<int, int> pii;

int l[M], h[M], st[M];
int a[N], n, m, ans[N];
vector<pair<int, pii>> ask[N];

void build(int x, int low, int high) {
    l[x] = low, h[x] = high;
    if(l[x] == h[x]) return;
    int mid = (low + high) >> 1;
    build(x << 1, low, mid);
    build(x << 1 | 1, mid + 1, high);
}

void upd(int x, int pos, int val) {
    if(l[x] > pos || h[x] < pos) return;
    if(l[x] == h[x]) {
        st[x] = max(st[x], val);
        return;
    }
    upd(x << 1, pos, val);
    upd(x << 1 | 1, pos, val);
    st[x] = max(st[x << 1], st[x << 1 | 1]);
}

int get(int x, int low, int high) {
    if(l[x] > high || h[x] < low) return 0;
    if(l[x] >= low && h[x] <= high) return st[x];
    return max(get(x << 1, low, high), get(x << 1 | 1, low, high));
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    for(int u, v, w, i = 1; i <= m; ++i) {
        cin >> u >> v >> w;
        ask[v].pb(i, pii(u, w));
    }
    build(1, 1, n);
    vector<int> st;
    for(int i = 1; i <= n; ++i) {
        while(st.size() && a[st.back()] <= a[i]) st.pop_back();
        if(st.size()) {
            upd(1, st.back(), a[st.back()] + a[i]);
        }
        st.pb(i);
        for(auto q: ask[i]) {
            //cout << q.fi << ' ' << get(1, q.se.fi, i) << '\n';
            ans[q.fi] = get(1, q.se.fi, i) <= q.se.se;
        }
    }
    for(int i = 1; i <= m; ++i) cout << ans[i] << '\n';
}

컴파일 시 표준 에러 (stderr) 메시지

sortbooks.cpp: In function 'int32_t main()':
sortbooks.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...