#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, m;
int a[maxN];
int st[4 * maxN];
void update(int id, int l, int r, int pos, int val)
{
if(l > pos || r < pos) return;
if(l == r && l == pos)
{
st[id] = max(st[id], val);
return;
}
int mid = (l + r) / 2;
update(id * 2, l, mid, pos, val);
update(id * 2 + 1, mid + 1, r, pos, val);
st[id] = max(st[id * 2], st[id * 2 + 1]);
}
int get(int id, int l, int r, int u, int v)
{
if(l > v || r < u) return 0;
if(l >= u && r <= v) return st[id];
int mid = (l + r) / 2;
return max(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
}
struct TQuery
{
int l, k, id;
};
vector<TQuery> q[maxN];
void ReadInput()
{
cin >> n >> m;
for(int i=1; i<=n; i++) cin >> a[i];
for(int i=1; i<=m; i++)
{
int l, r, k;
cin >> l >> r >> k;
q[r].pb({l, k, i});
}
}
int res[maxN];
void Solve()
{
stack<int> s;
for(int i=1; i<=n; i++)
{
while(!s.empty() && a[s.top()] <= a[i]) s.pop();
if(!s.empty()) update(1, 1, n, s.top(), a[s.top()] + a[i]);
s.push(i);
for(TQuery a : q[i])
{
res[a.id] = get(1, 1, n, a.l, i) <= a.k;
}
}
for(int i=1; i<=m; i++) cout << res[i] << '\n';
}
int32_t main()
{
// freopen("x.inp", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ReadInput();
Solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23796 KB |
Output is correct |
3 |
Correct |
14 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
14 ms |
23912 KB |
Output is correct |
6 |
Correct |
13 ms |
23912 KB |
Output is correct |
7 |
Correct |
14 ms |
23848 KB |
Output is correct |
8 |
Correct |
16 ms |
23764 KB |
Output is correct |
9 |
Correct |
13 ms |
23860 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23796 KB |
Output is correct |
3 |
Correct |
14 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
14 ms |
23912 KB |
Output is correct |
6 |
Correct |
13 ms |
23912 KB |
Output is correct |
7 |
Correct |
14 ms |
23848 KB |
Output is correct |
8 |
Correct |
16 ms |
23764 KB |
Output is correct |
9 |
Correct |
13 ms |
23860 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
14 ms |
24020 KB |
Output is correct |
12 |
Correct |
15 ms |
24148 KB |
Output is correct |
13 |
Correct |
16 ms |
24236 KB |
Output is correct |
14 |
Correct |
17 ms |
24300 KB |
Output is correct |
15 |
Correct |
17 ms |
24288 KB |
Output is correct |
16 |
Correct |
16 ms |
24236 KB |
Output is correct |
17 |
Correct |
16 ms |
24096 KB |
Output is correct |
18 |
Correct |
16 ms |
24096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1496 ms |
122152 KB |
Output is correct |
2 |
Correct |
1391 ms |
123436 KB |
Output is correct |
3 |
Correct |
1396 ms |
123248 KB |
Output is correct |
4 |
Correct |
1420 ms |
123288 KB |
Output is correct |
5 |
Correct |
1074 ms |
106948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
145 ms |
32888 KB |
Output is correct |
2 |
Correct |
91 ms |
33028 KB |
Output is correct |
3 |
Correct |
84 ms |
30824 KB |
Output is correct |
4 |
Correct |
103 ms |
30812 KB |
Output is correct |
5 |
Correct |
94 ms |
30732 KB |
Output is correct |
6 |
Correct |
70 ms |
30804 KB |
Output is correct |
7 |
Correct |
70 ms |
30800 KB |
Output is correct |
8 |
Correct |
82 ms |
30252 KB |
Output is correct |
9 |
Correct |
46 ms |
28968 KB |
Output is correct |
10 |
Correct |
108 ms |
30196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23796 KB |
Output is correct |
3 |
Correct |
14 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
14 ms |
23912 KB |
Output is correct |
6 |
Correct |
13 ms |
23912 KB |
Output is correct |
7 |
Correct |
14 ms |
23848 KB |
Output is correct |
8 |
Correct |
16 ms |
23764 KB |
Output is correct |
9 |
Correct |
13 ms |
23860 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
14 ms |
24020 KB |
Output is correct |
12 |
Correct |
15 ms |
24148 KB |
Output is correct |
13 |
Correct |
16 ms |
24236 KB |
Output is correct |
14 |
Correct |
17 ms |
24300 KB |
Output is correct |
15 |
Correct |
17 ms |
24288 KB |
Output is correct |
16 |
Correct |
16 ms |
24236 KB |
Output is correct |
17 |
Correct |
16 ms |
24096 KB |
Output is correct |
18 |
Correct |
16 ms |
24096 KB |
Output is correct |
19 |
Correct |
255 ms |
44588 KB |
Output is correct |
20 |
Correct |
277 ms |
44688 KB |
Output is correct |
21 |
Correct |
196 ms |
45012 KB |
Output is correct |
22 |
Correct |
198 ms |
44996 KB |
Output is correct |
23 |
Correct |
211 ms |
44892 KB |
Output is correct |
24 |
Correct |
154 ms |
40820 KB |
Output is correct |
25 |
Correct |
156 ms |
40860 KB |
Output is correct |
26 |
Correct |
197 ms |
40760 KB |
Output is correct |
27 |
Correct |
170 ms |
40612 KB |
Output is correct |
28 |
Correct |
177 ms |
40504 KB |
Output is correct |
29 |
Correct |
223 ms |
40440 KB |
Output is correct |
30 |
Correct |
187 ms |
40484 KB |
Output is correct |
31 |
Correct |
219 ms |
40500 KB |
Output is correct |
32 |
Correct |
192 ms |
40432 KB |
Output is correct |
33 |
Correct |
187 ms |
40472 KB |
Output is correct |
34 |
Correct |
151 ms |
40244 KB |
Output is correct |
35 |
Correct |
172 ms |
40140 KB |
Output is correct |
36 |
Correct |
147 ms |
40012 KB |
Output is correct |
37 |
Correct |
147 ms |
39968 KB |
Output is correct |
38 |
Correct |
150 ms |
40396 KB |
Output is correct |
39 |
Correct |
167 ms |
39956 KB |
Output is correct |
40 |
Correct |
148 ms |
36884 KB |
Output is correct |
41 |
Correct |
164 ms |
37948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23796 KB |
Output is correct |
3 |
Correct |
14 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
14 ms |
23912 KB |
Output is correct |
6 |
Correct |
13 ms |
23912 KB |
Output is correct |
7 |
Correct |
14 ms |
23848 KB |
Output is correct |
8 |
Correct |
16 ms |
23764 KB |
Output is correct |
9 |
Correct |
13 ms |
23860 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
14 ms |
24020 KB |
Output is correct |
12 |
Correct |
15 ms |
24148 KB |
Output is correct |
13 |
Correct |
16 ms |
24236 KB |
Output is correct |
14 |
Correct |
17 ms |
24300 KB |
Output is correct |
15 |
Correct |
17 ms |
24288 KB |
Output is correct |
16 |
Correct |
16 ms |
24236 KB |
Output is correct |
17 |
Correct |
16 ms |
24096 KB |
Output is correct |
18 |
Correct |
16 ms |
24096 KB |
Output is correct |
19 |
Correct |
1496 ms |
122152 KB |
Output is correct |
20 |
Correct |
1391 ms |
123436 KB |
Output is correct |
21 |
Correct |
1396 ms |
123248 KB |
Output is correct |
22 |
Correct |
1420 ms |
123288 KB |
Output is correct |
23 |
Correct |
1074 ms |
106948 KB |
Output is correct |
24 |
Correct |
145 ms |
32888 KB |
Output is correct |
25 |
Correct |
91 ms |
33028 KB |
Output is correct |
26 |
Correct |
84 ms |
30824 KB |
Output is correct |
27 |
Correct |
103 ms |
30812 KB |
Output is correct |
28 |
Correct |
94 ms |
30732 KB |
Output is correct |
29 |
Correct |
70 ms |
30804 KB |
Output is correct |
30 |
Correct |
70 ms |
30800 KB |
Output is correct |
31 |
Correct |
82 ms |
30252 KB |
Output is correct |
32 |
Correct |
46 ms |
28968 KB |
Output is correct |
33 |
Correct |
108 ms |
30196 KB |
Output is correct |
34 |
Correct |
255 ms |
44588 KB |
Output is correct |
35 |
Correct |
277 ms |
44688 KB |
Output is correct |
36 |
Correct |
196 ms |
45012 KB |
Output is correct |
37 |
Correct |
198 ms |
44996 KB |
Output is correct |
38 |
Correct |
211 ms |
44892 KB |
Output is correct |
39 |
Correct |
154 ms |
40820 KB |
Output is correct |
40 |
Correct |
156 ms |
40860 KB |
Output is correct |
41 |
Correct |
197 ms |
40760 KB |
Output is correct |
42 |
Correct |
170 ms |
40612 KB |
Output is correct |
43 |
Correct |
177 ms |
40504 KB |
Output is correct |
44 |
Correct |
223 ms |
40440 KB |
Output is correct |
45 |
Correct |
187 ms |
40484 KB |
Output is correct |
46 |
Correct |
219 ms |
40500 KB |
Output is correct |
47 |
Correct |
192 ms |
40432 KB |
Output is correct |
48 |
Correct |
187 ms |
40472 KB |
Output is correct |
49 |
Correct |
151 ms |
40244 KB |
Output is correct |
50 |
Correct |
172 ms |
40140 KB |
Output is correct |
51 |
Correct |
147 ms |
40012 KB |
Output is correct |
52 |
Correct |
147 ms |
39968 KB |
Output is correct |
53 |
Correct |
150 ms |
40396 KB |
Output is correct |
54 |
Correct |
167 ms |
39956 KB |
Output is correct |
55 |
Correct |
148 ms |
36884 KB |
Output is correct |
56 |
Correct |
164 ms |
37948 KB |
Output is correct |
57 |
Correct |
1482 ms |
124132 KB |
Output is correct |
58 |
Correct |
1444 ms |
124136 KB |
Output is correct |
59 |
Correct |
1360 ms |
124916 KB |
Output is correct |
60 |
Correct |
1343 ms |
124984 KB |
Output is correct |
61 |
Correct |
1358 ms |
125008 KB |
Output is correct |
62 |
Correct |
1269 ms |
125024 KB |
Output is correct |
63 |
Correct |
783 ms |
108580 KB |
Output is correct |
64 |
Correct |
796 ms |
108572 KB |
Output is correct |
65 |
Correct |
1079 ms |
108536 KB |
Output is correct |
66 |
Correct |
1096 ms |
108628 KB |
Output is correct |
67 |
Correct |
1045 ms |
108460 KB |
Output is correct |
68 |
Correct |
1122 ms |
107768 KB |
Output is correct |
69 |
Correct |
1061 ms |
107776 KB |
Output is correct |
70 |
Correct |
1068 ms |
107776 KB |
Output is correct |
71 |
Correct |
1092 ms |
107992 KB |
Output is correct |
72 |
Correct |
1087 ms |
107900 KB |
Output is correct |
73 |
Correct |
779 ms |
102700 KB |
Output is correct |
74 |
Correct |
762 ms |
103540 KB |
Output is correct |
75 |
Correct |
755 ms |
102344 KB |
Output is correct |
76 |
Correct |
735 ms |
102884 KB |
Output is correct |
77 |
Correct |
731 ms |
102552 KB |
Output is correct |
78 |
Correct |
1024 ms |
104656 KB |
Output is correct |
79 |
Correct |
680 ms |
88168 KB |
Output is correct |
80 |
Correct |
963 ms |
95512 KB |
Output is correct |