Submission #497425

#TimeUsernameProblemLanguageResultExecution timeMemory
497425ZielHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
8 / 100
3080 ms29068 KiB
/**
 * LES GREATEABLES BRO TEAM
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;
#define sz(x) (int)x.size()
const bool FLAG = false;
void setIO(const string &f = "");

const int N = 1e6 + 234;
int a[N], n, q;

void solve() {
    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    	cin >> a[i];
    while (q--) {
    	int l, r, k;
    	cin >> l >> r >> k;
    	ordered_set<int> s;
    	int mx = 0;
    	for (int i = r; i >= l; i--) {
    		if (sz(s)) {
    			int it = s.order_of_key(a[i]);
    			if (it > 0)
    				mx = max(mx, a[i] + (*s.find_by_order(it - 1)));
    		}
    		s.insert(a[i]);
    	}
    	cout << bool(mx <= k) << '\n';
    }
}

signed main() {
    setIO();
    
    int tt = 1;
    if (FLAG) {
    	cin >> tt;
    }
    while (tt--) {
    	solve();
    }
    
    return 0;
}

void setIO(const string &f) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen((f + ".in").c_str(), "r")) {
        freopen((f + ".in").c_str(), "r", stdin);
        freopen((f + ".out").c_str(), "w", stdout);
    }
}

Compilation message (stderr)

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