#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define tii array<int,3>
struct Query {
int l, r, k;
int idx;
bool operator<(const Query &q) {
if (q.r != r) return r < q.r;
return l < q.l;
}
};
struct Segtree {
int n;
vector<int> seg, lz;
Segtree(int sz) {
n=1;
while (n<sz)n*=2;
seg.assign(2*n,-1);
lz.assign(2*n,-1);
}
void pushdown(int x) {
if (lz[x] == -1) return;
if (seg[2*x+1] < lz[x]) {
seg[2*x+1] = lz[2*x+1] = lz[x];
}
if (seg[2*x+2] < lz[x]) {
seg[2*x+2] = lz[2*x+2] = lz[x];
}
lz[x] = -1;
}
void set(int l, int r, int v, int x, int lx, int rx) {
if (lx >= r || rx <= l) return;
if (lx >= l && rx <= r) {
if (seg[x] >= v) return;
seg[x] = lz[x] = v;
return;
}
pushdown(x);
int m=(lx+rx)/2;
set(l, r, v, 2*x+1, lx, m);
set(l, r, v, 2*x+2, m, rx);
seg[x] = min(seg[2*x+1], seg[2*x+2]);
}
void set(int l, int r, int v) {
set(l, r, v, 0, 0, n);
}
int get(int i, int x, int lx, int rx) {
if (rx-lx==1) {
return seg[x];
}
pushdown(x);
int m=(lx+rx)/2;
if (i<m)return get(i,2*x+1,lx,m);
return get(i, 2*x+2, m, rx);
}
int get(int i) {
return get(i, 0, 0, n);
}
};
signed main() {
int n,m;cin>>n>>m;
vector<int> a(n);
for (auto &x:a) cin>>x;
vector<Query> q;
vector<bool> ans(m, false);
for (int i=0;i<m;i++) {
Query qq;
qq.idx = i;
cin>>qq.l>>qq.r>>qq.k;
qq.l--;qq.r--;
if (qq.l == qq.r) {
ans[i] = true;
continue;
}
q.push_back(qq);
}
sort(q.begin(), q.end());
int pt = 0;
stack<tii> s;
Segtree sg(n);
vector<int> ans2(m);
for (int i=0;i<n;i++) {
while (s.size() && s.top()[2] <= a[i]) {
s.pop();
}
int last;
if (s.size()) {
last = s.top()[1]+1;
int first = s.top()[0];
int score = s.top()[2] + a[i];
sg.set(first, last, score);
}
else {
last = 0;
}
s.push({last, i, a[i]});
// for (int j=0;j<=i;j++) {
// cout<<sg.get(j)<<" ";
// }
// cout<<"\n";
while (pt < (int)q.size() && q[pt].r == i) {
int qt = q[pt].l;
int val = sg.get(qt);
ans[q[pt].idx] = (q[pt].k >= val);
ans2[q[pt].idx] = val;
pt++;
}
}
for (int i=0;i<m;i++) {
cout<<ans[i]<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
444 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
444 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
600 KB |
Output is correct |
12 |
Correct |
5 ms |
908 KB |
Output is correct |
13 |
Correct |
5 ms |
860 KB |
Output is correct |
14 |
Correct |
7 ms |
980 KB |
Output is correct |
15 |
Correct |
7 ms |
1084 KB |
Output is correct |
16 |
Correct |
6 ms |
984 KB |
Output is correct |
17 |
Correct |
5 ms |
860 KB |
Output is correct |
18 |
Correct |
5 ms |
984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1668 ms |
99380 KB |
Output is correct |
2 |
Correct |
1701 ms |
100660 KB |
Output is correct |
3 |
Correct |
1642 ms |
98784 KB |
Output is correct |
4 |
Correct |
1662 ms |
100196 KB |
Output is correct |
5 |
Correct |
1314 ms |
99044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
11044 KB |
Output is correct |
2 |
Correct |
117 ms |
11408 KB |
Output is correct |
3 |
Correct |
95 ms |
11356 KB |
Output is correct |
4 |
Correct |
95 ms |
11196 KB |
Output is correct |
5 |
Correct |
95 ms |
11708 KB |
Output is correct |
6 |
Correct |
97 ms |
11192 KB |
Output is correct |
7 |
Correct |
91 ms |
11192 KB |
Output is correct |
8 |
Correct |
98 ms |
10956 KB |
Output is correct |
9 |
Correct |
65 ms |
7624 KB |
Output is correct |
10 |
Correct |
95 ms |
10936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
444 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
600 KB |
Output is correct |
12 |
Correct |
5 ms |
908 KB |
Output is correct |
13 |
Correct |
5 ms |
860 KB |
Output is correct |
14 |
Correct |
7 ms |
980 KB |
Output is correct |
15 |
Correct |
7 ms |
1084 KB |
Output is correct |
16 |
Correct |
6 ms |
984 KB |
Output is correct |
17 |
Correct |
5 ms |
860 KB |
Output is correct |
18 |
Correct |
5 ms |
984 KB |
Output is correct |
19 |
Correct |
294 ms |
26544 KB |
Output is correct |
20 |
Correct |
294 ms |
24996 KB |
Output is correct |
21 |
Correct |
285 ms |
25108 KB |
Output is correct |
22 |
Correct |
286 ms |
26000 KB |
Output is correct |
23 |
Correct |
291 ms |
25224 KB |
Output is correct |
24 |
Correct |
243 ms |
26260 KB |
Output is correct |
25 |
Correct |
243 ms |
25024 KB |
Output is correct |
26 |
Correct |
243 ms |
25036 KB |
Output is correct |
27 |
Correct |
243 ms |
24756 KB |
Output is correct |
28 |
Correct |
248 ms |
26432 KB |
Output is correct |
29 |
Correct |
247 ms |
26580 KB |
Output is correct |
30 |
Correct |
250 ms |
25436 KB |
Output is correct |
31 |
Correct |
250 ms |
25324 KB |
Output is correct |
32 |
Correct |
249 ms |
26064 KB |
Output is correct |
33 |
Correct |
247 ms |
25744 KB |
Output is correct |
34 |
Correct |
247 ms |
25744 KB |
Output is correct |
35 |
Correct |
241 ms |
24744 KB |
Output is correct |
36 |
Correct |
246 ms |
25268 KB |
Output is correct |
37 |
Correct |
234 ms |
24992 KB |
Output is correct |
38 |
Correct |
271 ms |
25040 KB |
Output is correct |
39 |
Correct |
227 ms |
24504 KB |
Output is correct |
40 |
Correct |
189 ms |
18880 KB |
Output is correct |
41 |
Correct |
222 ms |
23352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
444 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
600 KB |
Output is correct |
12 |
Correct |
5 ms |
908 KB |
Output is correct |
13 |
Correct |
5 ms |
860 KB |
Output is correct |
14 |
Correct |
7 ms |
980 KB |
Output is correct |
15 |
Correct |
7 ms |
1084 KB |
Output is correct |
16 |
Correct |
6 ms |
984 KB |
Output is correct |
17 |
Correct |
5 ms |
860 KB |
Output is correct |
18 |
Correct |
5 ms |
984 KB |
Output is correct |
19 |
Correct |
1668 ms |
99380 KB |
Output is correct |
20 |
Correct |
1701 ms |
100660 KB |
Output is correct |
21 |
Correct |
1642 ms |
98784 KB |
Output is correct |
22 |
Correct |
1662 ms |
100196 KB |
Output is correct |
23 |
Correct |
1314 ms |
99044 KB |
Output is correct |
24 |
Correct |
118 ms |
11044 KB |
Output is correct |
25 |
Correct |
117 ms |
11408 KB |
Output is correct |
26 |
Correct |
95 ms |
11356 KB |
Output is correct |
27 |
Correct |
95 ms |
11196 KB |
Output is correct |
28 |
Correct |
95 ms |
11708 KB |
Output is correct |
29 |
Correct |
97 ms |
11192 KB |
Output is correct |
30 |
Correct |
91 ms |
11192 KB |
Output is correct |
31 |
Correct |
98 ms |
10956 KB |
Output is correct |
32 |
Correct |
65 ms |
7624 KB |
Output is correct |
33 |
Correct |
95 ms |
10936 KB |
Output is correct |
34 |
Correct |
294 ms |
26544 KB |
Output is correct |
35 |
Correct |
294 ms |
24996 KB |
Output is correct |
36 |
Correct |
285 ms |
25108 KB |
Output is correct |
37 |
Correct |
286 ms |
26000 KB |
Output is correct |
38 |
Correct |
291 ms |
25224 KB |
Output is correct |
39 |
Correct |
243 ms |
26260 KB |
Output is correct |
40 |
Correct |
243 ms |
25024 KB |
Output is correct |
41 |
Correct |
243 ms |
25036 KB |
Output is correct |
42 |
Correct |
243 ms |
24756 KB |
Output is correct |
43 |
Correct |
248 ms |
26432 KB |
Output is correct |
44 |
Correct |
247 ms |
26580 KB |
Output is correct |
45 |
Correct |
250 ms |
25436 KB |
Output is correct |
46 |
Correct |
250 ms |
25324 KB |
Output is correct |
47 |
Correct |
249 ms |
26064 KB |
Output is correct |
48 |
Correct |
247 ms |
25744 KB |
Output is correct |
49 |
Correct |
247 ms |
25744 KB |
Output is correct |
50 |
Correct |
241 ms |
24744 KB |
Output is correct |
51 |
Correct |
246 ms |
25268 KB |
Output is correct |
52 |
Correct |
234 ms |
24992 KB |
Output is correct |
53 |
Correct |
271 ms |
25040 KB |
Output is correct |
54 |
Correct |
227 ms |
24504 KB |
Output is correct |
55 |
Correct |
189 ms |
18880 KB |
Output is correct |
56 |
Correct |
222 ms |
23352 KB |
Output is correct |
57 |
Correct |
1680 ms |
115840 KB |
Output is correct |
58 |
Correct |
1640 ms |
115672 KB |
Output is correct |
59 |
Correct |
1562 ms |
115940 KB |
Output is correct |
60 |
Correct |
1572 ms |
115784 KB |
Output is correct |
61 |
Correct |
1543 ms |
115936 KB |
Output is correct |
62 |
Correct |
1580 ms |
115644 KB |
Output is correct |
63 |
Correct |
1208 ms |
113888 KB |
Output is correct |
64 |
Correct |
1251 ms |
113868 KB |
Output is correct |
65 |
Correct |
1383 ms |
115876 KB |
Output is correct |
66 |
Correct |
1322 ms |
116404 KB |
Output is correct |
67 |
Correct |
1293 ms |
116416 KB |
Output is correct |
68 |
Correct |
1390 ms |
115676 KB |
Output is correct |
69 |
Correct |
1399 ms |
116772 KB |
Output is correct |
70 |
Correct |
1399 ms |
115748 KB |
Output is correct |
71 |
Correct |
1371 ms |
116208 KB |
Output is correct |
72 |
Correct |
1407 ms |
115672 KB |
Output is correct |
73 |
Correct |
1234 ms |
112880 KB |
Output is correct |
74 |
Correct |
1223 ms |
113824 KB |
Output is correct |
75 |
Correct |
1210 ms |
112556 KB |
Output is correct |
76 |
Correct |
1135 ms |
113532 KB |
Output is correct |
77 |
Correct |
1185 ms |
113032 KB |
Output is correct |
78 |
Correct |
1484 ms |
110176 KB |
Output is correct |
79 |
Correct |
1219 ms |
84592 KB |
Output is correct |
80 |
Correct |
1251 ms |
107608 KB |
Output is correct |