#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#pragma GCC target("popcnt")
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
#define sz size()
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define pb push_back
const int mod = ll(1e9)+7; //(b + (a%b)) % b (to mod -1%(10^9+7) correctly in c++ its -1 but its suppose to be 10^9+6
const ll MOD = 998244353; // (a%mod)*(binpow(b,mod-2,mod) = (a/b)%mod
const int N = ll(1e6)+10;
const long long inf = 2e18;
const long double eps = 1e-15L;
ll lcm(ll a, ll b) { return (a / __gcd(a,b))*b; }
ll binpow(ll a, ll b, ll m) { ll res=1; a %= m; while(b>0){ if(b&1)res=(res * a) % m; a=(a * a) % m; b/=2; } return res%m;}
void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
const int B = 900;
int n, m, w[N], sta[20][N], LOG[N], mxsuf[N], pr[N];
//int ql[N], qr[N], qk[N]
int get(int l, int r) {
if(l > r) return 0;
int j = LOG[r - l + 1];
return max(sta[j][l], sta[j][r-(1<<j)+1]);
}
void Baizho() {
for(int i = 2; i < N; i ++) LOG[i] = LOG[i / 2] + 1;
cin>>n>>m;
if(n > 2e5 && m > 2e5) {
for(int i = 1; i <= n; i ++) {
cin>>w[i];
if(i > 1) {
if(w[i - 1] > w[i]) pr[i] ++;
}
pr[i] += pr[i - 1];
}
while(m --) {
int l, r, k; cin>>l>>r>>k;
if(pr[r] - pr[l] > 0) cout<<"0\n";
else cout<<"1\n";
}
return;
}
for(int i = 1; i <= n; i ++) {
cin>>w[i];
sta[0][i] = w[i];
}
for(int j = 1; j <= 19; j ++) {
for(int i = 1; i+(1<<j)-1 <= n; i ++) {
sta[j][i] = max(sta[j-1][i], sta[j-1][i+(1<<j-1)]);
}
}
for(int i = 1; i <= n; i ++) {
if(i % B == 1) {
int r = min(n, i + B - 1), mx = 0, ans = 0;
for(int j = i; j <= r; j ++) {
if(mx > w[j]) mxsuf[j] = mx + w[j];
mx = max(mx, w[j]);
}
for(int j = r - 1; j >= i; j --) mxsuf[j] = max(mxsuf[j], mxsuf[j + 1]);
}
}
// for(int i = 1; i <= n; i ++) cout<<mxsuf[i]<<" ";
// cout<<"\n";
while(m --) {
int l, r, k; cin>>l>>r>>k;
int bl = (l - 1) / B, br = (r - 1) / B;
if(bl == br) {
int mx = 0, ans = 0;
for(int i = l; i <= r; i ++) {
if(mx > w[i]) ans = max(ans, w[i] + mx);
mx = max(mx, w[i]);
}
cout<<(ans <= k)<<"\n";
continue;
}
int ans = 0, mx = 0;
for(int i = l; i <= bl * B + B; i ++) {
if(mx > w[i]) ans = max(ans, w[i] + mx);
mx = max(mx, w[i]);
}
for(int b = bl + 1; b < br; b ++) {
int pos = b * B;
for(int binl = b * B + 1, binr = b * B + B; binl <= binr; ) {
int mid = (binl + binr) / 2;
if(get(b * B + 1, mid) < mx) binl = mid + 1, pos = mid;
else binr = mid - 1;
}
if(pos >= b * B + 1) ans = max(ans, get(b * B + 1, pos) + mx);
if(pos < b * B + B) ans = max(ans, mxsuf[pos + 1]);
mx = max(mx, get(b * B + 1, b * B + B));
}
for(int i = br * B + 1; i <= r; i ++) {
if(mx > w[i]) ans = max(ans, w[i] + mx);
mx = max(mx, w[i]);
}
cout<<(ans <= k)<<"\n";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int ttt = 1;
// cin>>ttt;
for(int i=1; i<=ttt; i++) { Baizho(); }
}
Compilation message
sortbooks.cpp: In function 'void Baizho()':
sortbooks.cpp:71:49: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
71 | sta[j][i] = max(sta[j-1][i], sta[j-1][i+(1<<j-1)]);
| ~^~
sortbooks.cpp:76:39: warning: unused variable 'ans' [-Wunused-variable]
76 | int r = min(n, i + B - 1), mx = 0, ans = 0;
| ^~~
sortbooks.cpp: In function 'void Freopen(std::string)':
sortbooks.cpp:34:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:34:76: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
13148 KB |
Output is correct |
2 |
Correct |
2 ms |
7004 KB |
Output is correct |
3 |
Correct |
3 ms |
23388 KB |
Output is correct |
4 |
Correct |
4 ms |
19292 KB |
Output is correct |
5 |
Correct |
4 ms |
23388 KB |
Output is correct |
6 |
Correct |
4 ms |
25604 KB |
Output is correct |
7 |
Correct |
4 ms |
25436 KB |
Output is correct |
8 |
Correct |
4 ms |
25436 KB |
Output is correct |
9 |
Correct |
4 ms |
25432 KB |
Output is correct |
10 |
Correct |
5 ms |
25436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
13148 KB |
Output is correct |
2 |
Correct |
2 ms |
7004 KB |
Output is correct |
3 |
Correct |
3 ms |
23388 KB |
Output is correct |
4 |
Correct |
4 ms |
19292 KB |
Output is correct |
5 |
Correct |
4 ms |
23388 KB |
Output is correct |
6 |
Correct |
4 ms |
25604 KB |
Output is correct |
7 |
Correct |
4 ms |
25436 KB |
Output is correct |
8 |
Correct |
4 ms |
25436 KB |
Output is correct |
9 |
Correct |
4 ms |
25432 KB |
Output is correct |
10 |
Correct |
5 ms |
25436 KB |
Output is correct |
11 |
Correct |
6 ms |
29528 KB |
Output is correct |
12 |
Correct |
10 ms |
33624 KB |
Output is correct |
13 |
Correct |
8 ms |
33624 KB |
Output is correct |
14 |
Correct |
11 ms |
33860 KB |
Output is correct |
15 |
Correct |
10 ms |
33628 KB |
Output is correct |
16 |
Correct |
11 ms |
31792 KB |
Output is correct |
17 |
Correct |
11 ms |
31832 KB |
Output is correct |
18 |
Correct |
11 ms |
31836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
352 ms |
17176 KB |
Output is correct |
2 |
Correct |
356 ms |
16724 KB |
Output is correct |
3 |
Correct |
341 ms |
16420 KB |
Output is correct |
4 |
Correct |
343 ms |
16912 KB |
Output is correct |
5 |
Correct |
302 ms |
16812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
48200 KB |
Output is correct |
2 |
Correct |
485 ms |
48396 KB |
Output is correct |
3 |
Correct |
286 ms |
45104 KB |
Output is correct |
4 |
Correct |
256 ms |
44628 KB |
Output is correct |
5 |
Correct |
202 ms |
44532 KB |
Output is correct |
6 |
Correct |
462 ms |
44652 KB |
Output is correct |
7 |
Correct |
463 ms |
44832 KB |
Output is correct |
8 |
Correct |
394 ms |
44696 KB |
Output is correct |
9 |
Correct |
55 ms |
27740 KB |
Output is correct |
10 |
Correct |
385 ms |
46572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
13148 KB |
Output is correct |
2 |
Correct |
2 ms |
7004 KB |
Output is correct |
3 |
Correct |
3 ms |
23388 KB |
Output is correct |
4 |
Correct |
4 ms |
19292 KB |
Output is correct |
5 |
Correct |
4 ms |
23388 KB |
Output is correct |
6 |
Correct |
4 ms |
25604 KB |
Output is correct |
7 |
Correct |
4 ms |
25436 KB |
Output is correct |
8 |
Correct |
4 ms |
25436 KB |
Output is correct |
9 |
Correct |
4 ms |
25432 KB |
Output is correct |
10 |
Correct |
5 ms |
25436 KB |
Output is correct |
11 |
Correct |
6 ms |
29528 KB |
Output is correct |
12 |
Correct |
10 ms |
33624 KB |
Output is correct |
13 |
Correct |
8 ms |
33624 KB |
Output is correct |
14 |
Correct |
11 ms |
33860 KB |
Output is correct |
15 |
Correct |
10 ms |
33628 KB |
Output is correct |
16 |
Correct |
11 ms |
31792 KB |
Output is correct |
17 |
Correct |
11 ms |
31832 KB |
Output is correct |
18 |
Correct |
11 ms |
31836 KB |
Output is correct |
19 |
Correct |
715 ms |
58892 KB |
Output is correct |
20 |
Correct |
688 ms |
58964 KB |
Output is correct |
21 |
Correct |
1699 ms |
58892 KB |
Output is correct |
22 |
Correct |
1733 ms |
58728 KB |
Output is correct |
23 |
Correct |
1767 ms |
58852 KB |
Output is correct |
24 |
Correct |
1682 ms |
55600 KB |
Output is correct |
25 |
Correct |
1822 ms |
55896 KB |
Output is correct |
26 |
Correct |
1293 ms |
55496 KB |
Output is correct |
27 |
Correct |
1301 ms |
55388 KB |
Output is correct |
28 |
Correct |
1147 ms |
55524 KB |
Output is correct |
29 |
Correct |
616 ms |
55408 KB |
Output is correct |
30 |
Correct |
648 ms |
55468 KB |
Output is correct |
31 |
Correct |
691 ms |
55460 KB |
Output is correct |
32 |
Correct |
663 ms |
55852 KB |
Output is correct |
33 |
Correct |
660 ms |
55440 KB |
Output is correct |
34 |
Correct |
1614 ms |
55380 KB |
Output is correct |
35 |
Correct |
1695 ms |
55440 KB |
Output is correct |
36 |
Correct |
1665 ms |
55472 KB |
Output is correct |
37 |
Correct |
1851 ms |
55676 KB |
Output is correct |
38 |
Correct |
1664 ms |
55620 KB |
Output is correct |
39 |
Correct |
1226 ms |
57300 KB |
Output is correct |
40 |
Correct |
863 ms |
51288 KB |
Output is correct |
41 |
Correct |
1217 ms |
55544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
13148 KB |
Output is correct |
2 |
Correct |
2 ms |
7004 KB |
Output is correct |
3 |
Correct |
3 ms |
23388 KB |
Output is correct |
4 |
Correct |
4 ms |
19292 KB |
Output is correct |
5 |
Correct |
4 ms |
23388 KB |
Output is correct |
6 |
Correct |
4 ms |
25604 KB |
Output is correct |
7 |
Correct |
4 ms |
25436 KB |
Output is correct |
8 |
Correct |
4 ms |
25436 KB |
Output is correct |
9 |
Correct |
4 ms |
25432 KB |
Output is correct |
10 |
Correct |
5 ms |
25436 KB |
Output is correct |
11 |
Correct |
6 ms |
29528 KB |
Output is correct |
12 |
Correct |
10 ms |
33624 KB |
Output is correct |
13 |
Correct |
8 ms |
33624 KB |
Output is correct |
14 |
Correct |
11 ms |
33860 KB |
Output is correct |
15 |
Correct |
10 ms |
33628 KB |
Output is correct |
16 |
Correct |
11 ms |
31792 KB |
Output is correct |
17 |
Correct |
11 ms |
31832 KB |
Output is correct |
18 |
Correct |
11 ms |
31836 KB |
Output is correct |
19 |
Correct |
352 ms |
17176 KB |
Output is correct |
20 |
Correct |
356 ms |
16724 KB |
Output is correct |
21 |
Correct |
341 ms |
16420 KB |
Output is correct |
22 |
Correct |
343 ms |
16912 KB |
Output is correct |
23 |
Correct |
302 ms |
16812 KB |
Output is correct |
24 |
Correct |
219 ms |
48200 KB |
Output is correct |
25 |
Correct |
485 ms |
48396 KB |
Output is correct |
26 |
Correct |
286 ms |
45104 KB |
Output is correct |
27 |
Correct |
256 ms |
44628 KB |
Output is correct |
28 |
Correct |
202 ms |
44532 KB |
Output is correct |
29 |
Correct |
462 ms |
44652 KB |
Output is correct |
30 |
Correct |
463 ms |
44832 KB |
Output is correct |
31 |
Correct |
394 ms |
44696 KB |
Output is correct |
32 |
Correct |
55 ms |
27740 KB |
Output is correct |
33 |
Correct |
385 ms |
46572 KB |
Output is correct |
34 |
Correct |
715 ms |
58892 KB |
Output is correct |
35 |
Correct |
688 ms |
58964 KB |
Output is correct |
36 |
Correct |
1699 ms |
58892 KB |
Output is correct |
37 |
Correct |
1733 ms |
58728 KB |
Output is correct |
38 |
Correct |
1767 ms |
58852 KB |
Output is correct |
39 |
Correct |
1682 ms |
55600 KB |
Output is correct |
40 |
Correct |
1822 ms |
55896 KB |
Output is correct |
41 |
Correct |
1293 ms |
55496 KB |
Output is correct |
42 |
Correct |
1301 ms |
55388 KB |
Output is correct |
43 |
Correct |
1147 ms |
55524 KB |
Output is correct |
44 |
Correct |
616 ms |
55408 KB |
Output is correct |
45 |
Correct |
648 ms |
55468 KB |
Output is correct |
46 |
Correct |
691 ms |
55460 KB |
Output is correct |
47 |
Correct |
663 ms |
55852 KB |
Output is correct |
48 |
Correct |
660 ms |
55440 KB |
Output is correct |
49 |
Correct |
1614 ms |
55380 KB |
Output is correct |
50 |
Correct |
1695 ms |
55440 KB |
Output is correct |
51 |
Correct |
1665 ms |
55472 KB |
Output is correct |
52 |
Correct |
1851 ms |
55676 KB |
Output is correct |
53 |
Correct |
1664 ms |
55620 KB |
Output is correct |
54 |
Correct |
1226 ms |
57300 KB |
Output is correct |
55 |
Correct |
863 ms |
51288 KB |
Output is correct |
56 |
Correct |
1217 ms |
55544 KB |
Output is correct |
57 |
Incorrect |
341 ms |
16816 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |