#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e6;
struct Query { int l, r, k; };
int N, M, A[MAXN+10];
Query B[MAXN+10];
vector<int> tree[MAXN*4+10];
int tree2[MAXN*4+10];
void init(int node, int tl, int tr)
{
if(tl==tr)
{
tree[node].push_back(A[tl]);
tree2[node]=0;
return;
}
int mid=tl+tr>>1;
init(node*2, tl, mid);
init(node*2+1, mid+1, tr);
tree[node].resize(tree[node*2].size()+tree[node*2+1].size());
merge(tree[node*2].begin(), tree[node*2].end(), tree[node*2+1].begin(), tree[node*2+1].end(), tree[node].begin());
auto it=lower_bound(tree[node*2+1].begin(), tree[node*2+1].end(), tree[node*2].back());
if(it!=tree[node*2+1].begin()) tree2[node]=*(--it)+tree[node*2].back();
tree2[node]=max({tree2[node], tree2[node*2], tree2[node*2+1]});
}
void query(int node, int tl, int tr, int l, int r, vector<int> &V)
{
if(r<tl || tr<l) return;
if(l<=tl && tr<=r)
{
V.push_back(node);
return;
}
int mid=tl+tr>>1;
query(node*2, tl, mid, l, r, V);
query(node*2+1, mid+1, tr, l, r, V);
}
int main()
{
int i, j;
scanf("%d%d", &N, &M);
for(i=1; i<=N; i++) scanf("%d", &A[i]);
for(i=1; i<=M; i++) scanf("%d%d%d", &B[i].l, &B[i].r, &B[i].k);
init(1, 1, N);
for(i=1; i<=M; i++)
{
vector<int> V;
query(1, 1, N, B[i].l, B[i].r, V);
int ans=0, val=0;
for(auto it : V)
{
ans=max(ans, tree2[it]);
auto jt=lower_bound(tree[it].begin(), tree[it].end(), val);
if(jt!=tree[it].begin()) ans=max(ans, *(--jt)+val);
val=max(val, tree[it].back());
}
printf("%d\n", ans<=B[i].k);
}
}
Compilation message
sortbooks.cpp: In function 'void init(int, int, int)':
sortbooks.cpp:26:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
sortbooks.cpp: In function 'void query(int, int, int, int, int, std::vector<int>&)':
sortbooks.cpp:45:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:52:9: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
sortbooks.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &M);
~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:55:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=N; i++) scanf("%d", &A[i]);
~~~~~^~~~~~~~~~~~~
sortbooks.cpp:56:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=M; i++) scanf("%d%d%d", &B[i].l, &B[i].r, &B[i].k);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
94200 KB |
Output is correct |
2 |
Correct |
57 ms |
94200 KB |
Output is correct |
3 |
Correct |
56 ms |
94328 KB |
Output is correct |
4 |
Correct |
56 ms |
94328 KB |
Output is correct |
5 |
Correct |
65 ms |
94284 KB |
Output is correct |
6 |
Correct |
63 ms |
94456 KB |
Output is correct |
7 |
Correct |
57 ms |
94436 KB |
Output is correct |
8 |
Correct |
59 ms |
94328 KB |
Output is correct |
9 |
Correct |
69 ms |
94252 KB |
Output is correct |
10 |
Correct |
55 ms |
94328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
94200 KB |
Output is correct |
2 |
Correct |
57 ms |
94200 KB |
Output is correct |
3 |
Correct |
56 ms |
94328 KB |
Output is correct |
4 |
Correct |
56 ms |
94328 KB |
Output is correct |
5 |
Correct |
65 ms |
94284 KB |
Output is correct |
6 |
Correct |
63 ms |
94456 KB |
Output is correct |
7 |
Correct |
57 ms |
94436 KB |
Output is correct |
8 |
Correct |
59 ms |
94328 KB |
Output is correct |
9 |
Correct |
69 ms |
94252 KB |
Output is correct |
10 |
Correct |
55 ms |
94328 KB |
Output is correct |
11 |
Correct |
59 ms |
94584 KB |
Output is correct |
12 |
Correct |
69 ms |
95096 KB |
Output is correct |
13 |
Correct |
69 ms |
94968 KB |
Output is correct |
14 |
Correct |
77 ms |
95224 KB |
Output is correct |
15 |
Correct |
67 ms |
95096 KB |
Output is correct |
16 |
Correct |
64 ms |
94968 KB |
Output is correct |
17 |
Correct |
62 ms |
94840 KB |
Output is correct |
18 |
Correct |
62 ms |
95052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3089 ms |
249116 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
400 ms |
108836 KB |
Output is correct |
2 |
Correct |
365 ms |
110584 KB |
Output is correct |
3 |
Correct |
342 ms |
110500 KB |
Output is correct |
4 |
Correct |
295 ms |
110584 KB |
Output is correct |
5 |
Correct |
294 ms |
110764 KB |
Output is correct |
6 |
Correct |
286 ms |
110456 KB |
Output is correct |
7 |
Correct |
260 ms |
110456 KB |
Output is correct |
8 |
Correct |
309 ms |
110432 KB |
Output is correct |
9 |
Correct |
151 ms |
97272 KB |
Output is correct |
10 |
Correct |
254 ms |
110200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
94200 KB |
Output is correct |
2 |
Correct |
57 ms |
94200 KB |
Output is correct |
3 |
Correct |
56 ms |
94328 KB |
Output is correct |
4 |
Correct |
56 ms |
94328 KB |
Output is correct |
5 |
Correct |
65 ms |
94284 KB |
Output is correct |
6 |
Correct |
63 ms |
94456 KB |
Output is correct |
7 |
Correct |
57 ms |
94436 KB |
Output is correct |
8 |
Correct |
59 ms |
94328 KB |
Output is correct |
9 |
Correct |
69 ms |
94252 KB |
Output is correct |
10 |
Correct |
55 ms |
94328 KB |
Output is correct |
11 |
Correct |
59 ms |
94584 KB |
Output is correct |
12 |
Correct |
69 ms |
95096 KB |
Output is correct |
13 |
Correct |
69 ms |
94968 KB |
Output is correct |
14 |
Correct |
77 ms |
95224 KB |
Output is correct |
15 |
Correct |
67 ms |
95096 KB |
Output is correct |
16 |
Correct |
64 ms |
94968 KB |
Output is correct |
17 |
Correct |
62 ms |
94840 KB |
Output is correct |
18 |
Correct |
62 ms |
95052 KB |
Output is correct |
19 |
Correct |
797 ms |
130348 KB |
Output is correct |
20 |
Correct |
787 ms |
130424 KB |
Output is correct |
21 |
Correct |
635 ms |
130044 KB |
Output is correct |
22 |
Correct |
697 ms |
130040 KB |
Output is correct |
23 |
Correct |
665 ms |
130040 KB |
Output is correct |
24 |
Correct |
609 ms |
130168 KB |
Output is correct |
25 |
Correct |
550 ms |
129916 KB |
Output is correct |
26 |
Correct |
618 ms |
130168 KB |
Output is correct |
27 |
Correct |
733 ms |
130204 KB |
Output is correct |
28 |
Correct |
638 ms |
130168 KB |
Output is correct |
29 |
Correct |
646 ms |
130168 KB |
Output is correct |
30 |
Correct |
624 ms |
130264 KB |
Output is correct |
31 |
Correct |
739 ms |
130552 KB |
Output is correct |
32 |
Correct |
635 ms |
130296 KB |
Output is correct |
33 |
Correct |
732 ms |
130296 KB |
Output is correct |
34 |
Correct |
555 ms |
129888 KB |
Output is correct |
35 |
Correct |
525 ms |
129784 KB |
Output is correct |
36 |
Correct |
512 ms |
129656 KB |
Output is correct |
37 |
Correct |
520 ms |
129788 KB |
Output is correct |
38 |
Correct |
542 ms |
129968 KB |
Output is correct |
39 |
Correct |
586 ms |
128888 KB |
Output is correct |
40 |
Correct |
464 ms |
118520 KB |
Output is correct |
41 |
Correct |
525 ms |
128376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
94200 KB |
Output is correct |
2 |
Correct |
57 ms |
94200 KB |
Output is correct |
3 |
Correct |
56 ms |
94328 KB |
Output is correct |
4 |
Correct |
56 ms |
94328 KB |
Output is correct |
5 |
Correct |
65 ms |
94284 KB |
Output is correct |
6 |
Correct |
63 ms |
94456 KB |
Output is correct |
7 |
Correct |
57 ms |
94436 KB |
Output is correct |
8 |
Correct |
59 ms |
94328 KB |
Output is correct |
9 |
Correct |
69 ms |
94252 KB |
Output is correct |
10 |
Correct |
55 ms |
94328 KB |
Output is correct |
11 |
Correct |
59 ms |
94584 KB |
Output is correct |
12 |
Correct |
69 ms |
95096 KB |
Output is correct |
13 |
Correct |
69 ms |
94968 KB |
Output is correct |
14 |
Correct |
77 ms |
95224 KB |
Output is correct |
15 |
Correct |
67 ms |
95096 KB |
Output is correct |
16 |
Correct |
64 ms |
94968 KB |
Output is correct |
17 |
Correct |
62 ms |
94840 KB |
Output is correct |
18 |
Correct |
62 ms |
95052 KB |
Output is correct |
19 |
Execution timed out |
3089 ms |
249116 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |