Submission #1119011

#TimeUsernameProblemLanguageResultExecution timeMemory
1119011luvnaHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
100 / 100
1044 ms92404 KiB
#include<bits/stdc++.h>

#define MASK(i) (1 << (i))
#define pub push_back
#define all(v) v.begin(), v.end()
#define compact(v) v.erase(unique(all(v)), end(v))
#define pii pair<int,int>
#define fi first
#define se second
#define endl "\n"
#define sz(v) (int)(v).size()
#define dbg(x) "[" #x " = " << (x) << "]"

using namespace std;

template<class T> bool minimize(T& a, T b){if(a > b) return a = b, true;return false;}
template<class T> bool maximize(T& a, T b){if(a < b) return a = b, true;return false;}

typedef long long ll;
typedef long double ld;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r){return uniform_int_distribution<ll>(l, r)(rng);}

const int N = 1e6 + 15;

struct node{
    int l, limit, id;
};

int n, q;
int a[N];
vector<node> evt[N];
int bit[N];

void update(int idx, int v){
    for(;idx; idx -= (idx & (-idx))) maximize(bit[idx], v);
}

int get(int idx){int res = 0;
    for(;idx <= n; idx += (idx & (-idx))) maximize(res, bit[idx]);
    return res;
}

int ans[N];

void solve(){
    cin >> n >> q;

    for(int i = 1; i <= n; i++) cin >> a[i];

    for(int i = 1; i <= q; i++){
        int l, r, limit; cin >> l >> r >> limit;
        evt[r].pub({l,limit,i});
    }

    stack<int> st;

    for(int r = 1; r <= n; r++){
        while(!st.empty() && a[r] >= a[st.top()]) st.pop();
        if(!st.empty()) update(st.top(), a[st.top()] + a[r]);
        st.push(r);
        for(auto &[l, limit, id] : evt[r]){
            ans[id] = (get(l) <= limit);
        }
    }

    for(int i = 1; i <= q; i++) cout << ans[i] << endl;
}

signed main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(0); cout.tie(0);

    #define task "task"

    if(fopen(task".INP", "r")){
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }

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

Compilation message (stderr)

sortbooks.cpp: In function 'void solve()':
sortbooks.cpp:63:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   63 |         for(auto &[l, limit, id] : evt[r]){
      |                   ^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         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...