#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;
#define ll int
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].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); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
97340 KB |
Output is correct |
2 |
Correct |
22 ms |
97116 KB |
Output is correct |
3 |
Correct |
21 ms |
97324 KB |
Output is correct |
4 |
Correct |
22 ms |
97368 KB |
Output is correct |
5 |
Correct |
22 ms |
97368 KB |
Output is correct |
6 |
Correct |
23 ms |
97424 KB |
Output is correct |
7 |
Correct |
22 ms |
97368 KB |
Output is correct |
8 |
Correct |
22 ms |
97372 KB |
Output is correct |
9 |
Correct |
21 ms |
97396 KB |
Output is correct |
10 |
Correct |
21 ms |
97372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
97340 KB |
Output is correct |
2 |
Correct |
22 ms |
97116 KB |
Output is correct |
3 |
Correct |
21 ms |
97324 KB |
Output is correct |
4 |
Correct |
22 ms |
97368 KB |
Output is correct |
5 |
Correct |
22 ms |
97368 KB |
Output is correct |
6 |
Correct |
23 ms |
97424 KB |
Output is correct |
7 |
Correct |
22 ms |
97368 KB |
Output is correct |
8 |
Correct |
22 ms |
97372 KB |
Output is correct |
9 |
Correct |
21 ms |
97396 KB |
Output is correct |
10 |
Correct |
21 ms |
97372 KB |
Output is correct |
11 |
Correct |
23 ms |
97544 KB |
Output is correct |
12 |
Correct |
24 ms |
97884 KB |
Output is correct |
13 |
Correct |
24 ms |
97884 KB |
Output is correct |
14 |
Correct |
27 ms |
97856 KB |
Output is correct |
15 |
Correct |
27 ms |
98060 KB |
Output is correct |
16 |
Correct |
26 ms |
98068 KB |
Output is correct |
17 |
Correct |
25 ms |
97628 KB |
Output is correct |
18 |
Correct |
26 ms |
97884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2810 ms |
257304 KB |
Output is correct |
2 |
Correct |
2686 ms |
262144 KB |
Output is correct |
3 |
Correct |
2521 ms |
262144 KB |
Output is correct |
4 |
Correct |
2498 ms |
262144 KB |
Output is correct |
5 |
Correct |
2317 ms |
262144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
149 ms |
111056 KB |
Output is correct |
2 |
Correct |
143 ms |
111564 KB |
Output is correct |
3 |
Correct |
139 ms |
111056 KB |
Output is correct |
4 |
Correct |
132 ms |
111160 KB |
Output is correct |
5 |
Correct |
132 ms |
111056 KB |
Output is correct |
6 |
Correct |
122 ms |
111332 KB |
Output is correct |
7 |
Correct |
113 ms |
111204 KB |
Output is correct |
8 |
Correct |
113 ms |
111292 KB |
Output is correct |
9 |
Correct |
46 ms |
97480 KB |
Output is correct |
10 |
Correct |
112 ms |
111156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
97340 KB |
Output is correct |
2 |
Correct |
22 ms |
97116 KB |
Output is correct |
3 |
Correct |
21 ms |
97324 KB |
Output is correct |
4 |
Correct |
22 ms |
97368 KB |
Output is correct |
5 |
Correct |
22 ms |
97368 KB |
Output is correct |
6 |
Correct |
23 ms |
97424 KB |
Output is correct |
7 |
Correct |
22 ms |
97368 KB |
Output is correct |
8 |
Correct |
22 ms |
97372 KB |
Output is correct |
9 |
Correct |
21 ms |
97396 KB |
Output is correct |
10 |
Correct |
21 ms |
97372 KB |
Output is correct |
11 |
Correct |
23 ms |
97544 KB |
Output is correct |
12 |
Correct |
24 ms |
97884 KB |
Output is correct |
13 |
Correct |
24 ms |
97884 KB |
Output is correct |
14 |
Correct |
27 ms |
97856 KB |
Output is correct |
15 |
Correct |
27 ms |
98060 KB |
Output is correct |
16 |
Correct |
26 ms |
98068 KB |
Output is correct |
17 |
Correct |
25 ms |
97628 KB |
Output is correct |
18 |
Correct |
26 ms |
97884 KB |
Output is correct |
19 |
Correct |
369 ms |
125896 KB |
Output is correct |
20 |
Correct |
374 ms |
125888 KB |
Output is correct |
21 |
Correct |
316 ms |
125896 KB |
Output is correct |
22 |
Correct |
299 ms |
125940 KB |
Output is correct |
23 |
Correct |
294 ms |
125944 KB |
Output is correct |
24 |
Correct |
253 ms |
125896 KB |
Output is correct |
25 |
Correct |
252 ms |
125976 KB |
Output is correct |
26 |
Correct |
333 ms |
125896 KB |
Output is correct |
27 |
Correct |
326 ms |
125944 KB |
Output is correct |
28 |
Correct |
346 ms |
125816 KB |
Output is correct |
29 |
Correct |
381 ms |
125888 KB |
Output is correct |
30 |
Correct |
380 ms |
125888 KB |
Output is correct |
31 |
Correct |
359 ms |
125896 KB |
Output is correct |
32 |
Correct |
351 ms |
126124 KB |
Output is correct |
33 |
Correct |
362 ms |
125900 KB |
Output is correct |
34 |
Correct |
263 ms |
125880 KB |
Output is correct |
35 |
Correct |
252 ms |
125944 KB |
Output is correct |
36 |
Correct |
238 ms |
125932 KB |
Output is correct |
37 |
Correct |
238 ms |
125896 KB |
Output is correct |
38 |
Correct |
238 ms |
125948 KB |
Output is correct |
39 |
Correct |
299 ms |
125892 KB |
Output is correct |
40 |
Correct |
190 ms |
114124 KB |
Output is correct |
41 |
Correct |
265 ms |
125812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
97340 KB |
Output is correct |
2 |
Correct |
22 ms |
97116 KB |
Output is correct |
3 |
Correct |
21 ms |
97324 KB |
Output is correct |
4 |
Correct |
22 ms |
97368 KB |
Output is correct |
5 |
Correct |
22 ms |
97368 KB |
Output is correct |
6 |
Correct |
23 ms |
97424 KB |
Output is correct |
7 |
Correct |
22 ms |
97368 KB |
Output is correct |
8 |
Correct |
22 ms |
97372 KB |
Output is correct |
9 |
Correct |
21 ms |
97396 KB |
Output is correct |
10 |
Correct |
21 ms |
97372 KB |
Output is correct |
11 |
Correct |
23 ms |
97544 KB |
Output is correct |
12 |
Correct |
24 ms |
97884 KB |
Output is correct |
13 |
Correct |
24 ms |
97884 KB |
Output is correct |
14 |
Correct |
27 ms |
97856 KB |
Output is correct |
15 |
Correct |
27 ms |
98060 KB |
Output is correct |
16 |
Correct |
26 ms |
98068 KB |
Output is correct |
17 |
Correct |
25 ms |
97628 KB |
Output is correct |
18 |
Correct |
26 ms |
97884 KB |
Output is correct |
19 |
Correct |
2810 ms |
257304 KB |
Output is correct |
20 |
Correct |
2686 ms |
262144 KB |
Output is correct |
21 |
Correct |
2521 ms |
262144 KB |
Output is correct |
22 |
Correct |
2498 ms |
262144 KB |
Output is correct |
23 |
Correct |
2317 ms |
262144 KB |
Output is correct |
24 |
Correct |
149 ms |
111056 KB |
Output is correct |
25 |
Correct |
143 ms |
111564 KB |
Output is correct |
26 |
Correct |
139 ms |
111056 KB |
Output is correct |
27 |
Correct |
132 ms |
111160 KB |
Output is correct |
28 |
Correct |
132 ms |
111056 KB |
Output is correct |
29 |
Correct |
122 ms |
111332 KB |
Output is correct |
30 |
Correct |
113 ms |
111204 KB |
Output is correct |
31 |
Correct |
113 ms |
111292 KB |
Output is correct |
32 |
Correct |
46 ms |
97480 KB |
Output is correct |
33 |
Correct |
112 ms |
111156 KB |
Output is correct |
34 |
Correct |
369 ms |
125896 KB |
Output is correct |
35 |
Correct |
374 ms |
125888 KB |
Output is correct |
36 |
Correct |
316 ms |
125896 KB |
Output is correct |
37 |
Correct |
299 ms |
125940 KB |
Output is correct |
38 |
Correct |
294 ms |
125944 KB |
Output is correct |
39 |
Correct |
253 ms |
125896 KB |
Output is correct |
40 |
Correct |
252 ms |
125976 KB |
Output is correct |
41 |
Correct |
333 ms |
125896 KB |
Output is correct |
42 |
Correct |
326 ms |
125944 KB |
Output is correct |
43 |
Correct |
346 ms |
125816 KB |
Output is correct |
44 |
Correct |
381 ms |
125888 KB |
Output is correct |
45 |
Correct |
380 ms |
125888 KB |
Output is correct |
46 |
Correct |
359 ms |
125896 KB |
Output is correct |
47 |
Correct |
351 ms |
126124 KB |
Output is correct |
48 |
Correct |
362 ms |
125900 KB |
Output is correct |
49 |
Correct |
263 ms |
125880 KB |
Output is correct |
50 |
Correct |
252 ms |
125944 KB |
Output is correct |
51 |
Correct |
238 ms |
125932 KB |
Output is correct |
52 |
Correct |
238 ms |
125896 KB |
Output is correct |
53 |
Correct |
238 ms |
125948 KB |
Output is correct |
54 |
Correct |
299 ms |
125892 KB |
Output is correct |
55 |
Correct |
190 ms |
114124 KB |
Output is correct |
56 |
Correct |
265 ms |
125812 KB |
Output is correct |
57 |
Correct |
2463 ms |
262144 KB |
Output is correct |
58 |
Correct |
2491 ms |
262144 KB |
Output is correct |
59 |
Correct |
2385 ms |
262144 KB |
Output is correct |
60 |
Correct |
2389 ms |
262144 KB |
Output is correct |
61 |
Correct |
2434 ms |
262144 KB |
Output is correct |
62 |
Correct |
2401 ms |
262144 KB |
Output is correct |
63 |
Correct |
1245 ms |
262144 KB |
Output is correct |
64 |
Correct |
1237 ms |
262144 KB |
Output is correct |
65 |
Correct |
2157 ms |
262144 KB |
Output is correct |
66 |
Correct |
2143 ms |
262144 KB |
Output is correct |
67 |
Correct |
2126 ms |
262144 KB |
Output is correct |
68 |
Correct |
2272 ms |
262144 KB |
Output is correct |
69 |
Correct |
2301 ms |
262144 KB |
Output is correct |
70 |
Correct |
2292 ms |
262144 KB |
Output is correct |
71 |
Correct |
2329 ms |
262144 KB |
Output is correct |
72 |
Correct |
2338 ms |
262144 KB |
Output is correct |
73 |
Correct |
1234 ms |
262144 KB |
Output is correct |
74 |
Correct |
1206 ms |
262144 KB |
Output is correct |
75 |
Correct |
1211 ms |
262144 KB |
Output is correct |
76 |
Correct |
1192 ms |
262144 KB |
Output is correct |
77 |
Correct |
1209 ms |
262144 KB |
Output is correct |
78 |
Correct |
1872 ms |
262144 KB |
Output is correct |
79 |
Correct |
1142 ms |
192792 KB |
Output is correct |
80 |
Correct |
1772 ms |
262144 KB |
Output is correct |