제출 #1166362

#제출 시각아이디문제언어결과실행 시간메모리
1166362CrabCNHHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
100 / 100
486 ms84912 KiB
#include <bits/stdc++.h>

#define task   "BriantheCrab"

#define int    long long
#define pii    pair <int, int>
#define fi     first
#define se     second
#define szf    sizeof
#define sz(s)  (int)((s).size())

using namespace std;

template <class T> void mini (T &t, T f) {if (t > f) t = f;}
template <class T> void maxi (T &t, T f) {if (t < f) t = f;}

const int maxN = 1e6 + 5;
const int inf = 1e18 + 7;
const int mod = 1e9 + 7;

struct off {
    int l, c, id;
};

int n, m;
int a[maxN], res[maxN];
vector <off> q[maxN];

struct Fenwick {
    int bit[maxN];
    
    Fenwick () {
        memset (bit, 0, szf (bit));
    }
    
    void upd (int x, int v) {
        for (; x > 0; x -= x & (-x)) {
            maxi (bit[x], v);
        }
    }
    
    int getMax (int x) {
        int mx = -inf;
        for (; x <= n; x += x & (-x)) {
            maxi (mx, bit[x]);
        }
        return mx;
    }
};

Fenwick T;

void solve () {
    cin >> n >> m;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
    }
    for (int i = 1; i <= m; i ++) {
        int l, r, c;
        cin >> l >> r >> c;
        q[r].push_back ({l, c, i});
    }
    stack <int> st;
    for (int i = 1; i <= n; i ++) {
        while (!st.empty () && a[st.top ()] <= a[i]) {
            //cout << "OUT " << st.top () << '\n';
            st.pop ();
        }
        if (!st.empty ()) {
            T.upd (st.top (), a[st.top ()] + a[i]);
        }
        st.push (i);
        //cout << "IN " << st.top () << '\n';
        for (auto [l, c, id] : q[i]) {
            res[id] = (T.getMax (l) <= c);
        }
    }
    for (int i = 1; i <= m; i ++) {
        cout << res[i] << '\n';
    }
}

signed main () {
    cin.tie (nullptr) -> sync_with_stdio (false);
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    int t = 1;
    //cin >> t;
    while (t --) {
        solve ();
    } 
    return 0;
}
// thfdgb

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

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:86:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:87:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         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...