#include<bits/stdc++.h>
using namespace std;
#pragma gcc optimize("ofast")
#define nn '\n'
#define ll long long
#define pb emplace_back
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ff first
#define ss second
const ll maxn = 1000005;
const ll maxm = 1000005;
const ll mod = 100000000000000007;
const ll inf = mod*2;
struct BIT{
int arr[maxn];
int n;
BIT(int k){
n = k;
for(int i=1;i<=n;i++) arr[i] = 0;
}
void modify(int x, int pos){
for(int i=pos;i<=n;i+=i&-i) arr[i] = max(arr[i],x);
}
int query(int pos){
int res = 0;
for(int i=pos;i>0;i-=i&-i) res = max(res,arr[i]);
return res;
}
};
struct query{
int r, x, pos;
query(int a, int b, int c):r(a),x(b),pos(c){}
};
int main(){
int n, q;
int arr[maxn];
vector<query> que[maxn];
int ans[maxn];
int a, b, c;
vector<pii> mod[maxn];
cin >> n >> q;
for(int i=1;i<=n;i++) cin >> arr[i];
for(int i=1;i<=q;i++){
cin >> a >> b >> c;
que[a].pb(query(b,c,i));
}
vector<int> stk;
for(int i=1;i<=n;i++){
while(stk.size() && arr[stk.back()]<=arr[i]) stk.pop_back();
if(stk.size()) mod[stk.back()].pb(make_pair(i,arr[i]+arr[stk.back()]));
stk.pb(i);
}
BIT bit(n);
for(int i=n;i>0;i--){
for(auto k:mod[i]) bit.modify(k.ss,k.ff);
for(auto k:que[i]) ans[k.pos] = bit.query(k.r)<=k.x;
}
for(int i=1;i<=q;i++) cout << ans[i] << nn;
}
Compilation message
sortbooks.cpp:4: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
4 | #pragma gcc optimize("ofast")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
58956 KB |
Output is correct |
2 |
Correct |
43 ms |
58944 KB |
Output is correct |
3 |
Correct |
39 ms |
58964 KB |
Output is correct |
4 |
Correct |
36 ms |
59004 KB |
Output is correct |
5 |
Correct |
36 ms |
58912 KB |
Output is correct |
6 |
Correct |
39 ms |
58964 KB |
Output is correct |
7 |
Correct |
39 ms |
58996 KB |
Output is correct |
8 |
Correct |
38 ms |
58956 KB |
Output is correct |
9 |
Correct |
41 ms |
58892 KB |
Output is correct |
10 |
Correct |
39 ms |
58996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
58956 KB |
Output is correct |
2 |
Correct |
43 ms |
58944 KB |
Output is correct |
3 |
Correct |
39 ms |
58964 KB |
Output is correct |
4 |
Correct |
36 ms |
59004 KB |
Output is correct |
5 |
Correct |
36 ms |
58912 KB |
Output is correct |
6 |
Correct |
39 ms |
58964 KB |
Output is correct |
7 |
Correct |
39 ms |
58996 KB |
Output is correct |
8 |
Correct |
38 ms |
58956 KB |
Output is correct |
9 |
Correct |
41 ms |
58892 KB |
Output is correct |
10 |
Correct |
39 ms |
58996 KB |
Output is correct |
11 |
Correct |
40 ms |
59120 KB |
Output is correct |
12 |
Correct |
46 ms |
59236 KB |
Output is correct |
13 |
Correct |
42 ms |
59176 KB |
Output is correct |
14 |
Correct |
46 ms |
59336 KB |
Output is correct |
15 |
Correct |
50 ms |
59340 KB |
Output is correct |
16 |
Correct |
38 ms |
59212 KB |
Output is correct |
17 |
Correct |
39 ms |
59188 KB |
Output is correct |
18 |
Correct |
38 ms |
59180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1716 ms |
101352 KB |
Output is correct |
2 |
Correct |
1799 ms |
101352 KB |
Output is correct |
3 |
Correct |
1755 ms |
101344 KB |
Output is correct |
4 |
Correct |
1724 ms |
101340 KB |
Output is correct |
5 |
Correct |
1633 ms |
82796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
170 ms |
63304 KB |
Output is correct |
2 |
Correct |
156 ms |
64800 KB |
Output is correct |
3 |
Correct |
144 ms |
63208 KB |
Output is correct |
4 |
Correct |
141 ms |
63364 KB |
Output is correct |
5 |
Correct |
149 ms |
63432 KB |
Output is correct |
6 |
Correct |
125 ms |
62936 KB |
Output is correct |
7 |
Correct |
127 ms |
62940 KB |
Output is correct |
8 |
Correct |
132 ms |
63428 KB |
Output is correct |
9 |
Correct |
105 ms |
62016 KB |
Output is correct |
10 |
Correct |
127 ms |
63536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
58956 KB |
Output is correct |
2 |
Correct |
43 ms |
58944 KB |
Output is correct |
3 |
Correct |
39 ms |
58964 KB |
Output is correct |
4 |
Correct |
36 ms |
59004 KB |
Output is correct |
5 |
Correct |
36 ms |
58912 KB |
Output is correct |
6 |
Correct |
39 ms |
58964 KB |
Output is correct |
7 |
Correct |
39 ms |
58996 KB |
Output is correct |
8 |
Correct |
38 ms |
58956 KB |
Output is correct |
9 |
Correct |
41 ms |
58892 KB |
Output is correct |
10 |
Correct |
39 ms |
58996 KB |
Output is correct |
11 |
Correct |
40 ms |
59120 KB |
Output is correct |
12 |
Correct |
46 ms |
59236 KB |
Output is correct |
13 |
Correct |
42 ms |
59176 KB |
Output is correct |
14 |
Correct |
46 ms |
59336 KB |
Output is correct |
15 |
Correct |
50 ms |
59340 KB |
Output is correct |
16 |
Correct |
38 ms |
59212 KB |
Output is correct |
17 |
Correct |
39 ms |
59188 KB |
Output is correct |
18 |
Correct |
38 ms |
59180 KB |
Output is correct |
19 |
Correct |
359 ms |
74196 KB |
Output is correct |
20 |
Correct |
363 ms |
74168 KB |
Output is correct |
21 |
Correct |
328 ms |
73128 KB |
Output is correct |
22 |
Correct |
334 ms |
73060 KB |
Output is correct |
23 |
Correct |
326 ms |
73060 KB |
Output is correct |
24 |
Correct |
302 ms |
69580 KB |
Output is correct |
25 |
Correct |
307 ms |
69744 KB |
Output is correct |
26 |
Correct |
316 ms |
69972 KB |
Output is correct |
27 |
Correct |
369 ms |
70048 KB |
Output is correct |
28 |
Correct |
330 ms |
70088 KB |
Output is correct |
29 |
Correct |
333 ms |
70500 KB |
Output is correct |
30 |
Correct |
336 ms |
70476 KB |
Output is correct |
31 |
Correct |
350 ms |
70544 KB |
Output is correct |
32 |
Correct |
348 ms |
70516 KB |
Output is correct |
33 |
Correct |
348 ms |
70424 KB |
Output is correct |
34 |
Correct |
308 ms |
68928 KB |
Output is correct |
35 |
Correct |
288 ms |
69032 KB |
Output is correct |
36 |
Correct |
301 ms |
68688 KB |
Output is correct |
37 |
Correct |
288 ms |
68764 KB |
Output is correct |
38 |
Correct |
322 ms |
68944 KB |
Output is correct |
39 |
Correct |
292 ms |
69400 KB |
Output is correct |
40 |
Correct |
248 ms |
67844 KB |
Output is correct |
41 |
Correct |
275 ms |
69360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
58956 KB |
Output is correct |
2 |
Correct |
43 ms |
58944 KB |
Output is correct |
3 |
Correct |
39 ms |
58964 KB |
Output is correct |
4 |
Correct |
36 ms |
59004 KB |
Output is correct |
5 |
Correct |
36 ms |
58912 KB |
Output is correct |
6 |
Correct |
39 ms |
58964 KB |
Output is correct |
7 |
Correct |
39 ms |
58996 KB |
Output is correct |
8 |
Correct |
38 ms |
58956 KB |
Output is correct |
9 |
Correct |
41 ms |
58892 KB |
Output is correct |
10 |
Correct |
39 ms |
58996 KB |
Output is correct |
11 |
Correct |
40 ms |
59120 KB |
Output is correct |
12 |
Correct |
46 ms |
59236 KB |
Output is correct |
13 |
Correct |
42 ms |
59176 KB |
Output is correct |
14 |
Correct |
46 ms |
59336 KB |
Output is correct |
15 |
Correct |
50 ms |
59340 KB |
Output is correct |
16 |
Correct |
38 ms |
59212 KB |
Output is correct |
17 |
Correct |
39 ms |
59188 KB |
Output is correct |
18 |
Correct |
38 ms |
59180 KB |
Output is correct |
19 |
Correct |
1716 ms |
101352 KB |
Output is correct |
20 |
Correct |
1799 ms |
101352 KB |
Output is correct |
21 |
Correct |
1755 ms |
101344 KB |
Output is correct |
22 |
Correct |
1724 ms |
101340 KB |
Output is correct |
23 |
Correct |
1633 ms |
82796 KB |
Output is correct |
24 |
Correct |
170 ms |
63304 KB |
Output is correct |
25 |
Correct |
156 ms |
64800 KB |
Output is correct |
26 |
Correct |
144 ms |
63208 KB |
Output is correct |
27 |
Correct |
141 ms |
63364 KB |
Output is correct |
28 |
Correct |
149 ms |
63432 KB |
Output is correct |
29 |
Correct |
125 ms |
62936 KB |
Output is correct |
30 |
Correct |
127 ms |
62940 KB |
Output is correct |
31 |
Correct |
132 ms |
63428 KB |
Output is correct |
32 |
Correct |
105 ms |
62016 KB |
Output is correct |
33 |
Correct |
127 ms |
63536 KB |
Output is correct |
34 |
Correct |
359 ms |
74196 KB |
Output is correct |
35 |
Correct |
363 ms |
74168 KB |
Output is correct |
36 |
Correct |
328 ms |
73128 KB |
Output is correct |
37 |
Correct |
334 ms |
73060 KB |
Output is correct |
38 |
Correct |
326 ms |
73060 KB |
Output is correct |
39 |
Correct |
302 ms |
69580 KB |
Output is correct |
40 |
Correct |
307 ms |
69744 KB |
Output is correct |
41 |
Correct |
316 ms |
69972 KB |
Output is correct |
42 |
Correct |
369 ms |
70048 KB |
Output is correct |
43 |
Correct |
330 ms |
70088 KB |
Output is correct |
44 |
Correct |
333 ms |
70500 KB |
Output is correct |
45 |
Correct |
336 ms |
70476 KB |
Output is correct |
46 |
Correct |
350 ms |
70544 KB |
Output is correct |
47 |
Correct |
348 ms |
70516 KB |
Output is correct |
48 |
Correct |
348 ms |
70424 KB |
Output is correct |
49 |
Correct |
308 ms |
68928 KB |
Output is correct |
50 |
Correct |
288 ms |
69032 KB |
Output is correct |
51 |
Correct |
301 ms |
68688 KB |
Output is correct |
52 |
Correct |
288 ms |
68764 KB |
Output is correct |
53 |
Correct |
322 ms |
68944 KB |
Output is correct |
54 |
Correct |
292 ms |
69400 KB |
Output is correct |
55 |
Correct |
248 ms |
67844 KB |
Output is correct |
56 |
Correct |
275 ms |
69360 KB |
Output is correct |
57 |
Correct |
1855 ms |
135916 KB |
Output is correct |
58 |
Correct |
1805 ms |
135904 KB |
Output is correct |
59 |
Correct |
1753 ms |
133208 KB |
Output is correct |
60 |
Correct |
1785 ms |
133192 KB |
Output is correct |
61 |
Correct |
1730 ms |
133240 KB |
Output is correct |
62 |
Correct |
1745 ms |
133280 KB |
Output is correct |
63 |
Correct |
1373 ms |
109300 KB |
Output is correct |
64 |
Correct |
1361 ms |
109328 KB |
Output is correct |
65 |
Correct |
1662 ms |
115168 KB |
Output is correct |
66 |
Correct |
1703 ms |
114776 KB |
Output is correct |
67 |
Correct |
1645 ms |
114804 KB |
Output is correct |
68 |
Correct |
1696 ms |
116968 KB |
Output is correct |
69 |
Correct |
1719 ms |
117176 KB |
Output is correct |
70 |
Correct |
1809 ms |
116544 KB |
Output is correct |
71 |
Correct |
1763 ms |
116520 KB |
Output is correct |
72 |
Correct |
1720 ms |
116460 KB |
Output is correct |
73 |
Correct |
1298 ms |
106844 KB |
Output is correct |
74 |
Correct |
1332 ms |
107724 KB |
Output is correct |
75 |
Correct |
1307 ms |
106944 KB |
Output is correct |
76 |
Correct |
1305 ms |
106808 KB |
Output is correct |
77 |
Correct |
1302 ms |
106880 KB |
Output is correct |
78 |
Correct |
1507 ms |
113076 KB |
Output is correct |
79 |
Correct |
1166 ms |
102096 KB |
Output is correct |
80 |
Correct |
1314 ms |
111852 KB |
Output is correct |