#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*8];
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].empty() && 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) {
ans = max(ans, res[v]);
ll pos = lower_bound(all(t[v]), mx)-t[v].begin()-1;
if(pos>-1) ans = max(ans, mx+t[v][pos]);
if(!t[v].empty()) 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); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
192348 KB |
Output is correct |
2 |
Correct |
41 ms |
192348 KB |
Output is correct |
3 |
Correct |
41 ms |
192340 KB |
Output is correct |
4 |
Correct |
41 ms |
192340 KB |
Output is correct |
5 |
Correct |
40 ms |
192348 KB |
Output is correct |
6 |
Correct |
41 ms |
192480 KB |
Output is correct |
7 |
Correct |
41 ms |
192344 KB |
Output is correct |
8 |
Correct |
41 ms |
192260 KB |
Output is correct |
9 |
Correct |
41 ms |
192348 KB |
Output is correct |
10 |
Correct |
41 ms |
192456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
192348 KB |
Output is correct |
2 |
Correct |
41 ms |
192348 KB |
Output is correct |
3 |
Correct |
41 ms |
192340 KB |
Output is correct |
4 |
Correct |
41 ms |
192340 KB |
Output is correct |
5 |
Correct |
40 ms |
192348 KB |
Output is correct |
6 |
Correct |
41 ms |
192480 KB |
Output is correct |
7 |
Correct |
41 ms |
192344 KB |
Output is correct |
8 |
Correct |
41 ms |
192260 KB |
Output is correct |
9 |
Correct |
41 ms |
192348 KB |
Output is correct |
10 |
Correct |
41 ms |
192456 KB |
Output is correct |
11 |
Correct |
43 ms |
192604 KB |
Output is correct |
12 |
Correct |
45 ms |
193372 KB |
Output is correct |
13 |
Correct |
44 ms |
193292 KB |
Output is correct |
14 |
Correct |
46 ms |
193488 KB |
Output is correct |
15 |
Correct |
47 ms |
193360 KB |
Output is correct |
16 |
Correct |
45 ms |
193372 KB |
Output is correct |
17 |
Correct |
43 ms |
192856 KB |
Output is correct |
18 |
Correct |
46 ms |
193528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
193 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
192 ms |
214408 KB |
Output is correct |
2 |
Correct |
164 ms |
214484 KB |
Output is correct |
3 |
Correct |
169 ms |
214592 KB |
Output is correct |
4 |
Correct |
173 ms |
214472 KB |
Output is correct |
5 |
Correct |
174 ms |
214480 KB |
Output is correct |
6 |
Correct |
141 ms |
214472 KB |
Output is correct |
7 |
Correct |
150 ms |
214476 KB |
Output is correct |
8 |
Correct |
155 ms |
214476 KB |
Output is correct |
9 |
Correct |
67 ms |
192660 KB |
Output is correct |
10 |
Correct |
149 ms |
214472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
192348 KB |
Output is correct |
2 |
Correct |
41 ms |
192348 KB |
Output is correct |
3 |
Correct |
41 ms |
192340 KB |
Output is correct |
4 |
Correct |
41 ms |
192340 KB |
Output is correct |
5 |
Correct |
40 ms |
192348 KB |
Output is correct |
6 |
Correct |
41 ms |
192480 KB |
Output is correct |
7 |
Correct |
41 ms |
192344 KB |
Output is correct |
8 |
Correct |
41 ms |
192260 KB |
Output is correct |
9 |
Correct |
41 ms |
192348 KB |
Output is correct |
10 |
Correct |
41 ms |
192456 KB |
Output is correct |
11 |
Correct |
43 ms |
192604 KB |
Output is correct |
12 |
Correct |
45 ms |
193372 KB |
Output is correct |
13 |
Correct |
44 ms |
193292 KB |
Output is correct |
14 |
Correct |
46 ms |
193488 KB |
Output is correct |
15 |
Correct |
47 ms |
193360 KB |
Output is correct |
16 |
Correct |
45 ms |
193372 KB |
Output is correct |
17 |
Correct |
43 ms |
192856 KB |
Output is correct |
18 |
Correct |
46 ms |
193528 KB |
Output is correct |
19 |
Correct |
469 ms |
238448 KB |
Output is correct |
20 |
Correct |
443 ms |
238356 KB |
Output is correct |
21 |
Correct |
324 ms |
238596 KB |
Output is correct |
22 |
Correct |
321 ms |
238336 KB |
Output is correct |
23 |
Correct |
320 ms |
238276 KB |
Output is correct |
24 |
Correct |
279 ms |
238280 KB |
Output is correct |
25 |
Correct |
285 ms |
238376 KB |
Output is correct |
26 |
Correct |
350 ms |
238276 KB |
Output is correct |
27 |
Correct |
353 ms |
238240 KB |
Output is correct |
28 |
Correct |
379 ms |
238276 KB |
Output is correct |
29 |
Correct |
389 ms |
238428 KB |
Output is correct |
30 |
Correct |
391 ms |
238280 KB |
Output is correct |
31 |
Correct |
402 ms |
238280 KB |
Output is correct |
32 |
Correct |
395 ms |
238280 KB |
Output is correct |
33 |
Correct |
398 ms |
238276 KB |
Output is correct |
34 |
Correct |
276 ms |
238348 KB |
Output is correct |
35 |
Correct |
270 ms |
238344 KB |
Output is correct |
36 |
Correct |
264 ms |
238344 KB |
Output is correct |
37 |
Correct |
275 ms |
238324 KB |
Output is correct |
38 |
Correct |
270 ms |
238276 KB |
Output is correct |
39 |
Correct |
343 ms |
238788 KB |
Output is correct |
40 |
Correct |
219 ms |
217800 KB |
Output is correct |
41 |
Correct |
322 ms |
238356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
192348 KB |
Output is correct |
2 |
Correct |
41 ms |
192348 KB |
Output is correct |
3 |
Correct |
41 ms |
192340 KB |
Output is correct |
4 |
Correct |
41 ms |
192340 KB |
Output is correct |
5 |
Correct |
40 ms |
192348 KB |
Output is correct |
6 |
Correct |
41 ms |
192480 KB |
Output is correct |
7 |
Correct |
41 ms |
192344 KB |
Output is correct |
8 |
Correct |
41 ms |
192260 KB |
Output is correct |
9 |
Correct |
41 ms |
192348 KB |
Output is correct |
10 |
Correct |
41 ms |
192456 KB |
Output is correct |
11 |
Correct |
43 ms |
192604 KB |
Output is correct |
12 |
Correct |
45 ms |
193372 KB |
Output is correct |
13 |
Correct |
44 ms |
193292 KB |
Output is correct |
14 |
Correct |
46 ms |
193488 KB |
Output is correct |
15 |
Correct |
47 ms |
193360 KB |
Output is correct |
16 |
Correct |
45 ms |
193372 KB |
Output is correct |
17 |
Correct |
43 ms |
192856 KB |
Output is correct |
18 |
Correct |
46 ms |
193528 KB |
Output is correct |
19 |
Runtime error |
193 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |