#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
int n, m;
int v[MAXN];
int l[MAXN];
int ans[MAXN];
struct event{
int a, b, c, id;
event(int _a = 0, int _b = 0, int _c = 0, int _id = 0){
a = _a, b = _b, c = _c, id = _id;
}
void scan(int _id){
scanf("%d %d %d", &a, &b, &c);
id = _id;
}
bool operator < (event x) const{
if(c == x.c) return a > x.a;
return c > x.c;
}
};
vector<event> line;
int seg[4 * MAXN];
void update(int pos, int ini, int fim, int id, int val);
int query(int pos, int ini, int fim, int p, int q);
int main(){
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i++){
scanf("%d", &v[i]);
l[i] = i - 1;
while(l[i] > 0 && v[l[i]] <= v[i]) l[i] = l[l[i]];
line.push_back(event(-1, i, v[i] + v[l[i]], -1));
}
for(int i = 1; i <= m; i++){
event aux;
aux.scan(i);
line.push_back(aux);
}
sort(line.begin(), line.end());
for(int i = 0; i < line.size(); i++){
if(line[i].a == -1) update(1, 1, n, line[i].b, l[line[i].b]);
else ans[line[i].id] = query(1, 1, n, line[i].a, line[i].b) < line[i].a;
}
for(int i = 1; i <= m; i++)
printf("%d\n", ans[i]);
}
void update(int pos, int ini, int fim, int id, int val){
if(ini > id || fim < id) return;
if(ini == fim){
seg[pos] = max(seg[pos], val);
return;
}
int mid = (ini + fim) >> 1, e = pos << 1, d = e | 1;
update(e, ini, mid, id, val);
update(d, mid + 1, fim, id, val);
seg[pos] = max(seg[e], seg[d]);
}
int query(int pos, int ini, int fim, int p, int q){
if(ini > q || fim < p) return 0;
if(ini >= p && fim <= q) return seg[pos];
int mid = (ini + fim) >> 1, e = pos << 1, d = e | 1;
return max(query(e, ini, mid, p, q), query(d, mid + 1, fim, p, q));
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i = 0; i < line.size(); i++){
| ~~^~~~~~~~~~~~~
sortbooks.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
35 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
sortbooks.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
37 | scanf("%d", &v[i]);
| ~~~~~^~~~~~~~~~~~~
sortbooks.cpp: In member function 'void event::scan(int)':
sortbooks.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
19 | scanf("%d %d %d", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
716 KB |
Output is correct |
13 |
Correct |
6 ms |
716 KB |
Output is correct |
14 |
Correct |
7 ms |
844 KB |
Output is correct |
15 |
Correct |
9 ms |
844 KB |
Output is correct |
16 |
Correct |
7 ms |
840 KB |
Output is correct |
17 |
Correct |
5 ms |
844 KB |
Output is correct |
18 |
Correct |
6 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2158 ms |
64284 KB |
Output is correct |
2 |
Correct |
2164 ms |
69028 KB |
Output is correct |
3 |
Correct |
2201 ms |
69060 KB |
Output is correct |
4 |
Correct |
2127 ms |
69012 KB |
Output is correct |
5 |
Correct |
1981 ms |
69176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
194 ms |
7896 KB |
Output is correct |
2 |
Correct |
151 ms |
7852 KB |
Output is correct |
3 |
Correct |
139 ms |
7948 KB |
Output is correct |
4 |
Correct |
144 ms |
7896 KB |
Output is correct |
5 |
Correct |
135 ms |
7896 KB |
Output is correct |
6 |
Correct |
125 ms |
7732 KB |
Output is correct |
7 |
Correct |
122 ms |
7720 KB |
Output is correct |
8 |
Correct |
118 ms |
7628 KB |
Output is correct |
9 |
Correct |
59 ms |
3852 KB |
Output is correct |
10 |
Correct |
120 ms |
7588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
716 KB |
Output is correct |
13 |
Correct |
6 ms |
716 KB |
Output is correct |
14 |
Correct |
7 ms |
844 KB |
Output is correct |
15 |
Correct |
9 ms |
844 KB |
Output is correct |
16 |
Correct |
7 ms |
840 KB |
Output is correct |
17 |
Correct |
5 ms |
844 KB |
Output is correct |
18 |
Correct |
6 ms |
716 KB |
Output is correct |
19 |
Correct |
343 ms |
18056 KB |
Output is correct |
20 |
Correct |
349 ms |
18088 KB |
Output is correct |
21 |
Correct |
334 ms |
17896 KB |
Output is correct |
22 |
Correct |
330 ms |
17820 KB |
Output is correct |
23 |
Correct |
335 ms |
17972 KB |
Output is correct |
24 |
Correct |
304 ms |
17816 KB |
Output is correct |
25 |
Correct |
299 ms |
17772 KB |
Output is correct |
26 |
Correct |
328 ms |
18008 KB |
Output is correct |
27 |
Correct |
307 ms |
18012 KB |
Output is correct |
28 |
Correct |
325 ms |
17948 KB |
Output is correct |
29 |
Correct |
306 ms |
18008 KB |
Output is correct |
30 |
Correct |
309 ms |
18068 KB |
Output is correct |
31 |
Correct |
312 ms |
18068 KB |
Output is correct |
32 |
Correct |
323 ms |
18020 KB |
Output is correct |
33 |
Correct |
307 ms |
17996 KB |
Output is correct |
34 |
Correct |
292 ms |
17732 KB |
Output is correct |
35 |
Correct |
293 ms |
17660 KB |
Output is correct |
36 |
Correct |
272 ms |
17468 KB |
Output is correct |
37 |
Correct |
278 ms |
17508 KB |
Output is correct |
38 |
Correct |
279 ms |
17688 KB |
Output is correct |
39 |
Correct |
296 ms |
16620 KB |
Output is correct |
40 |
Correct |
217 ms |
13296 KB |
Output is correct |
41 |
Correct |
258 ms |
16128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
716 KB |
Output is correct |
13 |
Correct |
6 ms |
716 KB |
Output is correct |
14 |
Correct |
7 ms |
844 KB |
Output is correct |
15 |
Correct |
9 ms |
844 KB |
Output is correct |
16 |
Correct |
7 ms |
840 KB |
Output is correct |
17 |
Correct |
5 ms |
844 KB |
Output is correct |
18 |
Correct |
6 ms |
716 KB |
Output is correct |
19 |
Correct |
2158 ms |
64284 KB |
Output is correct |
20 |
Correct |
2164 ms |
69028 KB |
Output is correct |
21 |
Correct |
2201 ms |
69060 KB |
Output is correct |
22 |
Correct |
2127 ms |
69012 KB |
Output is correct |
23 |
Correct |
1981 ms |
69176 KB |
Output is correct |
24 |
Correct |
194 ms |
7896 KB |
Output is correct |
25 |
Correct |
151 ms |
7852 KB |
Output is correct |
26 |
Correct |
139 ms |
7948 KB |
Output is correct |
27 |
Correct |
144 ms |
7896 KB |
Output is correct |
28 |
Correct |
135 ms |
7896 KB |
Output is correct |
29 |
Correct |
125 ms |
7732 KB |
Output is correct |
30 |
Correct |
122 ms |
7720 KB |
Output is correct |
31 |
Correct |
118 ms |
7628 KB |
Output is correct |
32 |
Correct |
59 ms |
3852 KB |
Output is correct |
33 |
Correct |
120 ms |
7588 KB |
Output is correct |
34 |
Correct |
343 ms |
18056 KB |
Output is correct |
35 |
Correct |
349 ms |
18088 KB |
Output is correct |
36 |
Correct |
334 ms |
17896 KB |
Output is correct |
37 |
Correct |
330 ms |
17820 KB |
Output is correct |
38 |
Correct |
335 ms |
17972 KB |
Output is correct |
39 |
Correct |
304 ms |
17816 KB |
Output is correct |
40 |
Correct |
299 ms |
17772 KB |
Output is correct |
41 |
Correct |
328 ms |
18008 KB |
Output is correct |
42 |
Correct |
307 ms |
18012 KB |
Output is correct |
43 |
Correct |
325 ms |
17948 KB |
Output is correct |
44 |
Correct |
306 ms |
18008 KB |
Output is correct |
45 |
Correct |
309 ms |
18068 KB |
Output is correct |
46 |
Correct |
312 ms |
18068 KB |
Output is correct |
47 |
Correct |
323 ms |
18020 KB |
Output is correct |
48 |
Correct |
307 ms |
17996 KB |
Output is correct |
49 |
Correct |
292 ms |
17732 KB |
Output is correct |
50 |
Correct |
293 ms |
17660 KB |
Output is correct |
51 |
Correct |
272 ms |
17468 KB |
Output is correct |
52 |
Correct |
278 ms |
17508 KB |
Output is correct |
53 |
Correct |
279 ms |
17688 KB |
Output is correct |
54 |
Correct |
296 ms |
16620 KB |
Output is correct |
55 |
Correct |
217 ms |
13296 KB |
Output is correct |
56 |
Correct |
258 ms |
16128 KB |
Output is correct |
57 |
Correct |
2164 ms |
69628 KB |
Output is correct |
58 |
Correct |
2182 ms |
69644 KB |
Output is correct |
59 |
Correct |
2101 ms |
69744 KB |
Output is correct |
60 |
Correct |
2153 ms |
69732 KB |
Output is correct |
61 |
Correct |
2162 ms |
69564 KB |
Output is correct |
62 |
Correct |
2184 ms |
69428 KB |
Output is correct |
63 |
Correct |
1699 ms |
64228 KB |
Output is correct |
64 |
Correct |
1681 ms |
64248 KB |
Output is correct |
65 |
Correct |
1770 ms |
81764 KB |
Output is correct |
66 |
Correct |
1748 ms |
87012 KB |
Output is correct |
67 |
Correct |
1766 ms |
87012 KB |
Output is correct |
68 |
Correct |
1777 ms |
87132 KB |
Output is correct |
69 |
Correct |
1794 ms |
87268 KB |
Output is correct |
70 |
Correct |
1745 ms |
87180 KB |
Output is correct |
71 |
Correct |
1725 ms |
87172 KB |
Output is correct |
72 |
Correct |
1771 ms |
87140 KB |
Output is correct |
73 |
Correct |
1461 ms |
64484 KB |
Output is correct |
74 |
Correct |
1493 ms |
70752 KB |
Output is correct |
75 |
Correct |
1429 ms |
64336 KB |
Output is correct |
76 |
Correct |
1467 ms |
83964 KB |
Output is correct |
77 |
Correct |
1442 ms |
83712 KB |
Output is correct |
78 |
Correct |
1589 ms |
64744 KB |
Output is correct |
79 |
Correct |
1055 ms |
61096 KB |
Output is correct |
80 |
Correct |
1432 ms |
78152 KB |
Output is correct |