#include <bits/stdc++.h>
using namespace std;
int n,m,v[2000005],st[2000005],dr[2000005],cost[2000005];
vector <int> ev[2000005];
int aib[2000005],sol[2000005];
stack <int> stac;
int ub (int x)
{
return x&(-x);
}
void update(int poz2,int x)
{
int i;
for (i=poz2;i<=n;i+=ub(i))
{
aib[i]=max(aib[i],x);
}
}
int maxi(int poz2)
{
int i,maxim=0;
for (i=poz2;i>=1;i-=ub(i))
{
maxim=max(aib[i],maxim);
}
return maxim;
}
int i,j;
vector <pair <int,int>> ceau;
int main()
{
ios_base :: sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
for (i=1;i<=n;i++)
{
cin>>v[i];
}
for (i=1;i<=m;i++)
{
cin>>st[i]>>dr[i]>>cost[i];
ev[st[i]].push_back(i);
}
for (i=1;i<=n;i++)
{
while (!stac.empty()&&v[stac.top()]<=v[i])
{
stac.pop();
}
if (!stac.empty())
{
ceau.push_back({stac.top(),i});
}
stac.push(i);
}
sort (ceau.begin(),ceau.end());
int poz=((int)ceau.size())-1;
for (i=n;i>=1;i--)
{
while (poz>=0&&ceau[poz].first>=i)
{
update(ceau[poz].second,v[ceau[poz].first]+v[ceau[poz].second]);
poz--;
}
for (j=0;j<(int)ev[i].size();j++)
{
if (maxi(dr[ev[i][j]])<=cost[ev[i][j]])
{
sol[ev[i][j]]=1;
}
}
}
for (i=1;i<=m;i++)
{
cout<<sol[i]<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
47308 KB |
Output is correct |
2 |
Correct |
22 ms |
47252 KB |
Output is correct |
3 |
Correct |
24 ms |
47232 KB |
Output is correct |
4 |
Correct |
22 ms |
47308 KB |
Output is correct |
5 |
Correct |
22 ms |
47224 KB |
Output is correct |
6 |
Correct |
23 ms |
47312 KB |
Output is correct |
7 |
Correct |
23 ms |
47252 KB |
Output is correct |
8 |
Correct |
23 ms |
47308 KB |
Output is correct |
9 |
Correct |
23 ms |
47312 KB |
Output is correct |
10 |
Correct |
23 ms |
47284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
47308 KB |
Output is correct |
2 |
Correct |
22 ms |
47252 KB |
Output is correct |
3 |
Correct |
24 ms |
47232 KB |
Output is correct |
4 |
Correct |
22 ms |
47308 KB |
Output is correct |
5 |
Correct |
22 ms |
47224 KB |
Output is correct |
6 |
Correct |
23 ms |
47312 KB |
Output is correct |
7 |
Correct |
23 ms |
47252 KB |
Output is correct |
8 |
Correct |
23 ms |
47308 KB |
Output is correct |
9 |
Correct |
23 ms |
47312 KB |
Output is correct |
10 |
Correct |
23 ms |
47284 KB |
Output is correct |
11 |
Correct |
25 ms |
47448 KB |
Output is correct |
12 |
Correct |
24 ms |
47488 KB |
Output is correct |
13 |
Correct |
25 ms |
47520 KB |
Output is correct |
14 |
Correct |
26 ms |
47600 KB |
Output is correct |
15 |
Correct |
25 ms |
47656 KB |
Output is correct |
16 |
Correct |
25 ms |
47436 KB |
Output is correct |
17 |
Correct |
27 ms |
47436 KB |
Output is correct |
18 |
Correct |
26 ms |
47580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
922 ms |
94820 KB |
Output is correct |
2 |
Correct |
943 ms |
96536 KB |
Output is correct |
3 |
Correct |
960 ms |
96388 KB |
Output is correct |
4 |
Correct |
954 ms |
96540 KB |
Output is correct |
5 |
Correct |
831 ms |
88644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
52748 KB |
Output is correct |
2 |
Correct |
91 ms |
53668 KB |
Output is correct |
3 |
Correct |
79 ms |
53036 KB |
Output is correct |
4 |
Correct |
71 ms |
53300 KB |
Output is correct |
5 |
Correct |
84 ms |
53396 KB |
Output is correct |
6 |
Correct |
68 ms |
51736 KB |
Output is correct |
7 |
Correct |
62 ms |
51664 KB |
Output is correct |
8 |
Correct |
77 ms |
53412 KB |
Output is correct |
9 |
Correct |
54 ms |
51140 KB |
Output is correct |
10 |
Correct |
74 ms |
53240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
47308 KB |
Output is correct |
2 |
Correct |
22 ms |
47252 KB |
Output is correct |
3 |
Correct |
24 ms |
47232 KB |
Output is correct |
4 |
Correct |
22 ms |
47308 KB |
Output is correct |
5 |
Correct |
22 ms |
47224 KB |
Output is correct |
6 |
Correct |
23 ms |
47312 KB |
Output is correct |
7 |
Correct |
23 ms |
47252 KB |
Output is correct |
8 |
Correct |
23 ms |
47308 KB |
Output is correct |
9 |
Correct |
23 ms |
47312 KB |
Output is correct |
10 |
Correct |
23 ms |
47284 KB |
Output is correct |
11 |
Correct |
25 ms |
47448 KB |
Output is correct |
12 |
Correct |
24 ms |
47488 KB |
Output is correct |
13 |
Correct |
25 ms |
47520 KB |
Output is correct |
14 |
Correct |
26 ms |
47600 KB |
Output is correct |
15 |
Correct |
25 ms |
47656 KB |
Output is correct |
16 |
Correct |
25 ms |
47436 KB |
Output is correct |
17 |
Correct |
27 ms |
47436 KB |
Output is correct |
18 |
Correct |
26 ms |
47580 KB |
Output is correct |
19 |
Correct |
175 ms |
58144 KB |
Output is correct |
20 |
Correct |
185 ms |
64564 KB |
Output is correct |
21 |
Correct |
155 ms |
62112 KB |
Output is correct |
22 |
Correct |
153 ms |
62088 KB |
Output is correct |
23 |
Correct |
168 ms |
62128 KB |
Output is correct |
24 |
Correct |
159 ms |
59332 KB |
Output is correct |
25 |
Correct |
138 ms |
59372 KB |
Output is correct |
26 |
Correct |
147 ms |
60388 KB |
Output is correct |
27 |
Correct |
161 ms |
60364 KB |
Output is correct |
28 |
Correct |
152 ms |
60928 KB |
Output is correct |
29 |
Correct |
170 ms |
62152 KB |
Output is correct |
30 |
Correct |
188 ms |
62152 KB |
Output is correct |
31 |
Correct |
163 ms |
62096 KB |
Output is correct |
32 |
Correct |
165 ms |
62064 KB |
Output is correct |
33 |
Correct |
170 ms |
62096 KB |
Output is correct |
34 |
Correct |
126 ms |
58980 KB |
Output is correct |
35 |
Correct |
125 ms |
58948 KB |
Output is correct |
36 |
Correct |
119 ms |
58696 KB |
Output is correct |
37 |
Correct |
121 ms |
58696 KB |
Output is correct |
38 |
Correct |
129 ms |
59080 KB |
Output is correct |
39 |
Correct |
156 ms |
60336 KB |
Output is correct |
40 |
Correct |
120 ms |
58568 KB |
Output is correct |
41 |
Correct |
138 ms |
60432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
47308 KB |
Output is correct |
2 |
Correct |
22 ms |
47252 KB |
Output is correct |
3 |
Correct |
24 ms |
47232 KB |
Output is correct |
4 |
Correct |
22 ms |
47308 KB |
Output is correct |
5 |
Correct |
22 ms |
47224 KB |
Output is correct |
6 |
Correct |
23 ms |
47312 KB |
Output is correct |
7 |
Correct |
23 ms |
47252 KB |
Output is correct |
8 |
Correct |
23 ms |
47308 KB |
Output is correct |
9 |
Correct |
23 ms |
47312 KB |
Output is correct |
10 |
Correct |
23 ms |
47284 KB |
Output is correct |
11 |
Correct |
25 ms |
47448 KB |
Output is correct |
12 |
Correct |
24 ms |
47488 KB |
Output is correct |
13 |
Correct |
25 ms |
47520 KB |
Output is correct |
14 |
Correct |
26 ms |
47600 KB |
Output is correct |
15 |
Correct |
25 ms |
47656 KB |
Output is correct |
16 |
Correct |
25 ms |
47436 KB |
Output is correct |
17 |
Correct |
27 ms |
47436 KB |
Output is correct |
18 |
Correct |
26 ms |
47580 KB |
Output is correct |
19 |
Correct |
922 ms |
94820 KB |
Output is correct |
20 |
Correct |
943 ms |
96536 KB |
Output is correct |
21 |
Correct |
960 ms |
96388 KB |
Output is correct |
22 |
Correct |
954 ms |
96540 KB |
Output is correct |
23 |
Correct |
831 ms |
88644 KB |
Output is correct |
24 |
Correct |
88 ms |
52748 KB |
Output is correct |
25 |
Correct |
91 ms |
53668 KB |
Output is correct |
26 |
Correct |
79 ms |
53036 KB |
Output is correct |
27 |
Correct |
71 ms |
53300 KB |
Output is correct |
28 |
Correct |
84 ms |
53396 KB |
Output is correct |
29 |
Correct |
68 ms |
51736 KB |
Output is correct |
30 |
Correct |
62 ms |
51664 KB |
Output is correct |
31 |
Correct |
77 ms |
53412 KB |
Output is correct |
32 |
Correct |
54 ms |
51140 KB |
Output is correct |
33 |
Correct |
74 ms |
53240 KB |
Output is correct |
34 |
Correct |
175 ms |
58144 KB |
Output is correct |
35 |
Correct |
185 ms |
64564 KB |
Output is correct |
36 |
Correct |
155 ms |
62112 KB |
Output is correct |
37 |
Correct |
153 ms |
62088 KB |
Output is correct |
38 |
Correct |
168 ms |
62128 KB |
Output is correct |
39 |
Correct |
159 ms |
59332 KB |
Output is correct |
40 |
Correct |
138 ms |
59372 KB |
Output is correct |
41 |
Correct |
147 ms |
60388 KB |
Output is correct |
42 |
Correct |
161 ms |
60364 KB |
Output is correct |
43 |
Correct |
152 ms |
60928 KB |
Output is correct |
44 |
Correct |
170 ms |
62152 KB |
Output is correct |
45 |
Correct |
188 ms |
62152 KB |
Output is correct |
46 |
Correct |
163 ms |
62096 KB |
Output is correct |
47 |
Correct |
165 ms |
62064 KB |
Output is correct |
48 |
Correct |
170 ms |
62096 KB |
Output is correct |
49 |
Correct |
126 ms |
58980 KB |
Output is correct |
50 |
Correct |
125 ms |
58948 KB |
Output is correct |
51 |
Correct |
119 ms |
58696 KB |
Output is correct |
52 |
Correct |
121 ms |
58696 KB |
Output is correct |
53 |
Correct |
129 ms |
59080 KB |
Output is correct |
54 |
Correct |
156 ms |
60336 KB |
Output is correct |
55 |
Correct |
120 ms |
58568 KB |
Output is correct |
56 |
Correct |
138 ms |
60432 KB |
Output is correct |
57 |
Correct |
1029 ms |
134296 KB |
Output is correct |
58 |
Correct |
1020 ms |
134284 KB |
Output is correct |
59 |
Correct |
933 ms |
128504 KB |
Output is correct |
60 |
Correct |
941 ms |
128648 KB |
Output is correct |
61 |
Correct |
976 ms |
128580 KB |
Output is correct |
62 |
Correct |
988 ms |
128568 KB |
Output is correct |
63 |
Correct |
646 ms |
106208 KB |
Output is correct |
64 |
Correct |
653 ms |
106172 KB |
Output is correct |
65 |
Correct |
876 ms |
115824 KB |
Output is correct |
66 |
Correct |
850 ms |
115796 KB |
Output is correct |
67 |
Correct |
834 ms |
116280 KB |
Output is correct |
68 |
Correct |
914 ms |
122456 KB |
Output is correct |
69 |
Correct |
936 ms |
121480 KB |
Output is correct |
70 |
Correct |
948 ms |
120700 KB |
Output is correct |
71 |
Correct |
932 ms |
120840 KB |
Output is correct |
72 |
Correct |
945 ms |
120720 KB |
Output is correct |
73 |
Correct |
609 ms |
104368 KB |
Output is correct |
74 |
Correct |
653 ms |
105144 KB |
Output is correct |
75 |
Correct |
588 ms |
104384 KB |
Output is correct |
76 |
Correct |
572 ms |
104208 KB |
Output is correct |
77 |
Correct |
598 ms |
104356 KB |
Output is correct |
78 |
Correct |
803 ms |
112556 KB |
Output is correct |
79 |
Correct |
604 ms |
102076 KB |
Output is correct |
80 |
Correct |
810 ms |
114260 KB |
Output is correct |