#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;
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++]);
}
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);
}
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")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
94208 KB |
Output is correct |
2 |
Correct |
42 ms |
94176 KB |
Output is correct |
3 |
Correct |
40 ms |
94272 KB |
Output is correct |
4 |
Correct |
41 ms |
94132 KB |
Output is correct |
5 |
Correct |
41 ms |
94292 KB |
Output is correct |
6 |
Correct |
43 ms |
94240 KB |
Output is correct |
7 |
Correct |
44 ms |
94292 KB |
Output is correct |
8 |
Correct |
47 ms |
94264 KB |
Output is correct |
9 |
Correct |
42 ms |
94156 KB |
Output is correct |
10 |
Correct |
41 ms |
94228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
94208 KB |
Output is correct |
2 |
Correct |
42 ms |
94176 KB |
Output is correct |
3 |
Correct |
40 ms |
94272 KB |
Output is correct |
4 |
Correct |
41 ms |
94132 KB |
Output is correct |
5 |
Correct |
41 ms |
94292 KB |
Output is correct |
6 |
Correct |
43 ms |
94240 KB |
Output is correct |
7 |
Correct |
44 ms |
94292 KB |
Output is correct |
8 |
Correct |
47 ms |
94264 KB |
Output is correct |
9 |
Correct |
42 ms |
94156 KB |
Output is correct |
10 |
Correct |
41 ms |
94228 KB |
Output is correct |
11 |
Correct |
43 ms |
94420 KB |
Output is correct |
12 |
Correct |
44 ms |
94936 KB |
Output is correct |
13 |
Correct |
46 ms |
94996 KB |
Output is correct |
14 |
Correct |
47 ms |
94924 KB |
Output is correct |
15 |
Correct |
47 ms |
94968 KB |
Output is correct |
16 |
Correct |
54 ms |
94960 KB |
Output is correct |
17 |
Correct |
45 ms |
94712 KB |
Output is correct |
18 |
Correct |
45 ms |
94964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2895 ms |
237888 KB |
Output is correct |
2 |
Correct |
2843 ms |
237764 KB |
Output is correct |
3 |
Correct |
2897 ms |
237824 KB |
Output is correct |
4 |
Correct |
2825 ms |
237844 KB |
Output is correct |
5 |
Correct |
2666 ms |
238068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
191 ms |
108676 KB |
Output is correct |
2 |
Correct |
176 ms |
108564 KB |
Output is correct |
3 |
Correct |
176 ms |
108584 KB |
Output is correct |
4 |
Correct |
174 ms |
108564 KB |
Output is correct |
5 |
Correct |
167 ms |
108516 KB |
Output is correct |
6 |
Correct |
147 ms |
108580 KB |
Output is correct |
7 |
Correct |
146 ms |
108572 KB |
Output is correct |
8 |
Correct |
144 ms |
108676 KB |
Output is correct |
9 |
Correct |
73 ms |
94384 KB |
Output is correct |
10 |
Correct |
142 ms |
108516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
94208 KB |
Output is correct |
2 |
Correct |
42 ms |
94176 KB |
Output is correct |
3 |
Correct |
40 ms |
94272 KB |
Output is correct |
4 |
Correct |
41 ms |
94132 KB |
Output is correct |
5 |
Correct |
41 ms |
94292 KB |
Output is correct |
6 |
Correct |
43 ms |
94240 KB |
Output is correct |
7 |
Correct |
44 ms |
94292 KB |
Output is correct |
8 |
Correct |
47 ms |
94264 KB |
Output is correct |
9 |
Correct |
42 ms |
94156 KB |
Output is correct |
10 |
Correct |
41 ms |
94228 KB |
Output is correct |
11 |
Correct |
43 ms |
94420 KB |
Output is correct |
12 |
Correct |
44 ms |
94936 KB |
Output is correct |
13 |
Correct |
46 ms |
94996 KB |
Output is correct |
14 |
Correct |
47 ms |
94924 KB |
Output is correct |
15 |
Correct |
47 ms |
94968 KB |
Output is correct |
16 |
Correct |
54 ms |
94960 KB |
Output is correct |
17 |
Correct |
45 ms |
94712 KB |
Output is correct |
18 |
Correct |
45 ms |
94964 KB |
Output is correct |
19 |
Correct |
486 ms |
123676 KB |
Output is correct |
20 |
Correct |
423 ms |
123656 KB |
Output is correct |
21 |
Correct |
339 ms |
123648 KB |
Output is correct |
22 |
Correct |
371 ms |
123676 KB |
Output is correct |
23 |
Correct |
346 ms |
123672 KB |
Output is correct |
24 |
Correct |
295 ms |
123620 KB |
Output is correct |
25 |
Correct |
297 ms |
123584 KB |
Output is correct |
26 |
Correct |
351 ms |
123584 KB |
Output is correct |
27 |
Correct |
341 ms |
123660 KB |
Output is correct |
28 |
Correct |
371 ms |
123728 KB |
Output is correct |
29 |
Correct |
406 ms |
123668 KB |
Output is correct |
30 |
Correct |
385 ms |
123556 KB |
Output is correct |
31 |
Correct |
386 ms |
123620 KB |
Output is correct |
32 |
Correct |
390 ms |
123608 KB |
Output is correct |
33 |
Correct |
410 ms |
123624 KB |
Output is correct |
34 |
Correct |
282 ms |
123660 KB |
Output is correct |
35 |
Correct |
280 ms |
123612 KB |
Output is correct |
36 |
Correct |
288 ms |
123572 KB |
Output is correct |
37 |
Correct |
284 ms |
123588 KB |
Output is correct |
38 |
Correct |
284 ms |
123780 KB |
Output is correct |
39 |
Correct |
328 ms |
123560 KB |
Output is correct |
40 |
Correct |
259 ms |
111244 KB |
Output is correct |
41 |
Correct |
306 ms |
123600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
94208 KB |
Output is correct |
2 |
Correct |
42 ms |
94176 KB |
Output is correct |
3 |
Correct |
40 ms |
94272 KB |
Output is correct |
4 |
Correct |
41 ms |
94132 KB |
Output is correct |
5 |
Correct |
41 ms |
94292 KB |
Output is correct |
6 |
Correct |
43 ms |
94240 KB |
Output is correct |
7 |
Correct |
44 ms |
94292 KB |
Output is correct |
8 |
Correct |
47 ms |
94264 KB |
Output is correct |
9 |
Correct |
42 ms |
94156 KB |
Output is correct |
10 |
Correct |
41 ms |
94228 KB |
Output is correct |
11 |
Correct |
43 ms |
94420 KB |
Output is correct |
12 |
Correct |
44 ms |
94936 KB |
Output is correct |
13 |
Correct |
46 ms |
94996 KB |
Output is correct |
14 |
Correct |
47 ms |
94924 KB |
Output is correct |
15 |
Correct |
47 ms |
94968 KB |
Output is correct |
16 |
Correct |
54 ms |
94960 KB |
Output is correct |
17 |
Correct |
45 ms |
94712 KB |
Output is correct |
18 |
Correct |
45 ms |
94964 KB |
Output is correct |
19 |
Correct |
2895 ms |
237888 KB |
Output is correct |
20 |
Correct |
2843 ms |
237764 KB |
Output is correct |
21 |
Correct |
2897 ms |
237824 KB |
Output is correct |
22 |
Correct |
2825 ms |
237844 KB |
Output is correct |
23 |
Correct |
2666 ms |
238068 KB |
Output is correct |
24 |
Correct |
191 ms |
108676 KB |
Output is correct |
25 |
Correct |
176 ms |
108564 KB |
Output is correct |
26 |
Correct |
176 ms |
108584 KB |
Output is correct |
27 |
Correct |
174 ms |
108564 KB |
Output is correct |
28 |
Correct |
167 ms |
108516 KB |
Output is correct |
29 |
Correct |
147 ms |
108580 KB |
Output is correct |
30 |
Correct |
146 ms |
108572 KB |
Output is correct |
31 |
Correct |
144 ms |
108676 KB |
Output is correct |
32 |
Correct |
73 ms |
94384 KB |
Output is correct |
33 |
Correct |
142 ms |
108516 KB |
Output is correct |
34 |
Correct |
486 ms |
123676 KB |
Output is correct |
35 |
Correct |
423 ms |
123656 KB |
Output is correct |
36 |
Correct |
339 ms |
123648 KB |
Output is correct |
37 |
Correct |
371 ms |
123676 KB |
Output is correct |
38 |
Correct |
346 ms |
123672 KB |
Output is correct |
39 |
Correct |
295 ms |
123620 KB |
Output is correct |
40 |
Correct |
297 ms |
123584 KB |
Output is correct |
41 |
Correct |
351 ms |
123584 KB |
Output is correct |
42 |
Correct |
341 ms |
123660 KB |
Output is correct |
43 |
Correct |
371 ms |
123728 KB |
Output is correct |
44 |
Correct |
406 ms |
123668 KB |
Output is correct |
45 |
Correct |
385 ms |
123556 KB |
Output is correct |
46 |
Correct |
386 ms |
123620 KB |
Output is correct |
47 |
Correct |
390 ms |
123608 KB |
Output is correct |
48 |
Correct |
410 ms |
123624 KB |
Output is correct |
49 |
Correct |
282 ms |
123660 KB |
Output is correct |
50 |
Correct |
280 ms |
123612 KB |
Output is correct |
51 |
Correct |
288 ms |
123572 KB |
Output is correct |
52 |
Correct |
284 ms |
123588 KB |
Output is correct |
53 |
Correct |
284 ms |
123780 KB |
Output is correct |
54 |
Correct |
328 ms |
123560 KB |
Output is correct |
55 |
Correct |
259 ms |
111244 KB |
Output is correct |
56 |
Correct |
306 ms |
123600 KB |
Output is correct |
57 |
Correct |
2823 ms |
237804 KB |
Output is correct |
58 |
Correct |
2890 ms |
237992 KB |
Output is correct |
59 |
Correct |
2868 ms |
237916 KB |
Output is correct |
60 |
Correct |
2970 ms |
237908 KB |
Output is correct |
61 |
Correct |
2835 ms |
237864 KB |
Output is correct |
62 |
Correct |
2770 ms |
237904 KB |
Output is correct |
63 |
Correct |
1439 ms |
237788 KB |
Output is correct |
64 |
Correct |
1467 ms |
237860 KB |
Output is correct |
65 |
Correct |
2482 ms |
237904 KB |
Output is correct |
66 |
Correct |
2491 ms |
237820 KB |
Output is correct |
67 |
Correct |
2670 ms |
237972 KB |
Output is correct |
68 |
Execution timed out |
3045 ms |
237848 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |