/**
____ ____ ____ __________________ ____ ____ ____
||I || ||c || ||e || || || ||M || ||a || ||n ||
||__|| ||__|| ||__|| ||________________|| ||__|| ||__|| ||__||
|/__\| |/__\| |/__\| |/________________\| |/__\| |/__\| |/__\|
*/
#include <iostream>
#include <chrono>
#include <stack>
#include <vector>
#define endl '\n'
#define maxn 1000005
#define maxlog 20
#define INF 1000000010
#define LINF 1000000000000000005
#define endl '\n'
#define pb(x) push_back(x)
#define X first
#define Y second
#define control cout<<"passed"<<endl;
#pragma GCC optimize("O3" , "Ofast" , "unroll-loops" , "fast-math")
#pragma GCC target("avx2")
using namespace std;
typedef pair <int, int> pii;
typedef long long ll;
typedef pair <ll , ll> pll;
typedef pair <int , ll> pil;
typedef pair <ll , int> pli;
typedef long double ld;
std::chrono::high_resolution_clock::time_point startT, currT;
constexpr double TIME_MULT = 1;
double timePassed()
{
using namespace std::chrono;
currT = high_resolution_clock::now();
double time = duration_cast<duration<double>>(currT - startT).count();
return time * TIME_MULT;
}
int tree[maxn * 4];
void update(int node , int l , int r , int qp , int qval)
{
if(l == r)
{
tree[node] = max(tree[node] , qval);
return;
}
int mid = (l + r) / 2;
if(qp <= mid)
update(node * 2 , l , mid , qp , qval);
else
update(node * 2 + 1 , mid + 1 , r , qp , qval);
tree[node] = max(tree[node * 2] , tree[node * 2 + 1]);
}
int query(int node , int l , int r , int ql , int qr)
{
if(qr < l)
return -INF;
if(r < ql)
return -INF;
if(ql <= l && r <= qr)
return tree[node];
int mid = (l + r) / 2;
return max(query(node * 2 , l , mid , ql , qr) , query(node * 2 + 1 , mid + 1, r , ql , qr));
}
int a[maxn];
int n , q;
vector <pii> qu[maxn];
int mood[maxn];
void read()
{
cin >> n >> q;
for(int i = 1; i <= n; i++)
cin >> a[i];
int l , r , k;
for(int idx = 1; idx <= q; idx++)
{
cin >> l >> r >> k;
qu[r].push_back({l , idx});
mood[idx] = k;
}
}
stack <pii> s;
int mem[maxn];
void solve()
{
for(int i = 1; i <= n; i++)
{
//cout << "in1" << endl;
while(s.empty() == false && s.top().X <= a[i])
s.pop();
if(s.empty() == false)
update(1 , 1 , n , s.top().Y , a[i] + s.top().X);
//cout << "in2" << endl;
s.push({a[i] , i});
for(auto& e : qu[i])
mem[e.Y] = query(1 , 1 , n , e.X , i);
}
for(int i = 1; i <= q; i++)
if(mem[i] <= mood[i])
cout << 1 << endl;
else
cout << 0 << endl;
}
int main()
{
/**#ifdef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif*/
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
///startT = std::chrono::high_resolution_clock::now();
read();
//control
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
29020 KB |
Output is correct |
2 |
Correct |
5 ms |
29140 KB |
Output is correct |
3 |
Correct |
4 ms |
29020 KB |
Output is correct |
4 |
Correct |
5 ms |
29020 KB |
Output is correct |
5 |
Correct |
4 ms |
29208 KB |
Output is correct |
6 |
Correct |
4 ms |
29020 KB |
Output is correct |
7 |
Correct |
4 ms |
29020 KB |
Output is correct |
8 |
Correct |
5 ms |
29156 KB |
Output is correct |
9 |
Correct |
5 ms |
29020 KB |
Output is correct |
10 |
Correct |
5 ms |
29020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
29020 KB |
Output is correct |
2 |
Correct |
5 ms |
29140 KB |
Output is correct |
3 |
Correct |
4 ms |
29020 KB |
Output is correct |
4 |
Correct |
5 ms |
29020 KB |
Output is correct |
5 |
Correct |
4 ms |
29208 KB |
Output is correct |
6 |
Correct |
4 ms |
29020 KB |
Output is correct |
7 |
Correct |
4 ms |
29020 KB |
Output is correct |
8 |
Correct |
5 ms |
29156 KB |
Output is correct |
9 |
Correct |
5 ms |
29020 KB |
Output is correct |
10 |
Correct |
5 ms |
29020 KB |
Output is correct |
11 |
Correct |
6 ms |
29276 KB |
Output is correct |
12 |
Correct |
6 ms |
29272 KB |
Output is correct |
13 |
Correct |
6 ms |
29276 KB |
Output is correct |
14 |
Correct |
7 ms |
29532 KB |
Output is correct |
15 |
Correct |
8 ms |
29532 KB |
Output is correct |
16 |
Correct |
6 ms |
29460 KB |
Output is correct |
17 |
Correct |
6 ms |
29276 KB |
Output is correct |
18 |
Correct |
7 ms |
29276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
881 ms |
97380 KB |
Output is correct |
2 |
Correct |
865 ms |
98644 KB |
Output is correct |
3 |
Correct |
860 ms |
98384 KB |
Output is correct |
4 |
Correct |
867 ms |
98384 KB |
Output is correct |
5 |
Correct |
746 ms |
92240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
38452 KB |
Output is correct |
2 |
Correct |
70 ms |
38004 KB |
Output is correct |
3 |
Correct |
57 ms |
37204 KB |
Output is correct |
4 |
Correct |
60 ms |
37248 KB |
Output is correct |
5 |
Correct |
56 ms |
37456 KB |
Output is correct |
6 |
Correct |
43 ms |
36432 KB |
Output is correct |
7 |
Correct |
41 ms |
36444 KB |
Output is correct |
8 |
Correct |
65 ms |
37060 KB |
Output is correct |
9 |
Correct |
27 ms |
35796 KB |
Output is correct |
10 |
Correct |
53 ms |
36900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
29020 KB |
Output is correct |
2 |
Correct |
5 ms |
29140 KB |
Output is correct |
3 |
Correct |
4 ms |
29020 KB |
Output is correct |
4 |
Correct |
5 ms |
29020 KB |
Output is correct |
5 |
Correct |
4 ms |
29208 KB |
Output is correct |
6 |
Correct |
4 ms |
29020 KB |
Output is correct |
7 |
Correct |
4 ms |
29020 KB |
Output is correct |
8 |
Correct |
5 ms |
29156 KB |
Output is correct |
9 |
Correct |
5 ms |
29020 KB |
Output is correct |
10 |
Correct |
5 ms |
29020 KB |
Output is correct |
11 |
Correct |
6 ms |
29276 KB |
Output is correct |
12 |
Correct |
6 ms |
29272 KB |
Output is correct |
13 |
Correct |
6 ms |
29276 KB |
Output is correct |
14 |
Correct |
7 ms |
29532 KB |
Output is correct |
15 |
Correct |
8 ms |
29532 KB |
Output is correct |
16 |
Correct |
6 ms |
29460 KB |
Output is correct |
17 |
Correct |
6 ms |
29276 KB |
Output is correct |
18 |
Correct |
7 ms |
29276 KB |
Output is correct |
19 |
Correct |
145 ms |
46164 KB |
Output is correct |
20 |
Correct |
141 ms |
46164 KB |
Output is correct |
21 |
Correct |
116 ms |
44880 KB |
Output is correct |
22 |
Correct |
119 ms |
44760 KB |
Output is correct |
23 |
Correct |
120 ms |
44884 KB |
Output is correct |
24 |
Correct |
95 ms |
42580 KB |
Output is correct |
25 |
Correct |
94 ms |
42580 KB |
Output is correct |
26 |
Correct |
119 ms |
43252 KB |
Output is correct |
27 |
Correct |
117 ms |
43300 KB |
Output is correct |
28 |
Correct |
114 ms |
43344 KB |
Output is correct |
29 |
Correct |
126 ms |
44116 KB |
Output is correct |
30 |
Correct |
130 ms |
44112 KB |
Output is correct |
31 |
Correct |
137 ms |
43980 KB |
Output is correct |
32 |
Correct |
122 ms |
44128 KB |
Output is correct |
33 |
Correct |
127 ms |
44112 KB |
Output is correct |
34 |
Correct |
97 ms |
42328 KB |
Output is correct |
35 |
Correct |
90 ms |
42320 KB |
Output is correct |
36 |
Correct |
91 ms |
41968 KB |
Output is correct |
37 |
Correct |
92 ms |
42068 KB |
Output is correct |
38 |
Correct |
106 ms |
42232 KB |
Output is correct |
39 |
Correct |
116 ms |
43116 KB |
Output is correct |
40 |
Correct |
92 ms |
41268 KB |
Output is correct |
41 |
Correct |
104 ms |
41928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
29020 KB |
Output is correct |
2 |
Correct |
5 ms |
29140 KB |
Output is correct |
3 |
Correct |
4 ms |
29020 KB |
Output is correct |
4 |
Correct |
5 ms |
29020 KB |
Output is correct |
5 |
Correct |
4 ms |
29208 KB |
Output is correct |
6 |
Correct |
4 ms |
29020 KB |
Output is correct |
7 |
Correct |
4 ms |
29020 KB |
Output is correct |
8 |
Correct |
5 ms |
29156 KB |
Output is correct |
9 |
Correct |
5 ms |
29020 KB |
Output is correct |
10 |
Correct |
5 ms |
29020 KB |
Output is correct |
11 |
Correct |
6 ms |
29276 KB |
Output is correct |
12 |
Correct |
6 ms |
29272 KB |
Output is correct |
13 |
Correct |
6 ms |
29276 KB |
Output is correct |
14 |
Correct |
7 ms |
29532 KB |
Output is correct |
15 |
Correct |
8 ms |
29532 KB |
Output is correct |
16 |
Correct |
6 ms |
29460 KB |
Output is correct |
17 |
Correct |
6 ms |
29276 KB |
Output is correct |
18 |
Correct |
7 ms |
29276 KB |
Output is correct |
19 |
Correct |
881 ms |
97380 KB |
Output is correct |
20 |
Correct |
865 ms |
98644 KB |
Output is correct |
21 |
Correct |
860 ms |
98384 KB |
Output is correct |
22 |
Correct |
867 ms |
98384 KB |
Output is correct |
23 |
Correct |
746 ms |
92240 KB |
Output is correct |
24 |
Correct |
80 ms |
38452 KB |
Output is correct |
25 |
Correct |
70 ms |
38004 KB |
Output is correct |
26 |
Correct |
57 ms |
37204 KB |
Output is correct |
27 |
Correct |
60 ms |
37248 KB |
Output is correct |
28 |
Correct |
56 ms |
37456 KB |
Output is correct |
29 |
Correct |
43 ms |
36432 KB |
Output is correct |
30 |
Correct |
41 ms |
36444 KB |
Output is correct |
31 |
Correct |
65 ms |
37060 KB |
Output is correct |
32 |
Correct |
27 ms |
35796 KB |
Output is correct |
33 |
Correct |
53 ms |
36900 KB |
Output is correct |
34 |
Correct |
145 ms |
46164 KB |
Output is correct |
35 |
Correct |
141 ms |
46164 KB |
Output is correct |
36 |
Correct |
116 ms |
44880 KB |
Output is correct |
37 |
Correct |
119 ms |
44760 KB |
Output is correct |
38 |
Correct |
120 ms |
44884 KB |
Output is correct |
39 |
Correct |
95 ms |
42580 KB |
Output is correct |
40 |
Correct |
94 ms |
42580 KB |
Output is correct |
41 |
Correct |
119 ms |
43252 KB |
Output is correct |
42 |
Correct |
117 ms |
43300 KB |
Output is correct |
43 |
Correct |
114 ms |
43344 KB |
Output is correct |
44 |
Correct |
126 ms |
44116 KB |
Output is correct |
45 |
Correct |
130 ms |
44112 KB |
Output is correct |
46 |
Correct |
137 ms |
43980 KB |
Output is correct |
47 |
Correct |
122 ms |
44128 KB |
Output is correct |
48 |
Correct |
127 ms |
44112 KB |
Output is correct |
49 |
Correct |
97 ms |
42328 KB |
Output is correct |
50 |
Correct |
90 ms |
42320 KB |
Output is correct |
51 |
Correct |
91 ms |
41968 KB |
Output is correct |
52 |
Correct |
92 ms |
42068 KB |
Output is correct |
53 |
Correct |
106 ms |
42232 KB |
Output is correct |
54 |
Correct |
116 ms |
43116 KB |
Output is correct |
55 |
Correct |
92 ms |
41268 KB |
Output is correct |
56 |
Correct |
104 ms |
41928 KB |
Output is correct |
57 |
Correct |
1022 ms |
98104 KB |
Output is correct |
58 |
Correct |
884 ms |
98200 KB |
Output is correct |
59 |
Correct |
733 ms |
95312 KB |
Output is correct |
60 |
Correct |
727 ms |
95308 KB |
Output is correct |
61 |
Correct |
750 ms |
95356 KB |
Output is correct |
62 |
Correct |
730 ms |
95524 KB |
Output is correct |
63 |
Correct |
488 ms |
83552 KB |
Output is correct |
64 |
Correct |
469 ms |
83540 KB |
Output is correct |
65 |
Correct |
724 ms |
88812 KB |
Output is correct |
66 |
Correct |
635 ms |
88680 KB |
Output is correct |
67 |
Correct |
680 ms |
88936 KB |
Output is correct |
68 |
Correct |
839 ms |
91712 KB |
Output is correct |
69 |
Correct |
715 ms |
91760 KB |
Output is correct |
70 |
Correct |
726 ms |
91284 KB |
Output is correct |
71 |
Correct |
681 ms |
91216 KB |
Output is correct |
72 |
Correct |
719 ms |
91220 KB |
Output is correct |
73 |
Correct |
444 ms |
80208 KB |
Output is correct |
74 |
Correct |
462 ms |
81488 KB |
Output is correct |
75 |
Correct |
467 ms |
80464 KB |
Output is correct |
76 |
Correct |
441 ms |
80468 KB |
Output is correct |
77 |
Correct |
430 ms |
80288 KB |
Output is correct |
78 |
Correct |
614 ms |
85596 KB |
Output is correct |
79 |
Correct |
502 ms |
74828 KB |
Output is correct |
80 |
Correct |
607 ms |
81172 KB |
Output is correct |