#include <chrono>
#include <random>
#include <iostream>
#include <string>
#include <unordered_map>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
#define tm abc
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1e9 + 7;
const int inf = 1e9;
const int N = 1e6 + 15;
int n, m, sz, a[N], st[N], ans[N], t[N << 1];
bool output[N];
struct query {
int l, r, k, ind;
bool operator < (const query &b) const {
return r < b.r;
}
} qs[N];
inline void update(int i, int val) {
i += n;
for(t[i] = max(t[i], val); i > 1; i >>= 1)
t[i >> 1] = max(t[i >> 1], val);
}
inline int get(int l, int r) {
int res = 0;
for(l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
if(l & 1)
res = max(res, t[l++]);
if(r & 1)
res = max(res, t[--r]);
}
return res;
}
main() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
for(int i = 1; i <= m; ++i) {
scanf("%d%d%d", &qs[i].l, &qs[i].r, &qs[i].k);
qs[i].ind = i;
}
sort(qs + 1, qs + 1 + m);
int i = 1, j = 1;
for(; i <= n; ++i) {
while(sz && a[st[sz - 1]] <= a[i])
--sz;
if(sz) {
int ind_nearest = st[sz - 1];
int sum = a[ind_nearest] + a[i];
while(j <= m && qs[j].r < i) {
ans[qs[j].ind] = max(ans[qs[j].ind], get(qs[j].l, n));
++j;
}
update(ind_nearest, sum);
}
st[sz++] = i;
}
while(j <= m) {
ans[qs[j].ind] = max(ans[qs[j].ind], get(qs[j].l, n));
++j;
}
for(int i = 1; i <= m; ++i)
if(ans[qs[i].ind] <= qs[i].k)
output[qs[i].ind] = true;
for(int i = 1; i <= m; ++i)
puts(output[i] ? "1" : "0");
return 0;
}
Compilation message
sortbooks.cpp:72:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
~~~~~^~~~~~~~~~~~~
sortbooks.cpp:77:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &qs[i].l, &qs[i].r, &qs[i].k);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
3 ms |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
3 ms |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
636 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
6 ms |
760 KB |
Output is correct |
15 |
Correct |
6 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
632 KB |
Output is correct |
17 |
Correct |
5 ms |
632 KB |
Output is correct |
18 |
Correct |
5 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1014 ms |
65524 KB |
Output is correct |
2 |
Correct |
1045 ms |
66540 KB |
Output is correct |
3 |
Correct |
1143 ms |
66676 KB |
Output is correct |
4 |
Correct |
1044 ms |
66608 KB |
Output is correct |
5 |
Correct |
899 ms |
59768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
5752 KB |
Output is correct |
2 |
Correct |
81 ms |
5736 KB |
Output is correct |
3 |
Correct |
71 ms |
4960 KB |
Output is correct |
4 |
Correct |
71 ms |
4956 KB |
Output is correct |
5 |
Correct |
70 ms |
4936 KB |
Output is correct |
6 |
Correct |
71 ms |
4728 KB |
Output is correct |
7 |
Correct |
60 ms |
4840 KB |
Output is correct |
8 |
Correct |
65 ms |
4728 KB |
Output is correct |
9 |
Correct |
44 ms |
3960 KB |
Output is correct |
10 |
Correct |
66 ms |
4856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
3 ms |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
636 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
6 ms |
760 KB |
Output is correct |
15 |
Correct |
6 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
632 KB |
Output is correct |
17 |
Correct |
5 ms |
632 KB |
Output is correct |
18 |
Correct |
5 ms |
632 KB |
Output is correct |
19 |
Correct |
188 ms |
13848 KB |
Output is correct |
20 |
Correct |
186 ms |
13816 KB |
Output is correct |
21 |
Correct |
173 ms |
13688 KB |
Output is correct |
22 |
Correct |
174 ms |
13804 KB |
Output is correct |
23 |
Correct |
173 ms |
13628 KB |
Output is correct |
24 |
Correct |
157 ms |
12024 KB |
Output is correct |
25 |
Correct |
156 ms |
11988 KB |
Output is correct |
26 |
Correct |
165 ms |
12160 KB |
Output is correct |
27 |
Correct |
169 ms |
12280 KB |
Output is correct |
28 |
Correct |
166 ms |
12140 KB |
Output is correct |
29 |
Correct |
170 ms |
12248 KB |
Output is correct |
30 |
Correct |
183 ms |
12380 KB |
Output is correct |
31 |
Correct |
174 ms |
12408 KB |
Output is correct |
32 |
Correct |
172 ms |
12184 KB |
Output is correct |
33 |
Correct |
170 ms |
12408 KB |
Output is correct |
34 |
Correct |
144 ms |
12024 KB |
Output is correct |
35 |
Correct |
141 ms |
11896 KB |
Output is correct |
36 |
Correct |
139 ms |
11768 KB |
Output is correct |
37 |
Correct |
143 ms |
11788 KB |
Output is correct |
38 |
Correct |
141 ms |
11884 KB |
Output is correct |
39 |
Correct |
150 ms |
11384 KB |
Output is correct |
40 |
Correct |
189 ms |
9896 KB |
Output is correct |
41 |
Correct |
152 ms |
10436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
3 ms |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
636 KB |
Output is correct |
13 |
Correct |
5 ms |
632 KB |
Output is correct |
14 |
Correct |
6 ms |
760 KB |
Output is correct |
15 |
Correct |
6 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
632 KB |
Output is correct |
17 |
Correct |
5 ms |
632 KB |
Output is correct |
18 |
Correct |
5 ms |
632 KB |
Output is correct |
19 |
Correct |
1014 ms |
65524 KB |
Output is correct |
20 |
Correct |
1045 ms |
66540 KB |
Output is correct |
21 |
Correct |
1143 ms |
66676 KB |
Output is correct |
22 |
Correct |
1044 ms |
66608 KB |
Output is correct |
23 |
Correct |
899 ms |
59768 KB |
Output is correct |
24 |
Correct |
77 ms |
5752 KB |
Output is correct |
25 |
Correct |
81 ms |
5736 KB |
Output is correct |
26 |
Correct |
71 ms |
4960 KB |
Output is correct |
27 |
Correct |
71 ms |
4956 KB |
Output is correct |
28 |
Correct |
70 ms |
4936 KB |
Output is correct |
29 |
Correct |
71 ms |
4728 KB |
Output is correct |
30 |
Correct |
60 ms |
4840 KB |
Output is correct |
31 |
Correct |
65 ms |
4728 KB |
Output is correct |
32 |
Correct |
44 ms |
3960 KB |
Output is correct |
33 |
Correct |
66 ms |
4856 KB |
Output is correct |
34 |
Correct |
188 ms |
13848 KB |
Output is correct |
35 |
Correct |
186 ms |
13816 KB |
Output is correct |
36 |
Correct |
173 ms |
13688 KB |
Output is correct |
37 |
Correct |
174 ms |
13804 KB |
Output is correct |
38 |
Correct |
173 ms |
13628 KB |
Output is correct |
39 |
Correct |
157 ms |
12024 KB |
Output is correct |
40 |
Correct |
156 ms |
11988 KB |
Output is correct |
41 |
Correct |
165 ms |
12160 KB |
Output is correct |
42 |
Correct |
169 ms |
12280 KB |
Output is correct |
43 |
Correct |
166 ms |
12140 KB |
Output is correct |
44 |
Correct |
170 ms |
12248 KB |
Output is correct |
45 |
Correct |
183 ms |
12380 KB |
Output is correct |
46 |
Correct |
174 ms |
12408 KB |
Output is correct |
47 |
Correct |
172 ms |
12184 KB |
Output is correct |
48 |
Correct |
170 ms |
12408 KB |
Output is correct |
49 |
Correct |
144 ms |
12024 KB |
Output is correct |
50 |
Correct |
141 ms |
11896 KB |
Output is correct |
51 |
Correct |
139 ms |
11768 KB |
Output is correct |
52 |
Correct |
143 ms |
11788 KB |
Output is correct |
53 |
Correct |
141 ms |
11884 KB |
Output is correct |
54 |
Correct |
150 ms |
11384 KB |
Output is correct |
55 |
Correct |
189 ms |
9896 KB |
Output is correct |
56 |
Correct |
152 ms |
10436 KB |
Output is correct |
57 |
Correct |
1087 ms |
65180 KB |
Output is correct |
58 |
Correct |
1025 ms |
67948 KB |
Output is correct |
59 |
Correct |
1004 ms |
66664 KB |
Output is correct |
60 |
Correct |
1012 ms |
66240 KB |
Output is correct |
61 |
Correct |
1027 ms |
66040 KB |
Output is correct |
62 |
Correct |
997 ms |
66364 KB |
Output is correct |
63 |
Correct |
799 ms |
56616 KB |
Output is correct |
64 |
Correct |
818 ms |
55888 KB |
Output is correct |
65 |
Correct |
1006 ms |
58920 KB |
Output is correct |
66 |
Correct |
912 ms |
56740 KB |
Output is correct |
67 |
Correct |
909 ms |
56200 KB |
Output is correct |
68 |
Correct |
917 ms |
48544 KB |
Output is correct |
69 |
Correct |
918 ms |
53512 KB |
Output is correct |
70 |
Correct |
907 ms |
46576 KB |
Output is correct |
71 |
Correct |
914 ms |
51420 KB |
Output is correct |
72 |
Correct |
936 ms |
45368 KB |
Output is correct |
73 |
Correct |
709 ms |
38392 KB |
Output is correct |
74 |
Correct |
725 ms |
36336 KB |
Output is correct |
75 |
Correct |
712 ms |
32908 KB |
Output is correct |
76 |
Correct |
775 ms |
35672 KB |
Output is correct |
77 |
Correct |
740 ms |
37164 KB |
Output is correct |
78 |
Correct |
847 ms |
40644 KB |
Output is correct |
79 |
Correct |
661 ms |
38608 KB |
Output is correct |
80 |
Correct |
778 ms |
48004 KB |
Output is correct |