#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) {
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]);
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 |
21 ms |
98392 KB |
Output is correct |
2 |
Correct |
21 ms |
98396 KB |
Output is correct |
3 |
Correct |
21 ms |
98496 KB |
Output is correct |
4 |
Correct |
21 ms |
98400 KB |
Output is correct |
5 |
Correct |
27 ms |
98396 KB |
Output is correct |
6 |
Correct |
24 ms |
98396 KB |
Output is correct |
7 |
Correct |
21 ms |
98396 KB |
Output is correct |
8 |
Correct |
21 ms |
98392 KB |
Output is correct |
9 |
Correct |
22 ms |
98396 KB |
Output is correct |
10 |
Correct |
22 ms |
98540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
98392 KB |
Output is correct |
2 |
Correct |
21 ms |
98396 KB |
Output is correct |
3 |
Correct |
21 ms |
98496 KB |
Output is correct |
4 |
Correct |
21 ms |
98400 KB |
Output is correct |
5 |
Correct |
27 ms |
98396 KB |
Output is correct |
6 |
Correct |
24 ms |
98396 KB |
Output is correct |
7 |
Correct |
21 ms |
98396 KB |
Output is correct |
8 |
Correct |
21 ms |
98392 KB |
Output is correct |
9 |
Correct |
22 ms |
98396 KB |
Output is correct |
10 |
Correct |
22 ms |
98540 KB |
Output is correct |
11 |
Correct |
24 ms |
98740 KB |
Output is correct |
12 |
Correct |
25 ms |
99412 KB |
Output is correct |
13 |
Correct |
27 ms |
99416 KB |
Output is correct |
14 |
Correct |
26 ms |
99672 KB |
Output is correct |
15 |
Correct |
26 ms |
99676 KB |
Output is correct |
16 |
Correct |
25 ms |
99416 KB |
Output is correct |
17 |
Correct |
24 ms |
99164 KB |
Output is correct |
18 |
Correct |
25 ms |
99416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
338 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
178 ms |
120532 KB |
Output is correct |
2 |
Correct |
158 ms |
122384 KB |
Output is correct |
3 |
Correct |
159 ms |
122612 KB |
Output is correct |
4 |
Correct |
160 ms |
122556 KB |
Output is correct |
5 |
Correct |
165 ms |
122816 KB |
Output is correct |
6 |
Correct |
120 ms |
122312 KB |
Output is correct |
7 |
Correct |
121 ms |
122276 KB |
Output is correct |
8 |
Correct |
130 ms |
122052 KB |
Output is correct |
9 |
Correct |
49 ms |
100196 KB |
Output is correct |
10 |
Correct |
132 ms |
122056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
98392 KB |
Output is correct |
2 |
Correct |
21 ms |
98396 KB |
Output is correct |
3 |
Correct |
21 ms |
98496 KB |
Output is correct |
4 |
Correct |
21 ms |
98400 KB |
Output is correct |
5 |
Correct |
27 ms |
98396 KB |
Output is correct |
6 |
Correct |
24 ms |
98396 KB |
Output is correct |
7 |
Correct |
21 ms |
98396 KB |
Output is correct |
8 |
Correct |
21 ms |
98392 KB |
Output is correct |
9 |
Correct |
22 ms |
98396 KB |
Output is correct |
10 |
Correct |
22 ms |
98540 KB |
Output is correct |
11 |
Correct |
24 ms |
98740 KB |
Output is correct |
12 |
Correct |
25 ms |
99412 KB |
Output is correct |
13 |
Correct |
27 ms |
99416 KB |
Output is correct |
14 |
Correct |
26 ms |
99672 KB |
Output is correct |
15 |
Correct |
26 ms |
99676 KB |
Output is correct |
16 |
Correct |
25 ms |
99416 KB |
Output is correct |
17 |
Correct |
24 ms |
99164 KB |
Output is correct |
18 |
Correct |
25 ms |
99416 KB |
Output is correct |
19 |
Correct |
428 ms |
150672 KB |
Output is correct |
20 |
Correct |
440 ms |
150464 KB |
Output is correct |
21 |
Correct |
310 ms |
150620 KB |
Output is correct |
22 |
Correct |
302 ms |
150496 KB |
Output is correct |
23 |
Correct |
308 ms |
150536 KB |
Output is correct |
24 |
Correct |
274 ms |
150212 KB |
Output is correct |
25 |
Correct |
255 ms |
150136 KB |
Output is correct |
26 |
Correct |
379 ms |
150352 KB |
Output is correct |
27 |
Correct |
338 ms |
150432 KB |
Output is correct |
28 |
Correct |
363 ms |
150528 KB |
Output is correct |
29 |
Correct |
381 ms |
150464 KB |
Output is correct |
30 |
Correct |
392 ms |
150436 KB |
Output is correct |
31 |
Correct |
393 ms |
150724 KB |
Output is correct |
32 |
Correct |
402 ms |
150340 KB |
Output is correct |
33 |
Correct |
393 ms |
150508 KB |
Output is correct |
34 |
Correct |
247 ms |
150148 KB |
Output is correct |
35 |
Correct |
251 ms |
150252 KB |
Output is correct |
36 |
Correct |
246 ms |
149956 KB |
Output is correct |
37 |
Correct |
246 ms |
150004 KB |
Output is correct |
38 |
Correct |
260 ms |
150376 KB |
Output is correct |
39 |
Correct |
329 ms |
149376 KB |
Output is correct |
40 |
Correct |
208 ms |
128216 KB |
Output is correct |
41 |
Correct |
310 ms |
148928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
98392 KB |
Output is correct |
2 |
Correct |
21 ms |
98396 KB |
Output is correct |
3 |
Correct |
21 ms |
98496 KB |
Output is correct |
4 |
Correct |
21 ms |
98400 KB |
Output is correct |
5 |
Correct |
27 ms |
98396 KB |
Output is correct |
6 |
Correct |
24 ms |
98396 KB |
Output is correct |
7 |
Correct |
21 ms |
98396 KB |
Output is correct |
8 |
Correct |
21 ms |
98392 KB |
Output is correct |
9 |
Correct |
22 ms |
98396 KB |
Output is correct |
10 |
Correct |
22 ms |
98540 KB |
Output is correct |
11 |
Correct |
24 ms |
98740 KB |
Output is correct |
12 |
Correct |
25 ms |
99412 KB |
Output is correct |
13 |
Correct |
27 ms |
99416 KB |
Output is correct |
14 |
Correct |
26 ms |
99672 KB |
Output is correct |
15 |
Correct |
26 ms |
99676 KB |
Output is correct |
16 |
Correct |
25 ms |
99416 KB |
Output is correct |
17 |
Correct |
24 ms |
99164 KB |
Output is correct |
18 |
Correct |
25 ms |
99416 KB |
Output is correct |
19 |
Runtime error |
338 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |