#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
using namespace std;
const int N = 4e6 + 200;
pair<pair<int, int>, int> b[N];
pair<int, int> v[N];
int t[4 * N],a[N],n,Q,limit,l,r,x,ans[N],q[N],step;
int pos, val;
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};
}
}
bool comp(int i,int j)
{
return (b[i].fi.fi > b[j].fi.fi) || (b[i].fi.fi == b[j].fi.fi && (m_p(b[i].fi.se, b[i].se) < m_p(b[j].fi.se, b[j].se)));
}
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] = {{l, r}, x};
q[i] = i;
}
stable_sort(q + 1, q + Q + 1, comp);
for(int i,j = 1; j <= Q; j++)
{
i = q[j];
l = b[i].fi.fi;
r = b[i].fi.se;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
404 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
404 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
9 ms |
476 KB |
Output is correct |
12 |
Correct |
11 ms |
508 KB |
Output is correct |
13 |
Correct |
13 ms |
504 KB |
Output is correct |
14 |
Correct |
16 ms |
504 KB |
Output is correct |
15 |
Correct |
16 ms |
504 KB |
Output is correct |
16 |
Correct |
13 ms |
508 KB |
Output is correct |
17 |
Correct |
12 ms |
504 KB |
Output is correct |
18 |
Correct |
12 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3044 ms |
29120 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
251 ms |
3932 KB |
Output is correct |
2 |
Correct |
243 ms |
3984 KB |
Output is correct |
3 |
Correct |
236 ms |
3724 KB |
Output is correct |
4 |
Correct |
233 ms |
3752 KB |
Output is correct |
5 |
Correct |
242 ms |
3748 KB |
Output is correct |
6 |
Correct |
220 ms |
3804 KB |
Output is correct |
7 |
Correct |
223 ms |
3764 KB |
Output is correct |
8 |
Correct |
213 ms |
4012 KB |
Output is correct |
9 |
Correct |
151 ms |
2560 KB |
Output is correct |
10 |
Correct |
212 ms |
3980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
404 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
9 ms |
476 KB |
Output is correct |
12 |
Correct |
11 ms |
508 KB |
Output is correct |
13 |
Correct |
13 ms |
504 KB |
Output is correct |
14 |
Correct |
16 ms |
504 KB |
Output is correct |
15 |
Correct |
16 ms |
504 KB |
Output is correct |
16 |
Correct |
13 ms |
508 KB |
Output is correct |
17 |
Correct |
12 ms |
504 KB |
Output is correct |
18 |
Correct |
12 ms |
632 KB |
Output is correct |
19 |
Correct |
708 ms |
7600 KB |
Output is correct |
20 |
Correct |
687 ms |
7520 KB |
Output is correct |
21 |
Correct |
650 ms |
7452 KB |
Output is correct |
22 |
Correct |
675 ms |
7548 KB |
Output is correct |
23 |
Correct |
654 ms |
7592 KB |
Output is correct |
24 |
Correct |
605 ms |
7060 KB |
Output is correct |
25 |
Correct |
616 ms |
6988 KB |
Output is correct |
26 |
Correct |
626 ms |
7204 KB |
Output is correct |
27 |
Correct |
626 ms |
6992 KB |
Output is correct |
28 |
Correct |
629 ms |
7132 KB |
Output is correct |
29 |
Correct |
640 ms |
7012 KB |
Output is correct |
30 |
Correct |
641 ms |
7048 KB |
Output is correct |
31 |
Correct |
637 ms |
7152 KB |
Output is correct |
32 |
Correct |
636 ms |
7060 KB |
Output is correct |
33 |
Correct |
649 ms |
6972 KB |
Output is correct |
34 |
Correct |
598 ms |
7076 KB |
Output is correct |
35 |
Correct |
594 ms |
7284 KB |
Output is correct |
36 |
Correct |
591 ms |
7120 KB |
Output is correct |
37 |
Correct |
582 ms |
7216 KB |
Output is correct |
38 |
Correct |
625 ms |
7064 KB |
Output is correct |
39 |
Correct |
546 ms |
7304 KB |
Output is correct |
40 |
Correct |
453 ms |
6088 KB |
Output is correct |
41 |
Correct |
514 ms |
7532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
404 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
9 ms |
476 KB |
Output is correct |
12 |
Correct |
11 ms |
508 KB |
Output is correct |
13 |
Correct |
13 ms |
504 KB |
Output is correct |
14 |
Correct |
16 ms |
504 KB |
Output is correct |
15 |
Correct |
16 ms |
504 KB |
Output is correct |
16 |
Correct |
13 ms |
508 KB |
Output is correct |
17 |
Correct |
12 ms |
504 KB |
Output is correct |
18 |
Correct |
12 ms |
632 KB |
Output is correct |
19 |
Execution timed out |
3044 ms |
29120 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |