Submission #547647

#TimeUsernameProblemLanguageResultExecution timeMemory
547647Soul234Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
100 / 100
865 ms92384 KiB
#include<bits/stdc++.h>
using namespace std;

void DBG() { cerr << "]\n"; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << h; if(sizeof...(t)) cerr << ", ";
    DBG(t...);
}
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif // LOCAL

#define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--)
#define R0F(i,a) ROF(i,0,a)
#define each(e,a) for(auto &e : (a))
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb push_back
#define tcT template<class T
#define nl "\n"

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using str = string;
tcT> using V = vector<T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;

void setIO(string NAME = "") {
    cin.tie(0)->sync_with_stdio(0);
    if(sz(NAME)) {
        freopen((NAME + ".inp").c_str(),"r",stdin);
        freopen((NAME + ".out").c_str(),"w",stdout);
    }
}

tcT> bool ckmax(T&a, const T&b) {
    return b > a ? a = b, 1 : 0;
}

tcT, int SZ> using AR = array<T, SZ>;
const int MX = 1e6+5;
int N, M, A[MX], ft[MX], ans[MX];
V<AR<int,3>> q[MX];

void upd(int p, int val) {
    for(;p; p-=p&-p) ckmax(ft[p], val);
}

int query(int p) {
    int res = 0;
    for(;p<=N;p+=p&-p) ckmax(res, ft[p]);
    return res;
}

void solve() {
    cin>>N>>M;
    A[0] = INT_MAX;
    FOR(i,1,N+1) cin>>A[i];
    F0R(i,M) {
        int l, r, k; cin>>l>>r>>k;
        q[r].pb({l,k,i});
    }
    stack<int> st; st.push(0);
    FOR(i,1,N+1) {
        while(A[st.top()] <= A[i]) st.pop();
        if(st.top()) upd(st.top(), A[i] + A[st.top()]);
        F0R(j,sz(q[i])) ans[q[i][j][2]] = query(q[i][j][0]) <= q[i][j][1];
        st.push(i);
    }
    F0R(i,M) cout << ans[i] << nl;
}

int main() {
    setIO();

    int t=1;
    //cin>>t;
    while(t-->0) {
        solve();
    }

    return 0;
}

Compilation message (stderr)

sortbooks.cpp: In function 'void setIO(std::string)':
sortbooks.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen((NAME + ".inp").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen((NAME + ".out").c_str(),"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...