#include <bits/stdc++.h>
using namespace std;
struct node{
int s,e,v;
node *l,*r;
node (int _s, int _e){
s = _s; e = _e;
if (s!=e){
l = new node(s,(s+e)/2);
r = new node((s+e)/2+1,e);
}
v = -1;
}
void upd(int pos, int val){
if (s==e) {v = max(v,val);return;}
if (pos<=(s+e)/2) l->upd(pos,val);
else r->upd(pos,val);
v = max(l->v,r->v);
}
int que(int a, int b){
if (a<=s && e<=b) return v;
if (b<=(s+e)/2) return l->que(a,b);
if (a>(s+e)/2) return r->que(a,b);
return max(l->que(a,b),r->que(a,b));
}
}*root;
stack<int> thing;
int val[1000005];
int ans[1000005];
vector<pair<pair<int,int>,pair<int,int> > > qu;
vector<pair<int,int> > things;
bool cmp(pair<int,int> a, pair<int,int> b){
if (a.second==b.second) return a.first<b.first;
return a.second<b.second;
}
bool cmp2(pair<pair<int,int>,pair<int,int> > a, pair<pair<int,int>,pair<int,int> >b){
return cmp(a.first,b.first);
}
void input(int &a){
a = 0;
char ch = ' ';
while (ch<'0' || ch>'9'){
ch = getchar();
}
while (ch>='0' && ch<='9'){
a = (a<<3) + (a<<1) + ch - '0';
ch = getchar();
}
}
int main(){
int n,m;
input(n);
input(m);
for (int x = 0; x<n; x++){
input(val[x]);
}
for (int x = 0; x<n; x++){
while ((!thing.empty()) && val[thing.top()]<=val[x]){
thing.pop();
}
if (!thing.empty()){
things.push_back({thing.top(),x});
}
thing.push(x);
}
sort(things.begin(),things.end(),cmp);
root = new node(0,n);
for (int T = 0; T<m; T++){
int a,b,c;
input(a); input(b); input(c);
a--;b--;
qu.push_back({{a,b},{c,T}});
}
sort(qu.begin(),qu.end(),cmp2);
int c = 0;
for (auto&x:qu){
while (c!=things.size() && x.first.second>=things[c].second){
int v = root->que(things[c].first,things[c].first);
if (v<val[things[c].first]+val[things[c].second]){
root->upd(things[c].first,val[things[c].first]+val[things[c].second]);
}
c++;
}
ans[x.second.second] = root->que(x.first.first,x.first.second)<=x.second.first;
}
for (int x = 0; x<m; x++){
printf("%d\n",ans[x]);
}
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:83:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | while (c!=things.size() && x.first.second>=things[c].second){
| ~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
640 KB |
Output is correct |
12 |
Correct |
4 ms |
1024 KB |
Output is correct |
13 |
Correct |
5 ms |
1024 KB |
Output is correct |
14 |
Correct |
6 ms |
1280 KB |
Output is correct |
15 |
Correct |
6 ms |
1280 KB |
Output is correct |
16 |
Correct |
5 ms |
1152 KB |
Output is correct |
17 |
Correct |
5 ms |
1100 KB |
Output is correct |
18 |
Correct |
4 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1987 ms |
128484 KB |
Output is correct |
2 |
Correct |
2056 ms |
128708 KB |
Output is correct |
3 |
Correct |
1997 ms |
128472 KB |
Output is correct |
4 |
Correct |
1977 ms |
128568 KB |
Output is correct |
5 |
Correct |
1684 ms |
120540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
14696 KB |
Output is correct |
2 |
Correct |
124 ms |
13920 KB |
Output is correct |
3 |
Correct |
99 ms |
13208 KB |
Output is correct |
4 |
Correct |
104 ms |
13240 KB |
Output is correct |
5 |
Correct |
103 ms |
13228 KB |
Output is correct |
6 |
Correct |
83 ms |
13164 KB |
Output is correct |
7 |
Correct |
83 ms |
13164 KB |
Output is correct |
8 |
Correct |
97 ms |
13544 KB |
Output is correct |
9 |
Correct |
47 ms |
3304 KB |
Output is correct |
10 |
Correct |
96 ms |
13548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
640 KB |
Output is correct |
12 |
Correct |
4 ms |
1024 KB |
Output is correct |
13 |
Correct |
5 ms |
1024 KB |
Output is correct |
14 |
Correct |
6 ms |
1280 KB |
Output is correct |
15 |
Correct |
6 ms |
1280 KB |
Output is correct |
16 |
Correct |
5 ms |
1152 KB |
Output is correct |
17 |
Correct |
5 ms |
1100 KB |
Output is correct |
18 |
Correct |
4 ms |
1152 KB |
Output is correct |
19 |
Correct |
340 ms |
27228 KB |
Output is correct |
20 |
Correct |
327 ms |
27228 KB |
Output is correct |
21 |
Correct |
282 ms |
27228 KB |
Output is correct |
22 |
Correct |
287 ms |
27356 KB |
Output is correct |
23 |
Correct |
294 ms |
27228 KB |
Output is correct |
24 |
Correct |
209 ms |
25692 KB |
Output is correct |
25 |
Correct |
211 ms |
25692 KB |
Output is correct |
26 |
Correct |
248 ms |
25820 KB |
Output is correct |
27 |
Correct |
255 ms |
26204 KB |
Output is correct |
28 |
Correct |
251 ms |
26204 KB |
Output is correct |
29 |
Correct |
268 ms |
26204 KB |
Output is correct |
30 |
Correct |
257 ms |
26204 KB |
Output is correct |
31 |
Correct |
277 ms |
26204 KB |
Output is correct |
32 |
Correct |
267 ms |
26204 KB |
Output is correct |
33 |
Correct |
269 ms |
26256 KB |
Output is correct |
34 |
Correct |
208 ms |
26300 KB |
Output is correct |
35 |
Correct |
206 ms |
26328 KB |
Output is correct |
36 |
Correct |
202 ms |
26168 KB |
Output is correct |
37 |
Correct |
201 ms |
26204 KB |
Output is correct |
38 |
Correct |
206 ms |
26208 KB |
Output is correct |
39 |
Correct |
257 ms |
26840 KB |
Output is correct |
40 |
Correct |
192 ms |
19808 KB |
Output is correct |
41 |
Correct |
226 ms |
27104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
640 KB |
Output is correct |
12 |
Correct |
4 ms |
1024 KB |
Output is correct |
13 |
Correct |
5 ms |
1024 KB |
Output is correct |
14 |
Correct |
6 ms |
1280 KB |
Output is correct |
15 |
Correct |
6 ms |
1280 KB |
Output is correct |
16 |
Correct |
5 ms |
1152 KB |
Output is correct |
17 |
Correct |
5 ms |
1100 KB |
Output is correct |
18 |
Correct |
4 ms |
1152 KB |
Output is correct |
19 |
Correct |
1987 ms |
128484 KB |
Output is correct |
20 |
Correct |
2056 ms |
128708 KB |
Output is correct |
21 |
Correct |
1997 ms |
128472 KB |
Output is correct |
22 |
Correct |
1977 ms |
128568 KB |
Output is correct |
23 |
Correct |
1684 ms |
120540 KB |
Output is correct |
24 |
Correct |
133 ms |
14696 KB |
Output is correct |
25 |
Correct |
124 ms |
13920 KB |
Output is correct |
26 |
Correct |
99 ms |
13208 KB |
Output is correct |
27 |
Correct |
104 ms |
13240 KB |
Output is correct |
28 |
Correct |
103 ms |
13228 KB |
Output is correct |
29 |
Correct |
83 ms |
13164 KB |
Output is correct |
30 |
Correct |
83 ms |
13164 KB |
Output is correct |
31 |
Correct |
97 ms |
13544 KB |
Output is correct |
32 |
Correct |
47 ms |
3304 KB |
Output is correct |
33 |
Correct |
96 ms |
13548 KB |
Output is correct |
34 |
Correct |
340 ms |
27228 KB |
Output is correct |
35 |
Correct |
327 ms |
27228 KB |
Output is correct |
36 |
Correct |
282 ms |
27228 KB |
Output is correct |
37 |
Correct |
287 ms |
27356 KB |
Output is correct |
38 |
Correct |
294 ms |
27228 KB |
Output is correct |
39 |
Correct |
209 ms |
25692 KB |
Output is correct |
40 |
Correct |
211 ms |
25692 KB |
Output is correct |
41 |
Correct |
248 ms |
25820 KB |
Output is correct |
42 |
Correct |
255 ms |
26204 KB |
Output is correct |
43 |
Correct |
251 ms |
26204 KB |
Output is correct |
44 |
Correct |
268 ms |
26204 KB |
Output is correct |
45 |
Correct |
257 ms |
26204 KB |
Output is correct |
46 |
Correct |
277 ms |
26204 KB |
Output is correct |
47 |
Correct |
267 ms |
26204 KB |
Output is correct |
48 |
Correct |
269 ms |
26256 KB |
Output is correct |
49 |
Correct |
208 ms |
26300 KB |
Output is correct |
50 |
Correct |
206 ms |
26328 KB |
Output is correct |
51 |
Correct |
202 ms |
26168 KB |
Output is correct |
52 |
Correct |
201 ms |
26204 KB |
Output is correct |
53 |
Correct |
206 ms |
26208 KB |
Output is correct |
54 |
Correct |
257 ms |
26840 KB |
Output is correct |
55 |
Correct |
192 ms |
19808 KB |
Output is correct |
56 |
Correct |
226 ms |
27104 KB |
Output is correct |
57 |
Correct |
2004 ms |
129400 KB |
Output is correct |
58 |
Correct |
1971 ms |
129524 KB |
Output is correct |
59 |
Correct |
1895 ms |
129584 KB |
Output is correct |
60 |
Correct |
1905 ms |
129524 KB |
Output is correct |
61 |
Correct |
1912 ms |
129588 KB |
Output is correct |
62 |
Correct |
1961 ms |
129520 KB |
Output is correct |
63 |
Correct |
1130 ms |
121660 KB |
Output is correct |
64 |
Correct |
1138 ms |
121532 KB |
Output is correct |
65 |
Correct |
1573 ms |
121532 KB |
Output is correct |
66 |
Correct |
1571 ms |
121404 KB |
Output is correct |
67 |
Correct |
1554 ms |
121148 KB |
Output is correct |
68 |
Correct |
1631 ms |
121124 KB |
Output is correct |
69 |
Correct |
1651 ms |
121024 KB |
Output is correct |
70 |
Correct |
1650 ms |
121020 KB |
Output is correct |
71 |
Correct |
1654 ms |
121036 KB |
Output is correct |
72 |
Correct |
1662 ms |
121020 KB |
Output is correct |
73 |
Correct |
1099 ms |
121020 KB |
Output is correct |
74 |
Correct |
1126 ms |
121020 KB |
Output is correct |
75 |
Correct |
1103 ms |
121128 KB |
Output is correct |
76 |
Correct |
1088 ms |
121180 KB |
Output is correct |
77 |
Correct |
1076 ms |
121148 KB |
Output is correct |
78 |
Correct |
1516 ms |
123796 KB |
Output is correct |
79 |
Correct |
1081 ms |
75528 KB |
Output is correct |
80 |
Correct |
1394 ms |
126664 KB |
Output is correct |