#include "bits/stdc++.h"
#pragma optimize ("Bismillahirrahmanirrahim")
#pragma GCC optimize ("O3")
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define endl "\n"
//#define int long long
#define double long double
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define what_is(x) cerr << #x << " is " << x << endl;
#define m (l+r)/2
constexpr int N=1000005;
constexpr int MOD=1000000007;
//constexpr int INF2 = LLONG_MAX;
//constexpr int INF=(int)1e18;
constexpr int LOG=30;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
typedef priority_queue<pii,vector<pii>,greater<pii>> min_pq;
typedef priority_queue<pii> max_pq;
typedef long long ll;
//to think//
/*
* graph approach
* dp
* dividing the problem to smaller statements
* finding the real constraint
* sqrt decomposition
* greedy approach
* pigeonhole principle
* rewriting the problem/equality
* bitwise approaches
* binary search if monotonic
* divide and conquer
* combinatorics
* inclusion - exclusion
* think like bfs
*/
inline int in()
{
int x;cin >> x;
return x;
}
inline string in2()
{
string x;cin >> x;
return x;
}
vector<int> seg[4*N];
int ans[4*N];
int ar[N];
int n,q;
int maxi=0;
vector<int> xd;
inline void build(int rt,int l,int r)
{
if(l==r) {seg[rt].pb(ar[l]);return;}
build(rt*2,l,m);build(rt*2+1,m+1,r);
ans[rt]=max(ans[rt*2],ans[rt*2+1]);
int it=lower_bound(all(seg[rt*2+1]),seg[rt*2].back())-seg[rt*2+1].begin();
if(it) ans[rt]=max(seg[rt*2].back()+seg[rt*2+1][it-1],ans[rt]);
int n1=sz(seg[rt*2]),m1=sz(seg[rt*2+1]);
int p1=0,p2=0;
while(p1<n1 && p2<m1)
{
if(seg[rt*2][p1]<=seg[rt*2+1][p2]) seg[rt].pb(seg[rt*2][p1++]);
else seg[rt].pb(seg[rt*2+1][p2++]);
}
while(p1<n1) seg[rt].pb(seg[rt*2][p1++]);
while(p2<m1) seg[rt].pb(seg[rt*2+1][p2++]);
}
inline void query(int rt,int l,int r,int gl,int gr)
{
if(r<gl || l>gr || l>r) return;
if(l>=gl && r<=gr)
{
maxi=max(maxi,ans[rt]);
xd.pb(rt);
return;
}
query(rt*2,l,m,gl,gr);query(rt*2+1,m+1,r,gl,gr);
}
inline void solve()
{
n=in(),q=in();
for(int i=1;i<=n;i++) ar[i]=in();
build(1,1,n);
while(q--)
{
maxi=0;
xd.clear();
int l=in(),r=in(),zo=in();
query(1,1,n,l,r);
int hm=0;
for(int i=0;i<sz(xd)-1;i++)
{
hm=max(hm,seg[xd[i]].back());
int it=lower_bound(all(seg[xd[i+1]]),hm)-seg[xd[i+1]].begin();
if(it) maxi=max(hm+seg[xd[i+1]][it-1],maxi);
}
if(maxi<=zo) cout << 1 << endl;
else cout << 0 << endl;
}
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
cout << fixed << setprecision(15);
int t=1;//cin>> t;
for(int i=1;i<=t;i++)
{
// cout << "Case #" << i << ": ";
solve();
}
return 0;
}
Compilation message
sortbooks.cpp:2: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
2 | #pragma optimize ("Bismillahirrahmanirrahim")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
94244 KB |
Output is correct |
2 |
Correct |
46 ms |
94144 KB |
Output is correct |
3 |
Correct |
46 ms |
94280 KB |
Output is correct |
4 |
Correct |
45 ms |
94156 KB |
Output is correct |
5 |
Correct |
51 ms |
94232 KB |
Output is correct |
6 |
Correct |
45 ms |
94268 KB |
Output is correct |
7 |
Correct |
46 ms |
94284 KB |
Output is correct |
8 |
Correct |
45 ms |
94296 KB |
Output is correct |
9 |
Correct |
46 ms |
94272 KB |
Output is correct |
10 |
Correct |
45 ms |
94244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
94244 KB |
Output is correct |
2 |
Correct |
46 ms |
94144 KB |
Output is correct |
3 |
Correct |
46 ms |
94280 KB |
Output is correct |
4 |
Correct |
45 ms |
94156 KB |
Output is correct |
5 |
Correct |
51 ms |
94232 KB |
Output is correct |
6 |
Correct |
45 ms |
94268 KB |
Output is correct |
7 |
Correct |
46 ms |
94284 KB |
Output is correct |
8 |
Correct |
45 ms |
94296 KB |
Output is correct |
9 |
Correct |
46 ms |
94272 KB |
Output is correct |
10 |
Correct |
45 ms |
94244 KB |
Output is correct |
11 |
Correct |
45 ms |
94464 KB |
Output is correct |
12 |
Correct |
49 ms |
94984 KB |
Output is correct |
13 |
Correct |
48 ms |
95052 KB |
Output is correct |
14 |
Correct |
57 ms |
95000 KB |
Output is correct |
15 |
Correct |
50 ms |
95092 KB |
Output is correct |
16 |
Correct |
51 ms |
95076 KB |
Output is correct |
17 |
Correct |
47 ms |
94728 KB |
Output is correct |
18 |
Correct |
48 ms |
94968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2965 ms |
237964 KB |
Output is correct |
2 |
Correct |
2953 ms |
237892 KB |
Output is correct |
3 |
Correct |
2902 ms |
237836 KB |
Output is correct |
4 |
Correct |
2936 ms |
237968 KB |
Output is correct |
5 |
Correct |
2698 ms |
237964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
195 ms |
109092 KB |
Output is correct |
2 |
Correct |
175 ms |
109020 KB |
Output is correct |
3 |
Correct |
196 ms |
109016 KB |
Output is correct |
4 |
Correct |
175 ms |
108980 KB |
Output is correct |
5 |
Correct |
203 ms |
108984 KB |
Output is correct |
6 |
Correct |
197 ms |
109048 KB |
Output is correct |
7 |
Correct |
152 ms |
108988 KB |
Output is correct |
8 |
Correct |
212 ms |
109052 KB |
Output is correct |
9 |
Correct |
81 ms |
94980 KB |
Output is correct |
10 |
Correct |
158 ms |
109024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
94244 KB |
Output is correct |
2 |
Correct |
46 ms |
94144 KB |
Output is correct |
3 |
Correct |
46 ms |
94280 KB |
Output is correct |
4 |
Correct |
45 ms |
94156 KB |
Output is correct |
5 |
Correct |
51 ms |
94232 KB |
Output is correct |
6 |
Correct |
45 ms |
94268 KB |
Output is correct |
7 |
Correct |
46 ms |
94284 KB |
Output is correct |
8 |
Correct |
45 ms |
94296 KB |
Output is correct |
9 |
Correct |
46 ms |
94272 KB |
Output is correct |
10 |
Correct |
45 ms |
94244 KB |
Output is correct |
11 |
Correct |
45 ms |
94464 KB |
Output is correct |
12 |
Correct |
49 ms |
94984 KB |
Output is correct |
13 |
Correct |
48 ms |
95052 KB |
Output is correct |
14 |
Correct |
57 ms |
95000 KB |
Output is correct |
15 |
Correct |
50 ms |
95092 KB |
Output is correct |
16 |
Correct |
51 ms |
95076 KB |
Output is correct |
17 |
Correct |
47 ms |
94728 KB |
Output is correct |
18 |
Correct |
48 ms |
94968 KB |
Output is correct |
19 |
Correct |
422 ms |
124084 KB |
Output is correct |
20 |
Correct |
463 ms |
124124 KB |
Output is correct |
21 |
Correct |
372 ms |
124112 KB |
Output is correct |
22 |
Correct |
362 ms |
124188 KB |
Output is correct |
23 |
Correct |
338 ms |
124096 KB |
Output is correct |
24 |
Correct |
309 ms |
124088 KB |
Output is correct |
25 |
Correct |
306 ms |
124096 KB |
Output is correct |
26 |
Correct |
420 ms |
124188 KB |
Output is correct |
27 |
Correct |
427 ms |
124216 KB |
Output is correct |
28 |
Correct |
412 ms |
124160 KB |
Output is correct |
29 |
Correct |
450 ms |
124188 KB |
Output is correct |
30 |
Correct |
414 ms |
124172 KB |
Output is correct |
31 |
Correct |
448 ms |
124180 KB |
Output is correct |
32 |
Correct |
404 ms |
124112 KB |
Output is correct |
33 |
Correct |
400 ms |
124112 KB |
Output is correct |
34 |
Correct |
293 ms |
124180 KB |
Output is correct |
35 |
Correct |
305 ms |
124256 KB |
Output is correct |
36 |
Correct |
318 ms |
124180 KB |
Output is correct |
37 |
Correct |
297 ms |
124180 KB |
Output is correct |
38 |
Correct |
299 ms |
124080 KB |
Output is correct |
39 |
Correct |
331 ms |
124096 KB |
Output is correct |
40 |
Correct |
215 ms |
111864 KB |
Output is correct |
41 |
Correct |
324 ms |
124160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
94244 KB |
Output is correct |
2 |
Correct |
46 ms |
94144 KB |
Output is correct |
3 |
Correct |
46 ms |
94280 KB |
Output is correct |
4 |
Correct |
45 ms |
94156 KB |
Output is correct |
5 |
Correct |
51 ms |
94232 KB |
Output is correct |
6 |
Correct |
45 ms |
94268 KB |
Output is correct |
7 |
Correct |
46 ms |
94284 KB |
Output is correct |
8 |
Correct |
45 ms |
94296 KB |
Output is correct |
9 |
Correct |
46 ms |
94272 KB |
Output is correct |
10 |
Correct |
45 ms |
94244 KB |
Output is correct |
11 |
Correct |
45 ms |
94464 KB |
Output is correct |
12 |
Correct |
49 ms |
94984 KB |
Output is correct |
13 |
Correct |
48 ms |
95052 KB |
Output is correct |
14 |
Correct |
57 ms |
95000 KB |
Output is correct |
15 |
Correct |
50 ms |
95092 KB |
Output is correct |
16 |
Correct |
51 ms |
95076 KB |
Output is correct |
17 |
Correct |
47 ms |
94728 KB |
Output is correct |
18 |
Correct |
48 ms |
94968 KB |
Output is correct |
19 |
Correct |
2965 ms |
237964 KB |
Output is correct |
20 |
Correct |
2953 ms |
237892 KB |
Output is correct |
21 |
Correct |
2902 ms |
237836 KB |
Output is correct |
22 |
Correct |
2936 ms |
237968 KB |
Output is correct |
23 |
Correct |
2698 ms |
237964 KB |
Output is correct |
24 |
Correct |
195 ms |
109092 KB |
Output is correct |
25 |
Correct |
175 ms |
109020 KB |
Output is correct |
26 |
Correct |
196 ms |
109016 KB |
Output is correct |
27 |
Correct |
175 ms |
108980 KB |
Output is correct |
28 |
Correct |
203 ms |
108984 KB |
Output is correct |
29 |
Correct |
197 ms |
109048 KB |
Output is correct |
30 |
Correct |
152 ms |
108988 KB |
Output is correct |
31 |
Correct |
212 ms |
109052 KB |
Output is correct |
32 |
Correct |
81 ms |
94980 KB |
Output is correct |
33 |
Correct |
158 ms |
109024 KB |
Output is correct |
34 |
Correct |
422 ms |
124084 KB |
Output is correct |
35 |
Correct |
463 ms |
124124 KB |
Output is correct |
36 |
Correct |
372 ms |
124112 KB |
Output is correct |
37 |
Correct |
362 ms |
124188 KB |
Output is correct |
38 |
Correct |
338 ms |
124096 KB |
Output is correct |
39 |
Correct |
309 ms |
124088 KB |
Output is correct |
40 |
Correct |
306 ms |
124096 KB |
Output is correct |
41 |
Correct |
420 ms |
124188 KB |
Output is correct |
42 |
Correct |
427 ms |
124216 KB |
Output is correct |
43 |
Correct |
412 ms |
124160 KB |
Output is correct |
44 |
Correct |
450 ms |
124188 KB |
Output is correct |
45 |
Correct |
414 ms |
124172 KB |
Output is correct |
46 |
Correct |
448 ms |
124180 KB |
Output is correct |
47 |
Correct |
404 ms |
124112 KB |
Output is correct |
48 |
Correct |
400 ms |
124112 KB |
Output is correct |
49 |
Correct |
293 ms |
124180 KB |
Output is correct |
50 |
Correct |
305 ms |
124256 KB |
Output is correct |
51 |
Correct |
318 ms |
124180 KB |
Output is correct |
52 |
Correct |
297 ms |
124180 KB |
Output is correct |
53 |
Correct |
299 ms |
124080 KB |
Output is correct |
54 |
Correct |
331 ms |
124096 KB |
Output is correct |
55 |
Correct |
215 ms |
111864 KB |
Output is correct |
56 |
Correct |
324 ms |
124160 KB |
Output is correct |
57 |
Correct |
2872 ms |
238000 KB |
Output is correct |
58 |
Correct |
2870 ms |
237892 KB |
Output is correct |
59 |
Correct |
2800 ms |
237832 KB |
Output is correct |
60 |
Correct |
2861 ms |
237880 KB |
Output is correct |
61 |
Correct |
2866 ms |
237864 KB |
Output is correct |
62 |
Correct |
2802 ms |
237868 KB |
Output is correct |
63 |
Correct |
1492 ms |
237872 KB |
Output is correct |
64 |
Correct |
1481 ms |
237900 KB |
Output is correct |
65 |
Correct |
2527 ms |
237976 KB |
Output is correct |
66 |
Correct |
2498 ms |
237920 KB |
Output is correct |
67 |
Correct |
2530 ms |
237860 KB |
Output is correct |
68 |
Correct |
2645 ms |
237780 KB |
Output is correct |
69 |
Correct |
2620 ms |
237948 KB |
Output is correct |
70 |
Correct |
2701 ms |
237880 KB |
Output is correct |
71 |
Correct |
2629 ms |
237956 KB |
Output is correct |
72 |
Correct |
2886 ms |
238032 KB |
Output is correct |
73 |
Correct |
1547 ms |
237904 KB |
Output is correct |
74 |
Correct |
1491 ms |
237880 KB |
Output is correct |
75 |
Correct |
1423 ms |
238056 KB |
Output is correct |
76 |
Correct |
1424 ms |
237892 KB |
Output is correct |
77 |
Correct |
1416 ms |
237776 KB |
Output is correct |
78 |
Correct |
2156 ms |
237940 KB |
Output is correct |
79 |
Correct |
1336 ms |
167204 KB |
Output is correct |
80 |
Correct |
1986 ms |
237896 KB |
Output is correct |