//Dedicated to my love, ivaziva
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = int64_t;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define dbg(x) cerr << #x << ": " << x << '\n';
const int N = 1e6 + 20;
int maxi[4*N];
void updateMax(int v,int tl,int tr,int i,int x){
if(tl==tr){
maxi[v]=x;
return;
}
int mid=(tl+tr)/2;
if(i<=mid) updateMax(2*v,tl,mid,i,x);
else updateMax(2*v+1,mid+1,tr,i,x);
maxi[v]=max(maxi[2*v],maxi[2*v+1]);
}
int Max(int v,int tl,int tr,int l,int r){
if(l>r) return 0;
if(tl==l&&tr==r) return maxi[v];
int mid=(tl+tr)/2;
return max(Max(2*v,tl,mid,l,min(mid,r)),Max(2*v+1,mid+1,tr,max(mid+1,l),r));
}
struct qry {
int l, r, k, i;
};
bool cmp(qry x, qry y) {
return x.r < y.r;
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cout.tie(nullptr); cerr.tie(nullptr);
int n, q;
cin >> n >> q;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
stack<int> stk;
vector<int> b(n + 1);
for (int i = 1; i <= n; i++) {
while (!stk.empty() && a[i] >= a[stk.top()]) {
stk.pop();
}
if (!stk.empty()) {
b[i] = stk.top();
}
stk.push(i);
}
vector<qry> qu;
for (int i = 1; i <= q; i++) {
int l, r, k;
cin >> l >> r >> k;
qu.push_back({l, r, k, i});
}
sort(all(qu), cmp);
int j = 1;
vector<int> ans(q + 1, 0);
for (auto x : qu) {
while (j <= x.r) {
if (b[j] == 0) {
;
}
else {
updateMax(1, 1, n, b[j], a[j] + a[b[j]]);
}
j++;
}
ans[x.i] = Max(1, 1, n, x.l, x.r);
if (ans[x.i] <= x.k) {
ans[x.i] = 1;
} else {
ans[x.i] = 0;
}
}
for (int i = 1; i <= q; i++) {
cout << ans[i] << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
476 KB |
Output is correct |
9 |
Correct |
1 ms |
476 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
476 KB |
Output is correct |
9 |
Correct |
1 ms |
476 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
792 KB |
Output is correct |
14 |
Correct |
3 ms |
856 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
2 ms |
860 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
3 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
738 ms |
69796 KB |
Output is correct |
2 |
Correct |
739 ms |
70868 KB |
Output is correct |
3 |
Correct |
770 ms |
70740 KB |
Output is correct |
4 |
Correct |
738 ms |
70872 KB |
Output is correct |
5 |
Correct |
629 ms |
62540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
6348 KB |
Output is correct |
2 |
Correct |
57 ms |
6344 KB |
Output is correct |
3 |
Correct |
55 ms |
5192 KB |
Output is correct |
4 |
Correct |
52 ms |
5320 KB |
Output is correct |
5 |
Correct |
54 ms |
5208 KB |
Output is correct |
6 |
Correct |
48 ms |
5068 KB |
Output is correct |
7 |
Correct |
45 ms |
5068 KB |
Output is correct |
8 |
Correct |
47 ms |
5068 KB |
Output is correct |
9 |
Correct |
28 ms |
3784 KB |
Output is correct |
10 |
Correct |
51 ms |
4908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
476 KB |
Output is correct |
9 |
Correct |
1 ms |
476 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
792 KB |
Output is correct |
14 |
Correct |
3 ms |
856 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
2 ms |
860 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
3 ms |
856 KB |
Output is correct |
19 |
Correct |
134 ms |
14824 KB |
Output is correct |
20 |
Correct |
141 ms |
14780 KB |
Output is correct |
21 |
Correct |
129 ms |
14680 KB |
Output is correct |
22 |
Correct |
127 ms |
14716 KB |
Output is correct |
23 |
Correct |
125 ms |
14664 KB |
Output is correct |
24 |
Correct |
111 ms |
12484 KB |
Output is correct |
25 |
Correct |
114 ms |
12476 KB |
Output is correct |
26 |
Correct |
124 ms |
12736 KB |
Output is correct |
27 |
Correct |
118 ms |
12740 KB |
Output is correct |
28 |
Correct |
124 ms |
12740 KB |
Output is correct |
29 |
Correct |
121 ms |
12860 KB |
Output is correct |
30 |
Correct |
128 ms |
12736 KB |
Output is correct |
31 |
Correct |
125 ms |
12736 KB |
Output is correct |
32 |
Correct |
123 ms |
12784 KB |
Output is correct |
33 |
Correct |
121 ms |
12916 KB |
Output is correct |
34 |
Correct |
101 ms |
12484 KB |
Output is correct |
35 |
Correct |
104 ms |
12476 KB |
Output is correct |
36 |
Correct |
101 ms |
12340 KB |
Output is correct |
37 |
Correct |
104 ms |
12228 KB |
Output is correct |
38 |
Correct |
102 ms |
12484 KB |
Output is correct |
39 |
Correct |
110 ms |
12216 KB |
Output is correct |
40 |
Correct |
83 ms |
10180 KB |
Output is correct |
41 |
Correct |
97 ms |
10948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
476 KB |
Output is correct |
9 |
Correct |
1 ms |
476 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
792 KB |
Output is correct |
14 |
Correct |
3 ms |
856 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
2 ms |
860 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
3 ms |
856 KB |
Output is correct |
19 |
Correct |
738 ms |
69796 KB |
Output is correct |
20 |
Correct |
739 ms |
70868 KB |
Output is correct |
21 |
Correct |
770 ms |
70740 KB |
Output is correct |
22 |
Correct |
738 ms |
70872 KB |
Output is correct |
23 |
Correct |
629 ms |
62540 KB |
Output is correct |
24 |
Correct |
60 ms |
6348 KB |
Output is correct |
25 |
Correct |
57 ms |
6344 KB |
Output is correct |
26 |
Correct |
55 ms |
5192 KB |
Output is correct |
27 |
Correct |
52 ms |
5320 KB |
Output is correct |
28 |
Correct |
54 ms |
5208 KB |
Output is correct |
29 |
Correct |
48 ms |
5068 KB |
Output is correct |
30 |
Correct |
45 ms |
5068 KB |
Output is correct |
31 |
Correct |
47 ms |
5068 KB |
Output is correct |
32 |
Correct |
28 ms |
3784 KB |
Output is correct |
33 |
Correct |
51 ms |
4908 KB |
Output is correct |
34 |
Correct |
134 ms |
14824 KB |
Output is correct |
35 |
Correct |
141 ms |
14780 KB |
Output is correct |
36 |
Correct |
129 ms |
14680 KB |
Output is correct |
37 |
Correct |
127 ms |
14716 KB |
Output is correct |
38 |
Correct |
125 ms |
14664 KB |
Output is correct |
39 |
Correct |
111 ms |
12484 KB |
Output is correct |
40 |
Correct |
114 ms |
12476 KB |
Output is correct |
41 |
Correct |
124 ms |
12736 KB |
Output is correct |
42 |
Correct |
118 ms |
12740 KB |
Output is correct |
43 |
Correct |
124 ms |
12740 KB |
Output is correct |
44 |
Correct |
121 ms |
12860 KB |
Output is correct |
45 |
Correct |
128 ms |
12736 KB |
Output is correct |
46 |
Correct |
125 ms |
12736 KB |
Output is correct |
47 |
Correct |
123 ms |
12784 KB |
Output is correct |
48 |
Correct |
121 ms |
12916 KB |
Output is correct |
49 |
Correct |
101 ms |
12484 KB |
Output is correct |
50 |
Correct |
104 ms |
12476 KB |
Output is correct |
51 |
Correct |
101 ms |
12340 KB |
Output is correct |
52 |
Correct |
104 ms |
12228 KB |
Output is correct |
53 |
Correct |
102 ms |
12484 KB |
Output is correct |
54 |
Correct |
110 ms |
12216 KB |
Output is correct |
55 |
Correct |
83 ms |
10180 KB |
Output is correct |
56 |
Correct |
97 ms |
10948 KB |
Output is correct |
57 |
Correct |
749 ms |
71560 KB |
Output is correct |
58 |
Correct |
755 ms |
71460 KB |
Output is correct |
59 |
Correct |
708 ms |
71660 KB |
Output is correct |
60 |
Correct |
734 ms |
71584 KB |
Output is correct |
61 |
Correct |
715 ms |
71332 KB |
Output is correct |
62 |
Correct |
754 ms |
71464 KB |
Output is correct |
63 |
Correct |
551 ms |
61352 KB |
Output is correct |
64 |
Correct |
555 ms |
61652 KB |
Output is correct |
65 |
Correct |
618 ms |
63056 KB |
Output is correct |
66 |
Correct |
649 ms |
63088 KB |
Output is correct |
67 |
Correct |
660 ms |
63136 KB |
Output is correct |
68 |
Correct |
651 ms |
63180 KB |
Output is correct |
69 |
Correct |
669 ms |
63348 KB |
Output is correct |
70 |
Correct |
662 ms |
63328 KB |
Output is correct |
71 |
Correct |
647 ms |
63324 KB |
Output is correct |
72 |
Correct |
647 ms |
63332 KB |
Output is correct |
73 |
Correct |
528 ms |
59880 KB |
Output is correct |
74 |
Correct |
557 ms |
60836 KB |
Output is correct |
75 |
Correct |
533 ms |
59808 KB |
Output is correct |
76 |
Correct |
534 ms |
59976 KB |
Output is correct |
77 |
Correct |
537 ms |
59988 KB |
Output is correct |
78 |
Correct |
561 ms |
59860 KB |
Output is correct |
79 |
Correct |
421 ms |
48548 KB |
Output is correct |
80 |
Correct |
538 ms |
54436 KB |
Output is correct |