#include <bits/stdc++.h>
using namespace std;
vector<int> seg(4000001);
vector<int> wow(4000001);
int calc(int l, int r, int ql, int qr, int x) {
if(l == ql && r == qr) {
return seg[x];
}
int m = (l+r)/2,ans = 0;
if(qr <= m) {
ans = calc(l,m,ql,qr,x*2+1);
}
else if(ql > m) {
ans = calc(m+1,r,ql,qr,x*2+2);
}
else {
ans = calc(l,m,ql,m,x*2+1);
ans = max(ans,calc(m+1,r,m+1,qr,x*2+2));
}
return max(ans,wow[x]);
}
void upd(int l, int r, int ql, int qr, int x, int a) {
if(l == ql && r == qr) {
wow[x] = max(wow[x],a);
seg[x] = max(seg[x],a);
return;
}
int m = (l+r)/2;
if(qr <= m) {
upd(l,m,ql,qr,x*2+1,a);
}
else if(ql > m) {
upd(m+1,r,ql,qr,x*2+2,a);
}
else {
upd(l,m,ql,m,x*2+1,a);
upd(m+1,r,m+1,qr,x*2+2,a);
}
seg[x] = max(seg[x*2+1],seg[x*2+2]);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,q,a,b,c,y = 0;
cin >> n >> q;
vector<pair<pair<int,int>,int>> bruh(0);
vector<int> haha(n+1,1e9+10);
vector<int> wow(q);
vector<int> ans(q);
for(int i = 1; i <= n; i++) {
cin >> haha[i];
}
for(int i = 0; i < q; i++) {
cin >> a >> b >> wow[i];
bruh.push_back({{b,a},i});
}
sort(bruh.begin(),bruh.end());
vector<pair<int,int>> idk(1,{haha[0],0});
for(int i = 1; i <= n; i++) {
while(haha[i] >= idk[idk.size()-1].first) {
idk.pop_back();
}
if(idk.size() > 1) {
upd(1,n,idk[idk.size()-2].second+1,idk[idk.size()-1].second,0,haha[i]+idk[idk.size()-1].first);
}
idk.push_back({haha[i],i});
while(y < q && bruh[y].first.first == i) {
int r = bruh[y].first.first,l = bruh[y].first.second;
ans[bruh[y].second] = calc(1,n,l,r,0);
y++;
}
}
for(int i = 0; i < q; i++) {
cout << (ans[i] <= wow[i]) << "\n";
}
return 0;
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:50:17: warning: unused variable 'c' [-Wunused-variable]
50 | int n,q,a,b,c,y = 0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
31580 KB |
Output is correct |
2 |
Correct |
5 ms |
31660 KB |
Output is correct |
3 |
Correct |
5 ms |
31580 KB |
Output is correct |
4 |
Correct |
6 ms |
31788 KB |
Output is correct |
5 |
Correct |
6 ms |
31576 KB |
Output is correct |
6 |
Correct |
6 ms |
31580 KB |
Output is correct |
7 |
Correct |
5 ms |
31580 KB |
Output is correct |
8 |
Correct |
6 ms |
31580 KB |
Output is correct |
9 |
Correct |
6 ms |
31580 KB |
Output is correct |
10 |
Correct |
5 ms |
31580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
31580 KB |
Output is correct |
2 |
Correct |
5 ms |
31660 KB |
Output is correct |
3 |
Correct |
5 ms |
31580 KB |
Output is correct |
4 |
Correct |
6 ms |
31788 KB |
Output is correct |
5 |
Correct |
6 ms |
31576 KB |
Output is correct |
6 |
Correct |
6 ms |
31580 KB |
Output is correct |
7 |
Correct |
5 ms |
31580 KB |
Output is correct |
8 |
Correct |
6 ms |
31580 KB |
Output is correct |
9 |
Correct |
6 ms |
31580 KB |
Output is correct |
10 |
Correct |
5 ms |
31580 KB |
Output is correct |
11 |
Correct |
7 ms |
31880 KB |
Output is correct |
12 |
Correct |
9 ms |
31832 KB |
Output is correct |
13 |
Correct |
8 ms |
31832 KB |
Output is correct |
14 |
Correct |
9 ms |
32088 KB |
Output is correct |
15 |
Correct |
9 ms |
32092 KB |
Output is correct |
16 |
Correct |
8 ms |
32100 KB |
Output is correct |
17 |
Correct |
7 ms |
32092 KB |
Output is correct |
18 |
Correct |
8 ms |
31836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
982 ms |
79792 KB |
Output is correct |
2 |
Correct |
952 ms |
87364 KB |
Output is correct |
3 |
Correct |
919 ms |
86872 KB |
Output is correct |
4 |
Correct |
955 ms |
87244 KB |
Output is correct |
5 |
Correct |
735 ms |
87332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
36232 KB |
Output is correct |
2 |
Correct |
77 ms |
36184 KB |
Output is correct |
3 |
Correct |
63 ms |
36292 KB |
Output is correct |
4 |
Correct |
63 ms |
36228 KB |
Output is correct |
5 |
Correct |
63 ms |
36232 KB |
Output is correct |
6 |
Correct |
60 ms |
36052 KB |
Output is correct |
7 |
Correct |
55 ms |
36040 KB |
Output is correct |
8 |
Correct |
64 ms |
35908 KB |
Output is correct |
9 |
Correct |
46 ms |
35176 KB |
Output is correct |
10 |
Correct |
64 ms |
36076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
31580 KB |
Output is correct |
2 |
Correct |
5 ms |
31660 KB |
Output is correct |
3 |
Correct |
5 ms |
31580 KB |
Output is correct |
4 |
Correct |
6 ms |
31788 KB |
Output is correct |
5 |
Correct |
6 ms |
31576 KB |
Output is correct |
6 |
Correct |
6 ms |
31580 KB |
Output is correct |
7 |
Correct |
5 ms |
31580 KB |
Output is correct |
8 |
Correct |
6 ms |
31580 KB |
Output is correct |
9 |
Correct |
6 ms |
31580 KB |
Output is correct |
10 |
Correct |
5 ms |
31580 KB |
Output is correct |
11 |
Correct |
7 ms |
31880 KB |
Output is correct |
12 |
Correct |
9 ms |
31832 KB |
Output is correct |
13 |
Correct |
8 ms |
31832 KB |
Output is correct |
14 |
Correct |
9 ms |
32088 KB |
Output is correct |
15 |
Correct |
9 ms |
32092 KB |
Output is correct |
16 |
Correct |
8 ms |
32100 KB |
Output is correct |
17 |
Correct |
7 ms |
32092 KB |
Output is correct |
18 |
Correct |
8 ms |
31836 KB |
Output is correct |
19 |
Correct |
170 ms |
43208 KB |
Output is correct |
20 |
Correct |
185 ms |
43196 KB |
Output is correct |
21 |
Correct |
170 ms |
43024 KB |
Output is correct |
22 |
Correct |
158 ms |
43020 KB |
Output is correct |
23 |
Correct |
160 ms |
43204 KB |
Output is correct |
24 |
Correct |
131 ms |
43532 KB |
Output is correct |
25 |
Correct |
130 ms |
43172 KB |
Output is correct |
26 |
Correct |
133 ms |
43108 KB |
Output is correct |
27 |
Correct |
133 ms |
43204 KB |
Output is correct |
28 |
Correct |
134 ms |
43204 KB |
Output is correct |
29 |
Correct |
159 ms |
43780 KB |
Output is correct |
30 |
Correct |
140 ms |
43168 KB |
Output is correct |
31 |
Correct |
140 ms |
43100 KB |
Output is correct |
32 |
Correct |
137 ms |
43460 KB |
Output is correct |
33 |
Correct |
146 ms |
43820 KB |
Output is correct |
34 |
Correct |
119 ms |
43716 KB |
Output is correct |
35 |
Correct |
119 ms |
43456 KB |
Output is correct |
36 |
Correct |
120 ms |
43056 KB |
Output is correct |
37 |
Correct |
117 ms |
43204 KB |
Output is correct |
38 |
Correct |
118 ms |
43112 KB |
Output is correct |
39 |
Correct |
147 ms |
41920 KB |
Output is correct |
40 |
Correct |
98 ms |
41144 KB |
Output is correct |
41 |
Correct |
130 ms |
42064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
31580 KB |
Output is correct |
2 |
Correct |
5 ms |
31660 KB |
Output is correct |
3 |
Correct |
5 ms |
31580 KB |
Output is correct |
4 |
Correct |
6 ms |
31788 KB |
Output is correct |
5 |
Correct |
6 ms |
31576 KB |
Output is correct |
6 |
Correct |
6 ms |
31580 KB |
Output is correct |
7 |
Correct |
5 ms |
31580 KB |
Output is correct |
8 |
Correct |
6 ms |
31580 KB |
Output is correct |
9 |
Correct |
6 ms |
31580 KB |
Output is correct |
10 |
Correct |
5 ms |
31580 KB |
Output is correct |
11 |
Correct |
7 ms |
31880 KB |
Output is correct |
12 |
Correct |
9 ms |
31832 KB |
Output is correct |
13 |
Correct |
8 ms |
31832 KB |
Output is correct |
14 |
Correct |
9 ms |
32088 KB |
Output is correct |
15 |
Correct |
9 ms |
32092 KB |
Output is correct |
16 |
Correct |
8 ms |
32100 KB |
Output is correct |
17 |
Correct |
7 ms |
32092 KB |
Output is correct |
18 |
Correct |
8 ms |
31836 KB |
Output is correct |
19 |
Correct |
982 ms |
79792 KB |
Output is correct |
20 |
Correct |
952 ms |
87364 KB |
Output is correct |
21 |
Correct |
919 ms |
86872 KB |
Output is correct |
22 |
Correct |
955 ms |
87244 KB |
Output is correct |
23 |
Correct |
735 ms |
87332 KB |
Output is correct |
24 |
Correct |
84 ms |
36232 KB |
Output is correct |
25 |
Correct |
77 ms |
36184 KB |
Output is correct |
26 |
Correct |
63 ms |
36292 KB |
Output is correct |
27 |
Correct |
63 ms |
36228 KB |
Output is correct |
28 |
Correct |
63 ms |
36232 KB |
Output is correct |
29 |
Correct |
60 ms |
36052 KB |
Output is correct |
30 |
Correct |
55 ms |
36040 KB |
Output is correct |
31 |
Correct |
64 ms |
35908 KB |
Output is correct |
32 |
Correct |
46 ms |
35176 KB |
Output is correct |
33 |
Correct |
64 ms |
36076 KB |
Output is correct |
34 |
Correct |
170 ms |
43208 KB |
Output is correct |
35 |
Correct |
185 ms |
43196 KB |
Output is correct |
36 |
Correct |
170 ms |
43024 KB |
Output is correct |
37 |
Correct |
158 ms |
43020 KB |
Output is correct |
38 |
Correct |
160 ms |
43204 KB |
Output is correct |
39 |
Correct |
131 ms |
43532 KB |
Output is correct |
40 |
Correct |
130 ms |
43172 KB |
Output is correct |
41 |
Correct |
133 ms |
43108 KB |
Output is correct |
42 |
Correct |
133 ms |
43204 KB |
Output is correct |
43 |
Correct |
134 ms |
43204 KB |
Output is correct |
44 |
Correct |
159 ms |
43780 KB |
Output is correct |
45 |
Correct |
140 ms |
43168 KB |
Output is correct |
46 |
Correct |
140 ms |
43100 KB |
Output is correct |
47 |
Correct |
137 ms |
43460 KB |
Output is correct |
48 |
Correct |
146 ms |
43820 KB |
Output is correct |
49 |
Correct |
119 ms |
43716 KB |
Output is correct |
50 |
Correct |
119 ms |
43456 KB |
Output is correct |
51 |
Correct |
120 ms |
43056 KB |
Output is correct |
52 |
Correct |
117 ms |
43204 KB |
Output is correct |
53 |
Correct |
118 ms |
43112 KB |
Output is correct |
54 |
Correct |
147 ms |
41920 KB |
Output is correct |
55 |
Correct |
98 ms |
41144 KB |
Output is correct |
56 |
Correct |
130 ms |
42064 KB |
Output is correct |
57 |
Correct |
926 ms |
88320 KB |
Output is correct |
58 |
Correct |
969 ms |
87892 KB |
Output is correct |
59 |
Correct |
927 ms |
87644 KB |
Output is correct |
60 |
Correct |
906 ms |
87728 KB |
Output is correct |
61 |
Correct |
909 ms |
87940 KB |
Output is correct |
62 |
Correct |
899 ms |
87700 KB |
Output is correct |
63 |
Correct |
612 ms |
85936 KB |
Output is correct |
64 |
Correct |
617 ms |
86344 KB |
Output is correct |
65 |
Correct |
706 ms |
87648 KB |
Output is correct |
66 |
Correct |
768 ms |
88244 KB |
Output is correct |
67 |
Correct |
699 ms |
87680 KB |
Output is correct |
68 |
Correct |
757 ms |
88068 KB |
Output is correct |
69 |
Correct |
791 ms |
87896 KB |
Output is correct |
70 |
Correct |
732 ms |
87644 KB |
Output is correct |
71 |
Correct |
761 ms |
87628 KB |
Output is correct |
72 |
Correct |
771 ms |
87744 KB |
Output is correct |
73 |
Correct |
617 ms |
85080 KB |
Output is correct |
74 |
Correct |
621 ms |
85664 KB |
Output is correct |
75 |
Correct |
624 ms |
84828 KB |
Output is correct |
76 |
Correct |
656 ms |
85096 KB |
Output is correct |
77 |
Correct |
610 ms |
84824 KB |
Output is correct |
78 |
Correct |
703 ms |
82508 KB |
Output is correct |
79 |
Correct |
498 ms |
75548 KB |
Output is correct |
80 |
Correct |
717 ms |
79544 KB |
Output is correct |