#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
using namespace std;
const int N = 4e6 + 200;
pair<int, int> v[N],b[N];
vector<int> q[N];
int t[4 * N],a[N],n,Q,limit,l,r,x,step,pos,val;
bool ans[N];
void upd(int v,int tl,int tr)
{
if(tl == tr)
{
t[v] = val + a[tl];
return;
}
int tm = (tl + tr) >> 1;
if(pos <= tm) upd(v << 1, tl, tm);
else upd(v << 1 | 1, tm + 1, tr);
t[v] = max(t[v << 1], t[v << 1 | 1]);
}
int get(int v,int tl,int tr)
{
if(tr < l || tl > r) return 0;
if(tl >= l && tr <= r) return t[v];
int tm = (tl + tr) >> 1;
return max(get(v << 1, tl, tm), get(v << 1 | 1, tm + 1, tr));
}
void make(int l,int r)
{
int x,Pos;
for(int i = r; i >= l; i--)
{
x = a[i];
while(step > 0 && x > v[step].fi)
{
Pos = v[step].se;
pos = Pos;
val = x;
upd(1, 1, n);
step--;
}
v[++step] = {x, i};
}
}
int main()
{
ios_base::sync_with_stdio();cin.tie(0);cout.tie(0);
cin>>n>>Q;
for(int i = 1; i <= n; i++) cin>>a[i];
limit = n;
for(int i = 1; i <= Q; i++)
{
cin>>l>>r>>x;
b[i] = {r, x};
q[l].push_back(i);
}
for(int j = n; j > 0; j--) if(!q[j].empty())
for(auto i : q[j])
{
l = j;
r = b[i].fi;
if(limit >= l)
{
make(l, limit);
limit = l - 1;
}
x = get(1, 1, n);
ans[i] = (x <= b[i].se);
}
for(int i = 1; i <= Q; i++) cout<<ans[i]<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
94328 KB |
Output is correct |
2 |
Correct |
87 ms |
94380 KB |
Output is correct |
3 |
Correct |
89 ms |
94328 KB |
Output is correct |
4 |
Correct |
96 ms |
94324 KB |
Output is correct |
5 |
Correct |
93 ms |
94328 KB |
Output is correct |
6 |
Correct |
88 ms |
94300 KB |
Output is correct |
7 |
Correct |
89 ms |
94408 KB |
Output is correct |
8 |
Correct |
88 ms |
94332 KB |
Output is correct |
9 |
Correct |
99 ms |
94288 KB |
Output is correct |
10 |
Correct |
89 ms |
94328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
94328 KB |
Output is correct |
2 |
Correct |
87 ms |
94380 KB |
Output is correct |
3 |
Correct |
89 ms |
94328 KB |
Output is correct |
4 |
Correct |
96 ms |
94324 KB |
Output is correct |
5 |
Correct |
93 ms |
94328 KB |
Output is correct |
6 |
Correct |
88 ms |
94300 KB |
Output is correct |
7 |
Correct |
89 ms |
94408 KB |
Output is correct |
8 |
Correct |
88 ms |
94332 KB |
Output is correct |
9 |
Correct |
99 ms |
94288 KB |
Output is correct |
10 |
Correct |
89 ms |
94328 KB |
Output is correct |
11 |
Correct |
103 ms |
94500 KB |
Output is correct |
12 |
Correct |
97 ms |
94584 KB |
Output is correct |
13 |
Correct |
103 ms |
94684 KB |
Output is correct |
14 |
Correct |
116 ms |
94808 KB |
Output is correct |
15 |
Correct |
101 ms |
94584 KB |
Output is correct |
16 |
Correct |
98 ms |
94612 KB |
Output is correct |
17 |
Correct |
98 ms |
94668 KB |
Output is correct |
18 |
Correct |
96 ms |
94604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3014 ms |
129488 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
355 ms |
98940 KB |
Output is correct |
2 |
Correct |
329 ms |
97932 KB |
Output is correct |
3 |
Correct |
345 ms |
98364 KB |
Output is correct |
4 |
Correct |
338 ms |
98508 KB |
Output is correct |
5 |
Correct |
329 ms |
98664 KB |
Output is correct |
6 |
Correct |
295 ms |
97272 KB |
Output is correct |
7 |
Correct |
289 ms |
97352 KB |
Output is correct |
8 |
Correct |
328 ms |
98424 KB |
Output is correct |
9 |
Correct |
224 ms |
95992 KB |
Output is correct |
10 |
Correct |
309 ms |
98248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
94328 KB |
Output is correct |
2 |
Correct |
87 ms |
94380 KB |
Output is correct |
3 |
Correct |
89 ms |
94328 KB |
Output is correct |
4 |
Correct |
96 ms |
94324 KB |
Output is correct |
5 |
Correct |
93 ms |
94328 KB |
Output is correct |
6 |
Correct |
88 ms |
94300 KB |
Output is correct |
7 |
Correct |
89 ms |
94408 KB |
Output is correct |
8 |
Correct |
88 ms |
94332 KB |
Output is correct |
9 |
Correct |
99 ms |
94288 KB |
Output is correct |
10 |
Correct |
89 ms |
94328 KB |
Output is correct |
11 |
Correct |
103 ms |
94500 KB |
Output is correct |
12 |
Correct |
97 ms |
94584 KB |
Output is correct |
13 |
Correct |
103 ms |
94684 KB |
Output is correct |
14 |
Correct |
116 ms |
94808 KB |
Output is correct |
15 |
Correct |
101 ms |
94584 KB |
Output is correct |
16 |
Correct |
98 ms |
94612 KB |
Output is correct |
17 |
Correct |
98 ms |
94668 KB |
Output is correct |
18 |
Correct |
96 ms |
94604 KB |
Output is correct |
19 |
Correct |
788 ms |
103344 KB |
Output is correct |
20 |
Correct |
788 ms |
103436 KB |
Output is correct |
21 |
Correct |
725 ms |
101040 KB |
Output is correct |
22 |
Correct |
728 ms |
101064 KB |
Output is correct |
23 |
Correct |
726 ms |
101112 KB |
Output is correct |
24 |
Correct |
677 ms |
100532 KB |
Output is correct |
25 |
Correct |
678 ms |
100568 KB |
Output is correct |
26 |
Correct |
729 ms |
101444 KB |
Output is correct |
27 |
Correct |
724 ms |
101260 KB |
Output is correct |
28 |
Correct |
749 ms |
101868 KB |
Output is correct |
29 |
Correct |
752 ms |
102820 KB |
Output is correct |
30 |
Correct |
749 ms |
103000 KB |
Output is correct |
31 |
Correct |
757 ms |
102792 KB |
Output is correct |
32 |
Correct |
748 ms |
102936 KB |
Output is correct |
33 |
Correct |
765 ms |
102904 KB |
Output is correct |
34 |
Correct |
649 ms |
100132 KB |
Output is correct |
35 |
Correct |
676 ms |
100168 KB |
Output is correct |
36 |
Correct |
658 ms |
100156 KB |
Output is correct |
37 |
Correct |
644 ms |
100132 KB |
Output is correct |
38 |
Correct |
656 ms |
100248 KB |
Output is correct |
39 |
Correct |
636 ms |
101560 KB |
Output is correct |
40 |
Correct |
560 ms |
100516 KB |
Output is correct |
41 |
Correct |
638 ms |
101828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
94328 KB |
Output is correct |
2 |
Correct |
87 ms |
94380 KB |
Output is correct |
3 |
Correct |
89 ms |
94328 KB |
Output is correct |
4 |
Correct |
96 ms |
94324 KB |
Output is correct |
5 |
Correct |
93 ms |
94328 KB |
Output is correct |
6 |
Correct |
88 ms |
94300 KB |
Output is correct |
7 |
Correct |
89 ms |
94408 KB |
Output is correct |
8 |
Correct |
88 ms |
94332 KB |
Output is correct |
9 |
Correct |
99 ms |
94288 KB |
Output is correct |
10 |
Correct |
89 ms |
94328 KB |
Output is correct |
11 |
Correct |
103 ms |
94500 KB |
Output is correct |
12 |
Correct |
97 ms |
94584 KB |
Output is correct |
13 |
Correct |
103 ms |
94684 KB |
Output is correct |
14 |
Correct |
116 ms |
94808 KB |
Output is correct |
15 |
Correct |
101 ms |
94584 KB |
Output is correct |
16 |
Correct |
98 ms |
94612 KB |
Output is correct |
17 |
Correct |
98 ms |
94668 KB |
Output is correct |
18 |
Correct |
96 ms |
94604 KB |
Output is correct |
19 |
Execution timed out |
3014 ms |
129488 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |