#include "bits/stdc++.h"
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using ll = long long;
using ld = long double;
#define pb push_back
#define ff first
#define ss second
#define sz(x) (ll)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
void IOIGold2024_InshAllah() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
ll binmul(ll a, ll b, ll c) { ll res = 0; while(b) { if(b&1) (res += a) %= c; (a += a) %= c; b >>= 1; } return res; }
ll binpow(ll a, ll b, ll c) { ll res = 1; while(b) { if(b&1) (res *= a) %= c; (a *= a) %= c; b >>= 1; } return res; }
template<typename T> T gcd(T a, T b) { if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b) { return a/gcd(a, b)*b; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ld rnd() { return rng()%INT_MAX*1.0/INT_MAX; }
const ll inf = 1e18+7, MX = LLONG_MAX, MN = LLONG_MIN;
const ll mod = 1e9+7, N = 1e6+5;
vector<ll> t[N*4];
ll a[N], res[N*4], ans, mx;
void build(ll v, ll tl, ll tr) {
if(tl==tr) {
t[v].pb(a[tl]);
return;
}
ll tm = (tl+tr)/2;
build(v*2, tl, tm), build(v*2+1, tm+1, tr);
ll i = 0, j = 0;
res[v] = max(res[v*2], res[v*2+1]);
while(i<sz(t[v*2]) || j<sz(t[v*2+1])) {
if(j==sz(t[v*2+1]) || (i<sz(t[v*2]) && t[v*2][i]<t[v*2+1][j])) t[v].pb(t[v*2][i++]);
else {
if(t[v*2+1][j]<t[v*2].back()) res[v] = max(res[v], t[v*2+1][j]+t[v*2].back());
t[v].pb(t[v*2+1][j++]);
}
}
}
void get(ll v, ll tl, ll tr, ll l, ll r) {
if(r<tl || tr<l || r<l) return;
if(l<=tl && tr<=r) {
ll pos = lower_bound(all(t[v]), mx)-t[v].begin()-1;
if(pos>-1) ans = max(ans, mx+t[v][pos]);
mx = max(mx, t[v].back());
return;
}
ll tm = (tl+tr)/2;
get(v*2, tl, tm, l, r), get(v*2+1, tm+1, tr, l, r);
}
void kigash() {
ll n, q;
cin>>n>>q;
for(ll i=1; i<=n; i++) cin>>a[i];
build(1, 1, n);
while(q--) {
ll l, r, k;
cin>>l>>r>>k;
mx = ans = 0;
get(1, 1, n, l, r);
if(ans>k) cout<<"0\n";
else cout<<"1\n";
}
return;
}
signed main(/*Kigash Amir*/) {
// freopen("");
IOIGold2024_InshAllah();
ll tt = 1;
// cin>>tt;
for(ll i=1; i<=tt; i++) {
kigash();
}
}
Compilation message
sortbooks.cpp:4: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
4 | #pragma comment(linker, "/stack:200000000")
|
sortbooks.cpp: In function 'void freopen(std::string)':
sortbooks.cpp:17:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:17:73: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
98452 KB |
Output is correct |
2 |
Correct |
22 ms |
98604 KB |
Output is correct |
3 |
Incorrect |
21 ms |
98392 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
98452 KB |
Output is correct |
2 |
Correct |
22 ms |
98604 KB |
Output is correct |
3 |
Incorrect |
21 ms |
98392 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
345 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
175 ms |
120524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
98452 KB |
Output is correct |
2 |
Correct |
22 ms |
98604 KB |
Output is correct |
3 |
Incorrect |
21 ms |
98392 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
98452 KB |
Output is correct |
2 |
Correct |
22 ms |
98604 KB |
Output is correct |
3 |
Incorrect |
21 ms |
98392 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |