#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define f first
#define s second
const int mxN = 1e6;
int n;
int bit[mxN+1];
void upd(int x, int v){
while (x > 0){
// cout << x << '\n';
bit[x] = max(bit[x],v);
x -= ((~x+1) & x);
}
}
int query(int x){
int res = 0;
while (x <= n){
// cout << x << '\n';
res = max(res,bit[x]);
x += ((~x+1) & x);
}
return res;
}
struct qu {
int l,r,k,idx;
};
int main()
{
memset(bit,0,sizeof(bit));
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int m;
cin >> n >> m;
int vals[n+1];
vector<qu> all[n+1];
for (int i =1; i <= n; i++) cin >> vals[i];
vals[0] = 1e9+1;
bitset<mxN> ans;
qu temp;
for (int i =0; i < m; i++){
cin >> temp.l >> temp.r >> temp.k;
temp.idx = i;
all[temp.r].pb(temp);
}
// cout << "Read\n";
stack<int> curr;
curr.push(0);
for (int i = 1; i <= n; i++){
while (vals[curr.top()] <= vals[i]) curr.pop();
upd(curr.top(),vals[curr.top()]+vals[i]);
curr.push(i);
for (qu c : all[i]){
ans[c.idx] = query(c.l) <= c.k;
}
}
for (int i =0; i < m; i++) cout << ans[i] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
2 ms |
4440 KB |
Output is correct |
10 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
2 ms |
4440 KB |
Output is correct |
10 |
Correct |
2 ms |
4444 KB |
Output is correct |
11 |
Correct |
3 ms |
4440 KB |
Output is correct |
12 |
Correct |
3 ms |
4700 KB |
Output is correct |
13 |
Correct |
3 ms |
4700 KB |
Output is correct |
14 |
Correct |
3 ms |
4700 KB |
Output is correct |
15 |
Correct |
3 ms |
4700 KB |
Output is correct |
16 |
Correct |
3 ms |
4696 KB |
Output is correct |
17 |
Correct |
4 ms |
4700 KB |
Output is correct |
18 |
Correct |
3 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
649 ms |
59916 KB |
Output is correct |
2 |
Correct |
715 ms |
89280 KB |
Output is correct |
3 |
Correct |
723 ms |
89356 KB |
Output is correct |
4 |
Correct |
701 ms |
89076 KB |
Output is correct |
5 |
Correct |
641 ms |
91940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
9852 KB |
Output is correct |
2 |
Correct |
38 ms |
9812 KB |
Output is correct |
3 |
Correct |
39 ms |
9852 KB |
Output is correct |
4 |
Correct |
37 ms |
9964 KB |
Output is correct |
5 |
Correct |
38 ms |
9808 KB |
Output is correct |
6 |
Correct |
35 ms |
9552 KB |
Output is correct |
7 |
Correct |
31 ms |
9608 KB |
Output is correct |
8 |
Correct |
36 ms |
9936 KB |
Output is correct |
9 |
Correct |
24 ms |
6600 KB |
Output is correct |
10 |
Correct |
36 ms |
9940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
2 ms |
4440 KB |
Output is correct |
10 |
Correct |
2 ms |
4444 KB |
Output is correct |
11 |
Correct |
3 ms |
4440 KB |
Output is correct |
12 |
Correct |
3 ms |
4700 KB |
Output is correct |
13 |
Correct |
3 ms |
4700 KB |
Output is correct |
14 |
Correct |
3 ms |
4700 KB |
Output is correct |
15 |
Correct |
3 ms |
4700 KB |
Output is correct |
16 |
Correct |
3 ms |
4696 KB |
Output is correct |
17 |
Correct |
4 ms |
4700 KB |
Output is correct |
18 |
Correct |
3 ms |
4700 KB |
Output is correct |
19 |
Correct |
107 ms |
15368 KB |
Output is correct |
20 |
Correct |
97 ms |
15336 KB |
Output is correct |
21 |
Correct |
87 ms |
15184 KB |
Output is correct |
22 |
Correct |
85 ms |
15184 KB |
Output is correct |
23 |
Correct |
86 ms |
15184 KB |
Output is correct |
24 |
Correct |
78 ms |
14992 KB |
Output is correct |
25 |
Correct |
85 ms |
15148 KB |
Output is correct |
26 |
Correct |
88 ms |
15136 KB |
Output is correct |
27 |
Correct |
98 ms |
15456 KB |
Output is correct |
28 |
Correct |
84 ms |
15080 KB |
Output is correct |
29 |
Correct |
94 ms |
15460 KB |
Output is correct |
30 |
Correct |
92 ms |
15440 KB |
Output is correct |
31 |
Correct |
88 ms |
15348 KB |
Output is correct |
32 |
Correct |
90 ms |
15364 KB |
Output is correct |
33 |
Correct |
88 ms |
15320 KB |
Output is correct |
34 |
Correct |
72 ms |
14676 KB |
Output is correct |
35 |
Correct |
91 ms |
14812 KB |
Output is correct |
36 |
Correct |
77 ms |
14640 KB |
Output is correct |
37 |
Correct |
72 ms |
14568 KB |
Output is correct |
38 |
Correct |
74 ms |
14676 KB |
Output is correct |
39 |
Correct |
95 ms |
14928 KB |
Output is correct |
40 |
Correct |
72 ms |
12736 KB |
Output is correct |
41 |
Correct |
80 ms |
15440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
2 ms |
4440 KB |
Output is correct |
10 |
Correct |
2 ms |
4444 KB |
Output is correct |
11 |
Correct |
3 ms |
4440 KB |
Output is correct |
12 |
Correct |
3 ms |
4700 KB |
Output is correct |
13 |
Correct |
3 ms |
4700 KB |
Output is correct |
14 |
Correct |
3 ms |
4700 KB |
Output is correct |
15 |
Correct |
3 ms |
4700 KB |
Output is correct |
16 |
Correct |
3 ms |
4696 KB |
Output is correct |
17 |
Correct |
4 ms |
4700 KB |
Output is correct |
18 |
Correct |
3 ms |
4700 KB |
Output is correct |
19 |
Correct |
649 ms |
59916 KB |
Output is correct |
20 |
Correct |
715 ms |
89280 KB |
Output is correct |
21 |
Correct |
723 ms |
89356 KB |
Output is correct |
22 |
Correct |
701 ms |
89076 KB |
Output is correct |
23 |
Correct |
641 ms |
91940 KB |
Output is correct |
24 |
Correct |
42 ms |
9852 KB |
Output is correct |
25 |
Correct |
38 ms |
9812 KB |
Output is correct |
26 |
Correct |
39 ms |
9852 KB |
Output is correct |
27 |
Correct |
37 ms |
9964 KB |
Output is correct |
28 |
Correct |
38 ms |
9808 KB |
Output is correct |
29 |
Correct |
35 ms |
9552 KB |
Output is correct |
30 |
Correct |
31 ms |
9608 KB |
Output is correct |
31 |
Correct |
36 ms |
9936 KB |
Output is correct |
32 |
Correct |
24 ms |
6600 KB |
Output is correct |
33 |
Correct |
36 ms |
9940 KB |
Output is correct |
34 |
Correct |
107 ms |
15368 KB |
Output is correct |
35 |
Correct |
97 ms |
15336 KB |
Output is correct |
36 |
Correct |
87 ms |
15184 KB |
Output is correct |
37 |
Correct |
85 ms |
15184 KB |
Output is correct |
38 |
Correct |
86 ms |
15184 KB |
Output is correct |
39 |
Correct |
78 ms |
14992 KB |
Output is correct |
40 |
Correct |
85 ms |
15148 KB |
Output is correct |
41 |
Correct |
88 ms |
15136 KB |
Output is correct |
42 |
Correct |
98 ms |
15456 KB |
Output is correct |
43 |
Correct |
84 ms |
15080 KB |
Output is correct |
44 |
Correct |
94 ms |
15460 KB |
Output is correct |
45 |
Correct |
92 ms |
15440 KB |
Output is correct |
46 |
Correct |
88 ms |
15348 KB |
Output is correct |
47 |
Correct |
90 ms |
15364 KB |
Output is correct |
48 |
Correct |
88 ms |
15320 KB |
Output is correct |
49 |
Correct |
72 ms |
14676 KB |
Output is correct |
50 |
Correct |
91 ms |
14812 KB |
Output is correct |
51 |
Correct |
77 ms |
14640 KB |
Output is correct |
52 |
Correct |
72 ms |
14568 KB |
Output is correct |
53 |
Correct |
74 ms |
14676 KB |
Output is correct |
54 |
Correct |
95 ms |
14928 KB |
Output is correct |
55 |
Correct |
72 ms |
12736 KB |
Output is correct |
56 |
Correct |
80 ms |
15440 KB |
Output is correct |
57 |
Correct |
678 ms |
93008 KB |
Output is correct |
58 |
Correct |
690 ms |
93140 KB |
Output is correct |
59 |
Correct |
615 ms |
92256 KB |
Output is correct |
60 |
Correct |
603 ms |
92148 KB |
Output is correct |
61 |
Correct |
613 ms |
92364 KB |
Output is correct |
62 |
Correct |
634 ms |
92144 KB |
Output is correct |
63 |
Correct |
437 ms |
89680 KB |
Output is correct |
64 |
Correct |
408 ms |
89864 KB |
Output is correct |
65 |
Correct |
584 ms |
92148 KB |
Output is correct |
66 |
Correct |
670 ms |
92044 KB |
Output is correct |
67 |
Correct |
592 ms |
92240 KB |
Output is correct |
68 |
Correct |
673 ms |
92956 KB |
Output is correct |
69 |
Correct |
659 ms |
93116 KB |
Output is correct |
70 |
Correct |
685 ms |
92756 KB |
Output is correct |
71 |
Correct |
675 ms |
92752 KB |
Output is correct |
72 |
Correct |
642 ms |
92752 KB |
Output is correct |
73 |
Correct |
390 ms |
84584 KB |
Output is correct |
74 |
Correct |
412 ms |
85668 KB |
Output is correct |
75 |
Correct |
379 ms |
84816 KB |
Output is correct |
76 |
Correct |
379 ms |
84820 KB |
Output is correct |
77 |
Correct |
374 ms |
84516 KB |
Output is correct |
78 |
Correct |
609 ms |
84660 KB |
Output is correct |
79 |
Correct |
448 ms |
64416 KB |
Output is correct |
80 |
Correct |
560 ms |
82764 KB |
Output is correct |