#include<bits/stdc++.h>
using namespace std;
#define N 1000005
struct ii{
int l, r, idx;
bool operator < (ii& o){
return l < o.l;
}
};
struct fw{
int n;
vector<int> bit;
fw(int siz){
n = siz;
bit.resize(n + 1, 0);
}
void ud(int pos, int val){
while (pos <= n){
bit[pos] = max(bit[pos], val);
pos += (pos & (-pos));
}
}
int get(int pos){
int rt = 0;
while (pos >= 1){
rt = max(rt, bit[pos]);
pos -= (pos & (-pos));
}
return rt;
}
};
int n, m, a[N], res[N];
vector<ii> vd, qr[N];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
stack<int> st;
cin >> n >> m;
for (int i = 1; i <= n; i++){
cin >> a[i];
while (st.size() && a[st.top()] <= a[i]) st.pop();
if (st.size()){
vd.push_back({st.top(), i, 0});
}
st.push(i);
}
for (int i = 1; i <= m; i++){
int l, r, k;
cin >> l >> r >> k;
qr[l].push_back({k, r, i});
}
sort(vd.begin(), vd.end());
int j = (int) vd.size();
fw s1(n);
for (int i = n; i >= 1; i--){
while (j - 1 >= 0 && vd[j - 1].l >= i){
j--;
s1.ud(vd[j].r, a[vd[j].l] + a[vd[j].r]);
}
for (auto x : qr[i]){
res[x.idx] = (s1.get(x.r) <= x.l);
}
}
for (int i = 1; i <= m; i++) cout << res[i] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23896 KB |
Output is correct |
2 |
Correct |
10 ms |
23900 KB |
Output is correct |
3 |
Correct |
13 ms |
23752 KB |
Output is correct |
4 |
Correct |
9 ms |
23932 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23900 KB |
Output is correct |
8 |
Correct |
10 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23904 KB |
Output is correct |
10 |
Correct |
9 ms |
23900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23896 KB |
Output is correct |
2 |
Correct |
10 ms |
23900 KB |
Output is correct |
3 |
Correct |
13 ms |
23752 KB |
Output is correct |
4 |
Correct |
9 ms |
23932 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23900 KB |
Output is correct |
8 |
Correct |
10 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23904 KB |
Output is correct |
10 |
Correct |
9 ms |
23900 KB |
Output is correct |
11 |
Correct |
13 ms |
23900 KB |
Output is correct |
12 |
Correct |
15 ms |
24228 KB |
Output is correct |
13 |
Correct |
12 ms |
24152 KB |
Output is correct |
14 |
Correct |
13 ms |
24156 KB |
Output is correct |
15 |
Correct |
14 ms |
24156 KB |
Output is correct |
16 |
Correct |
11 ms |
24156 KB |
Output is correct |
17 |
Correct |
11 ms |
24188 KB |
Output is correct |
18 |
Correct |
11 ms |
24156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
659 ms |
102964 KB |
Output is correct |
2 |
Correct |
627 ms |
104012 KB |
Output is correct |
3 |
Correct |
600 ms |
103852 KB |
Output is correct |
4 |
Correct |
672 ms |
103984 KB |
Output is correct |
5 |
Correct |
530 ms |
92104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
30636 KB |
Output is correct |
2 |
Correct |
52 ms |
30452 KB |
Output is correct |
3 |
Correct |
45 ms |
29268 KB |
Output is correct |
4 |
Correct |
47 ms |
29268 KB |
Output is correct |
5 |
Correct |
44 ms |
29520 KB |
Output is correct |
6 |
Correct |
35 ms |
28952 KB |
Output is correct |
7 |
Correct |
34 ms |
28956 KB |
Output is correct |
8 |
Correct |
48 ms |
29896 KB |
Output is correct |
9 |
Correct |
28 ms |
27148 KB |
Output is correct |
10 |
Correct |
42 ms |
29648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23896 KB |
Output is correct |
2 |
Correct |
10 ms |
23900 KB |
Output is correct |
3 |
Correct |
13 ms |
23752 KB |
Output is correct |
4 |
Correct |
9 ms |
23932 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23900 KB |
Output is correct |
8 |
Correct |
10 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23904 KB |
Output is correct |
10 |
Correct |
9 ms |
23900 KB |
Output is correct |
11 |
Correct |
13 ms |
23900 KB |
Output is correct |
12 |
Correct |
15 ms |
24228 KB |
Output is correct |
13 |
Correct |
12 ms |
24152 KB |
Output is correct |
14 |
Correct |
13 ms |
24156 KB |
Output is correct |
15 |
Correct |
14 ms |
24156 KB |
Output is correct |
16 |
Correct |
11 ms |
24156 KB |
Output is correct |
17 |
Correct |
11 ms |
24188 KB |
Output is correct |
18 |
Correct |
11 ms |
24156 KB |
Output is correct |
19 |
Correct |
113 ms |
40128 KB |
Output is correct |
20 |
Correct |
115 ms |
40000 KB |
Output is correct |
21 |
Correct |
96 ms |
39356 KB |
Output is correct |
22 |
Correct |
119 ms |
39400 KB |
Output is correct |
23 |
Correct |
99 ms |
39268 KB |
Output is correct |
24 |
Correct |
81 ms |
36944 KB |
Output is correct |
25 |
Correct |
80 ms |
36944 KB |
Output is correct |
26 |
Correct |
90 ms |
37088 KB |
Output is correct |
27 |
Correct |
89 ms |
37244 KB |
Output is correct |
28 |
Correct |
86 ms |
37204 KB |
Output is correct |
29 |
Correct |
92 ms |
37716 KB |
Output is correct |
30 |
Correct |
102 ms |
37712 KB |
Output is correct |
31 |
Correct |
94 ms |
37712 KB |
Output is correct |
32 |
Correct |
102 ms |
37712 KB |
Output is correct |
33 |
Correct |
100 ms |
37680 KB |
Output is correct |
34 |
Correct |
71 ms |
36076 KB |
Output is correct |
35 |
Correct |
77 ms |
36180 KB |
Output is correct |
36 |
Correct |
77 ms |
35968 KB |
Output is correct |
37 |
Correct |
71 ms |
36084 KB |
Output is correct |
38 |
Correct |
84 ms |
36184 KB |
Output is correct |
39 |
Correct |
94 ms |
36292 KB |
Output is correct |
40 |
Correct |
87 ms |
34300 KB |
Output is correct |
41 |
Correct |
84 ms |
37068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23896 KB |
Output is correct |
2 |
Correct |
10 ms |
23900 KB |
Output is correct |
3 |
Correct |
13 ms |
23752 KB |
Output is correct |
4 |
Correct |
9 ms |
23932 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23900 KB |
Output is correct |
8 |
Correct |
10 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23904 KB |
Output is correct |
10 |
Correct |
9 ms |
23900 KB |
Output is correct |
11 |
Correct |
13 ms |
23900 KB |
Output is correct |
12 |
Correct |
15 ms |
24228 KB |
Output is correct |
13 |
Correct |
12 ms |
24152 KB |
Output is correct |
14 |
Correct |
13 ms |
24156 KB |
Output is correct |
15 |
Correct |
14 ms |
24156 KB |
Output is correct |
16 |
Correct |
11 ms |
24156 KB |
Output is correct |
17 |
Correct |
11 ms |
24188 KB |
Output is correct |
18 |
Correct |
11 ms |
24156 KB |
Output is correct |
19 |
Correct |
659 ms |
102964 KB |
Output is correct |
20 |
Correct |
627 ms |
104012 KB |
Output is correct |
21 |
Correct |
600 ms |
103852 KB |
Output is correct |
22 |
Correct |
672 ms |
103984 KB |
Output is correct |
23 |
Correct |
530 ms |
92104 KB |
Output is correct |
24 |
Correct |
50 ms |
30636 KB |
Output is correct |
25 |
Correct |
52 ms |
30452 KB |
Output is correct |
26 |
Correct |
45 ms |
29268 KB |
Output is correct |
27 |
Correct |
47 ms |
29268 KB |
Output is correct |
28 |
Correct |
44 ms |
29520 KB |
Output is correct |
29 |
Correct |
35 ms |
28952 KB |
Output is correct |
30 |
Correct |
34 ms |
28956 KB |
Output is correct |
31 |
Correct |
48 ms |
29896 KB |
Output is correct |
32 |
Correct |
28 ms |
27148 KB |
Output is correct |
33 |
Correct |
42 ms |
29648 KB |
Output is correct |
34 |
Correct |
113 ms |
40128 KB |
Output is correct |
35 |
Correct |
115 ms |
40000 KB |
Output is correct |
36 |
Correct |
96 ms |
39356 KB |
Output is correct |
37 |
Correct |
119 ms |
39400 KB |
Output is correct |
38 |
Correct |
99 ms |
39268 KB |
Output is correct |
39 |
Correct |
81 ms |
36944 KB |
Output is correct |
40 |
Correct |
80 ms |
36944 KB |
Output is correct |
41 |
Correct |
90 ms |
37088 KB |
Output is correct |
42 |
Correct |
89 ms |
37244 KB |
Output is correct |
43 |
Correct |
86 ms |
37204 KB |
Output is correct |
44 |
Correct |
92 ms |
37716 KB |
Output is correct |
45 |
Correct |
102 ms |
37712 KB |
Output is correct |
46 |
Correct |
94 ms |
37712 KB |
Output is correct |
47 |
Correct |
102 ms |
37712 KB |
Output is correct |
48 |
Correct |
100 ms |
37680 KB |
Output is correct |
49 |
Correct |
71 ms |
36076 KB |
Output is correct |
50 |
Correct |
77 ms |
36180 KB |
Output is correct |
51 |
Correct |
77 ms |
35968 KB |
Output is correct |
52 |
Correct |
71 ms |
36084 KB |
Output is correct |
53 |
Correct |
84 ms |
36184 KB |
Output is correct |
54 |
Correct |
94 ms |
36292 KB |
Output is correct |
55 |
Correct |
87 ms |
34300 KB |
Output is correct |
56 |
Correct |
84 ms |
37068 KB |
Output is correct |
57 |
Correct |
679 ms |
105380 KB |
Output is correct |
58 |
Correct |
685 ms |
105124 KB |
Output is correct |
59 |
Correct |
630 ms |
103104 KB |
Output is correct |
60 |
Correct |
706 ms |
102524 KB |
Output is correct |
61 |
Correct |
697 ms |
100404 KB |
Output is correct |
62 |
Correct |
711 ms |
94120 KB |
Output is correct |
63 |
Correct |
351 ms |
85908 KB |
Output is correct |
64 |
Correct |
392 ms |
85784 KB |
Output is correct |
65 |
Correct |
581 ms |
91480 KB |
Output is correct |
66 |
Correct |
585 ms |
91404 KB |
Output is correct |
67 |
Correct |
579 ms |
91532 KB |
Output is correct |
68 |
Correct |
665 ms |
93528 KB |
Output is correct |
69 |
Correct |
616 ms |
93576 KB |
Output is correct |
70 |
Correct |
635 ms |
93284 KB |
Output is correct |
71 |
Correct |
619 ms |
93184 KB |
Output is correct |
72 |
Correct |
655 ms |
93000 KB |
Output is correct |
73 |
Correct |
323 ms |
83472 KB |
Output is correct |
74 |
Correct |
331 ms |
84212 KB |
Output is correct |
75 |
Correct |
311 ms |
83284 KB |
Output is correct |
76 |
Correct |
348 ms |
83436 KB |
Output is correct |
77 |
Correct |
337 ms |
83548 KB |
Output is correct |
78 |
Correct |
544 ms |
87384 KB |
Output is correct |
79 |
Correct |
406 ms |
74456 KB |
Output is correct |
80 |
Correct |
540 ms |
89136 KB |
Output is correct |