#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
struct cell
{
int l,r,c,in;
void read()
{
cin>>l>>r>>c;
}
};
bool cmp(cell a1,cell a2)
{
if(a1.r<a2.r)return true;
if(a1.r>a2.r)return false;
if(a1.l<a2.l)return true;
return false;
}
cell b[1000005];
int n,m,a[1000005],l,r,c,p[4000005],otg[1000005];
void update(int l,int r,int ql,int qr,int h,int x)
{
if(l>qr||r<ql)return;
if(l>=ql&&r<=qr)
{
p[h]=max(x,p[h]);
return;
}
int m=(l+r)/2;
update(l,m,ql,qr,h*2,x);
update(m+1,r,ql,qr,h*2+1,x);
p[h]=max(max(p[h*2],p[h*2+1]),p[h]);
}
int query(int l,int r,int ql,int qr,int h)
{
if(l>qr||r<ql)return 0;
if(l>=ql&&r<=qr)return p[h];
int m=(l+r)/2;
return max(query(l,m,ql,qr,h*2),query(m+1,r,ql,qr,h*2+1));
}
stack<int>s;
stack<int>in;
void read()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=m;i++)
{
b[i].read();
b[i].in=i;
}
sort(b+1,b+m+1,cmp);
int pos=1;
for(int i=1;i<=m;i++)
{
for(int j=pos;j<=b[i].r;j++)
{
while(!s.empty()&&s.top()<=a[j])
{
s.pop();
in.pop();
}
if(s.empty())
{
s.push(a[j]);
in.push(j);
}
else
{
update(1,n,in.top(),in.top(),1,a[j]+s.top());
s.push(a[j]);
in.push(j);
}
}
if(b[i].c>=query(1,n,b[i].l,b[i].r,1))otg[b[i].in]=1;
pos=b[i].r+1;
}
for(int i=1;i<=m;i++)
{
cout<<otg[i]<<endl;
}
}
int main()
{
speed();
read();
return 0;
}
# |
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 |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
3 ms |
604 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
4 ms |
600 KB |
Output is correct |
15 |
Correct |
4 ms |
604 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
856 KB |
Output is correct |
18 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
852 ms |
60848 KB |
Output is correct |
2 |
Correct |
842 ms |
61768 KB |
Output is correct |
3 |
Correct |
863 ms |
61520 KB |
Output is correct |
4 |
Correct |
865 ms |
61604 KB |
Output is correct |
5 |
Correct |
687 ms |
57424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
5968 KB |
Output is correct |
2 |
Correct |
69 ms |
5972 KB |
Output is correct |
3 |
Correct |
59 ms |
4944 KB |
Output is correct |
4 |
Correct |
58 ms |
4948 KB |
Output is correct |
5 |
Correct |
58 ms |
4948 KB |
Output is correct |
6 |
Correct |
52 ms |
4296 KB |
Output is correct |
7 |
Correct |
54 ms |
4436 KB |
Output is correct |
8 |
Correct |
54 ms |
4688 KB |
Output is correct |
9 |
Correct |
29 ms |
3924 KB |
Output is correct |
10 |
Correct |
59 ms |
4528 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 |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
3 ms |
604 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
4 ms |
600 KB |
Output is correct |
15 |
Correct |
4 ms |
604 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
856 KB |
Output is correct |
18 |
Correct |
3 ms |
604 KB |
Output is correct |
19 |
Correct |
158 ms |
14064 KB |
Output is correct |
20 |
Correct |
162 ms |
14188 KB |
Output is correct |
21 |
Correct |
156 ms |
13904 KB |
Output is correct |
22 |
Correct |
153 ms |
13904 KB |
Output is correct |
23 |
Correct |
154 ms |
13980 KB |
Output is correct |
24 |
Correct |
130 ms |
11872 KB |
Output is correct |
25 |
Correct |
119 ms |
11860 KB |
Output is correct |
26 |
Correct |
130 ms |
11856 KB |
Output is correct |
27 |
Correct |
135 ms |
11856 KB |
Output is correct |
28 |
Correct |
133 ms |
11976 KB |
Output is correct |
29 |
Correct |
133 ms |
11988 KB |
Output is correct |
30 |
Correct |
144 ms |
12112 KB |
Output is correct |
31 |
Correct |
139 ms |
12048 KB |
Output is correct |
32 |
Correct |
137 ms |
12112 KB |
Output is correct |
33 |
Correct |
133 ms |
12116 KB |
Output is correct |
34 |
Correct |
124 ms |
11604 KB |
Output is correct |
35 |
Correct |
118 ms |
11600 KB |
Output is correct |
36 |
Correct |
122 ms |
11604 KB |
Output is correct |
37 |
Correct |
116 ms |
11604 KB |
Output is correct |
38 |
Correct |
119 ms |
11736 KB |
Output is correct |
39 |
Correct |
117 ms |
11280 KB |
Output is correct |
40 |
Correct |
91 ms |
9808 KB |
Output is correct |
41 |
Correct |
112 ms |
10288 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 |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
3 ms |
604 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
4 ms |
600 KB |
Output is correct |
15 |
Correct |
4 ms |
604 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
856 KB |
Output is correct |
18 |
Correct |
3 ms |
604 KB |
Output is correct |
19 |
Correct |
852 ms |
60848 KB |
Output is correct |
20 |
Correct |
842 ms |
61768 KB |
Output is correct |
21 |
Correct |
863 ms |
61520 KB |
Output is correct |
22 |
Correct |
865 ms |
61604 KB |
Output is correct |
23 |
Correct |
687 ms |
57424 KB |
Output is correct |
24 |
Correct |
76 ms |
5968 KB |
Output is correct |
25 |
Correct |
69 ms |
5972 KB |
Output is correct |
26 |
Correct |
59 ms |
4944 KB |
Output is correct |
27 |
Correct |
58 ms |
4948 KB |
Output is correct |
28 |
Correct |
58 ms |
4948 KB |
Output is correct |
29 |
Correct |
52 ms |
4296 KB |
Output is correct |
30 |
Correct |
54 ms |
4436 KB |
Output is correct |
31 |
Correct |
54 ms |
4688 KB |
Output is correct |
32 |
Correct |
29 ms |
3924 KB |
Output is correct |
33 |
Correct |
59 ms |
4528 KB |
Output is correct |
34 |
Correct |
158 ms |
14064 KB |
Output is correct |
35 |
Correct |
162 ms |
14188 KB |
Output is correct |
36 |
Correct |
156 ms |
13904 KB |
Output is correct |
37 |
Correct |
153 ms |
13904 KB |
Output is correct |
38 |
Correct |
154 ms |
13980 KB |
Output is correct |
39 |
Correct |
130 ms |
11872 KB |
Output is correct |
40 |
Correct |
119 ms |
11860 KB |
Output is correct |
41 |
Correct |
130 ms |
11856 KB |
Output is correct |
42 |
Correct |
135 ms |
11856 KB |
Output is correct |
43 |
Correct |
133 ms |
11976 KB |
Output is correct |
44 |
Correct |
133 ms |
11988 KB |
Output is correct |
45 |
Correct |
144 ms |
12112 KB |
Output is correct |
46 |
Correct |
139 ms |
12048 KB |
Output is correct |
47 |
Correct |
137 ms |
12112 KB |
Output is correct |
48 |
Correct |
133 ms |
12116 KB |
Output is correct |
49 |
Correct |
124 ms |
11604 KB |
Output is correct |
50 |
Correct |
118 ms |
11600 KB |
Output is correct |
51 |
Correct |
122 ms |
11604 KB |
Output is correct |
52 |
Correct |
116 ms |
11604 KB |
Output is correct |
53 |
Correct |
119 ms |
11736 KB |
Output is correct |
54 |
Correct |
117 ms |
11280 KB |
Output is correct |
55 |
Correct |
91 ms |
9808 KB |
Output is correct |
56 |
Correct |
112 ms |
10288 KB |
Output is correct |
57 |
Correct |
908 ms |
67488 KB |
Output is correct |
58 |
Correct |
908 ms |
67668 KB |
Output is correct |
59 |
Correct |
881 ms |
67664 KB |
Output is correct |
60 |
Correct |
899 ms |
67556 KB |
Output is correct |
61 |
Correct |
929 ms |
67412 KB |
Output is correct |
62 |
Correct |
857 ms |
67364 KB |
Output is correct |
63 |
Correct |
653 ms |
57528 KB |
Output is correct |
64 |
Correct |
652 ms |
57380 KB |
Output is correct |
65 |
Correct |
704 ms |
59220 KB |
Output is correct |
66 |
Correct |
705 ms |
59220 KB |
Output is correct |
67 |
Correct |
681 ms |
59220 KB |
Output is correct |
68 |
Correct |
704 ms |
59424 KB |
Output is correct |
69 |
Correct |
687 ms |
59468 KB |
Output is correct |
70 |
Correct |
689 ms |
59476 KB |
Output is correct |
71 |
Correct |
698 ms |
59476 KB |
Output is correct |
72 |
Correct |
687 ms |
59248 KB |
Output is correct |
73 |
Correct |
627 ms |
55884 KB |
Output is correct |
74 |
Correct |
631 ms |
56912 KB |
Output is correct |
75 |
Correct |
613 ms |
55888 KB |
Output is correct |
76 |
Correct |
616 ms |
55668 KB |
Output is correct |
77 |
Correct |
628 ms |
55888 KB |
Output is correct |
78 |
Correct |
646 ms |
56012 KB |
Output is correct |
79 |
Correct |
505 ms |
46676 KB |
Output is correct |
80 |
Correct |
647 ms |
50520 KB |
Output is correct |