#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
int n,m;
int a[1000005], ans[1000005];
stack<int> s;
vector<pair<pair<int, int>, pair<int,int> > > que;
struct node
{
int mx = 0;
node *l, *r;
} *root;
node* build(int l, int r)
{
node *ptr = new node();
if(l == r) return ptr;
int mid = (l + r) >> 1;
ptr->l = build(l, mid);
ptr->r = build(mid + 1, r);
return ptr;
}
node* build()
{
return build(0, n - 1);
}
void update(node *ptr, int l, int r, int po, int val)
{
ptr->mx = max(ptr->mx, val);
if(l == r) return ;
int mid = (l + r) >> 1;
if(po <= mid) update(ptr->l, l, mid, po, val);
else update(ptr->r, mid + 1, r, po, val);
}
void update(int po, int val)
{
update(root, 0, n - 1, po, val);
}
int query(node *ptr, int l, int r, int ll, int rr)
{
if(ll <= l && r <= rr) return ptr->mx;
if(rr < l || r < ll) return 0;
int mid = (l + r) >> 1;
return max(query(ptr->l, l, mid, ll, rr), query(ptr->r, mid + 1, r, ll, rr));
}
int query(int ll, int rr)
{
return query(root, 0, n - 1, ll, rr);
}
int main()
{
scanf("%d %d",&n,&m);
root = build();
for(int i = 0; i < n; i++)
{
scanf("%d",&a[i]);
}
for(int i = 0; i < m ; i++)
{
int a, b, c;
scanf("%d %d %d",&a,&b,&c);
que.pb({{b - 1, a - 1}, {c, i}});
}
sort(que.begin(), que.end());
int cur = 0;
for(int i = 0; i < n; i++)
{
while(!s.empty() && a[s.top()] <= a[i])
s.pop();
if(!s.empty())
update(s.top(), a[s.top()] + a[i]);
s.push(i);
while(cur < m && que[cur].f.f == i)
{
ans[que[cur].s.s] = (query(que[cur].f.s, que[cur].f.f) <= que[cur].s.f)? 1:0;
cur++;
}
}
for(int i = 0; i < m; i++)
printf("%d\n", ans[i]);
return 0;
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | scanf("%d %d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~
sortbooks.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
sortbooks.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | scanf("%d %d %d",&a,&b,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
4 ms |
852 KB |
Output is correct |
13 |
Correct |
6 ms |
852 KB |
Output is correct |
14 |
Correct |
8 ms |
1012 KB |
Output is correct |
15 |
Correct |
6 ms |
952 KB |
Output is correct |
16 |
Correct |
4 ms |
980 KB |
Output is correct |
17 |
Correct |
4 ms |
808 KB |
Output is correct |
18 |
Correct |
4 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1481 ms |
88612 KB |
Output is correct |
2 |
Correct |
1451 ms |
88656 KB |
Output is correct |
3 |
Correct |
1411 ms |
88484 KB |
Output is correct |
4 |
Correct |
1426 ms |
88604 KB |
Output is correct |
5 |
Correct |
1384 ms |
88524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
9696 KB |
Output is correct |
2 |
Correct |
97 ms |
9812 KB |
Output is correct |
3 |
Correct |
90 ms |
9776 KB |
Output is correct |
4 |
Correct |
89 ms |
9808 KB |
Output is correct |
5 |
Correct |
90 ms |
9872 KB |
Output is correct |
6 |
Correct |
80 ms |
9808 KB |
Output is correct |
7 |
Correct |
82 ms |
9864 KB |
Output is correct |
8 |
Correct |
80 ms |
9880 KB |
Output is correct |
9 |
Correct |
46 ms |
3204 KB |
Output is correct |
10 |
Correct |
82 ms |
9824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
4 ms |
852 KB |
Output is correct |
13 |
Correct |
6 ms |
852 KB |
Output is correct |
14 |
Correct |
8 ms |
1012 KB |
Output is correct |
15 |
Correct |
6 ms |
952 KB |
Output is correct |
16 |
Correct |
4 ms |
980 KB |
Output is correct |
17 |
Correct |
4 ms |
808 KB |
Output is correct |
18 |
Correct |
4 ms |
852 KB |
Output is correct |
19 |
Correct |
243 ms |
18948 KB |
Output is correct |
20 |
Correct |
229 ms |
18688 KB |
Output is correct |
21 |
Correct |
202 ms |
18604 KB |
Output is correct |
22 |
Correct |
194 ms |
18692 KB |
Output is correct |
23 |
Correct |
213 ms |
18756 KB |
Output is correct |
24 |
Correct |
189 ms |
18608 KB |
Output is correct |
25 |
Correct |
176 ms |
18652 KB |
Output is correct |
26 |
Correct |
187 ms |
18688 KB |
Output is correct |
27 |
Correct |
189 ms |
18636 KB |
Output is correct |
28 |
Correct |
192 ms |
18608 KB |
Output is correct |
29 |
Correct |
204 ms |
18708 KB |
Output is correct |
30 |
Correct |
219 ms |
18696 KB |
Output is correct |
31 |
Correct |
207 ms |
18672 KB |
Output is correct |
32 |
Correct |
219 ms |
18596 KB |
Output is correct |
33 |
Correct |
211 ms |
18688 KB |
Output is correct |
34 |
Correct |
173 ms |
18640 KB |
Output is correct |
35 |
Correct |
189 ms |
18624 KB |
Output is correct |
36 |
Correct |
170 ms |
18580 KB |
Output is correct |
37 |
Correct |
172 ms |
18668 KB |
Output is correct |
38 |
Correct |
176 ms |
18600 KB |
Output is correct |
39 |
Correct |
175 ms |
18672 KB |
Output is correct |
40 |
Correct |
141 ms |
14040 KB |
Output is correct |
41 |
Correct |
173 ms |
18676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
4 ms |
852 KB |
Output is correct |
13 |
Correct |
6 ms |
852 KB |
Output is correct |
14 |
Correct |
8 ms |
1012 KB |
Output is correct |
15 |
Correct |
6 ms |
952 KB |
Output is correct |
16 |
Correct |
4 ms |
980 KB |
Output is correct |
17 |
Correct |
4 ms |
808 KB |
Output is correct |
18 |
Correct |
4 ms |
852 KB |
Output is correct |
19 |
Correct |
1481 ms |
88612 KB |
Output is correct |
20 |
Correct |
1451 ms |
88656 KB |
Output is correct |
21 |
Correct |
1411 ms |
88484 KB |
Output is correct |
22 |
Correct |
1426 ms |
88604 KB |
Output is correct |
23 |
Correct |
1384 ms |
88524 KB |
Output is correct |
24 |
Correct |
99 ms |
9696 KB |
Output is correct |
25 |
Correct |
97 ms |
9812 KB |
Output is correct |
26 |
Correct |
90 ms |
9776 KB |
Output is correct |
27 |
Correct |
89 ms |
9808 KB |
Output is correct |
28 |
Correct |
90 ms |
9872 KB |
Output is correct |
29 |
Correct |
80 ms |
9808 KB |
Output is correct |
30 |
Correct |
82 ms |
9864 KB |
Output is correct |
31 |
Correct |
80 ms |
9880 KB |
Output is correct |
32 |
Correct |
46 ms |
3204 KB |
Output is correct |
33 |
Correct |
82 ms |
9824 KB |
Output is correct |
34 |
Correct |
243 ms |
18948 KB |
Output is correct |
35 |
Correct |
229 ms |
18688 KB |
Output is correct |
36 |
Correct |
202 ms |
18604 KB |
Output is correct |
37 |
Correct |
194 ms |
18692 KB |
Output is correct |
38 |
Correct |
213 ms |
18756 KB |
Output is correct |
39 |
Correct |
189 ms |
18608 KB |
Output is correct |
40 |
Correct |
176 ms |
18652 KB |
Output is correct |
41 |
Correct |
187 ms |
18688 KB |
Output is correct |
42 |
Correct |
189 ms |
18636 KB |
Output is correct |
43 |
Correct |
192 ms |
18608 KB |
Output is correct |
44 |
Correct |
204 ms |
18708 KB |
Output is correct |
45 |
Correct |
219 ms |
18696 KB |
Output is correct |
46 |
Correct |
207 ms |
18672 KB |
Output is correct |
47 |
Correct |
219 ms |
18596 KB |
Output is correct |
48 |
Correct |
211 ms |
18688 KB |
Output is correct |
49 |
Correct |
173 ms |
18640 KB |
Output is correct |
50 |
Correct |
189 ms |
18624 KB |
Output is correct |
51 |
Correct |
170 ms |
18580 KB |
Output is correct |
52 |
Correct |
172 ms |
18668 KB |
Output is correct |
53 |
Correct |
176 ms |
18600 KB |
Output is correct |
54 |
Correct |
175 ms |
18672 KB |
Output is correct |
55 |
Correct |
141 ms |
14040 KB |
Output is correct |
56 |
Correct |
173 ms |
18676 KB |
Output is correct |
57 |
Correct |
1361 ms |
88600 KB |
Output is correct |
58 |
Correct |
1362 ms |
88608 KB |
Output is correct |
59 |
Correct |
1368 ms |
88612 KB |
Output is correct |
60 |
Correct |
1343 ms |
88624 KB |
Output is correct |
61 |
Correct |
1297 ms |
88684 KB |
Output is correct |
62 |
Correct |
1422 ms |
88608 KB |
Output is correct |
63 |
Correct |
1008 ms |
88560 KB |
Output is correct |
64 |
Correct |
972 ms |
88636 KB |
Output is correct |
65 |
Correct |
1297 ms |
88612 KB |
Output is correct |
66 |
Correct |
1639 ms |
88636 KB |
Output is correct |
67 |
Correct |
1351 ms |
88680 KB |
Output is correct |
68 |
Correct |
1748 ms |
88608 KB |
Output is correct |
69 |
Correct |
1414 ms |
88612 KB |
Output is correct |
70 |
Correct |
1544 ms |
88608 KB |
Output is correct |
71 |
Correct |
1450 ms |
88668 KB |
Output is correct |
72 |
Correct |
1298 ms |
88756 KB |
Output is correct |
73 |
Correct |
910 ms |
88672 KB |
Output is correct |
74 |
Correct |
889 ms |
88576 KB |
Output is correct |
75 |
Correct |
899 ms |
88664 KB |
Output is correct |
76 |
Correct |
887 ms |
88600 KB |
Output is correct |
77 |
Correct |
915 ms |
88596 KB |
Output is correct |
78 |
Correct |
1122 ms |
88740 KB |
Output is correct |
79 |
Correct |
872 ms |
56928 KB |
Output is correct |
80 |
Correct |
1113 ms |
88680 KB |
Output is correct |