/* Speech to the young */
//#include <bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <unordered_map>
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define YOSIK() ios_base::sync_with_stdio(0),cin.tie(0)
#define int long long
#define pans cout << "\n------ans-------\n"
const int N = 1e6 + 10;
const int INF = 1e18 + 7;
const int MOD = 1e9 + 7;
const int P = 31;
int n, m, t[N * 4];
int a[N], res[N], l[N], r[N], k[N];
vector <int> qu[N];
void upd (int v, int tl, int tr, int pos, int val) {
if (tl == tr) {
t[v] = val;
return;
}
int mid = (tl + tr) >> 1;
if (pos <= mid) upd (v + v, tl, mid, pos, val);
else upd (v + v + 1, mid + 1, tr, pos, val);
t[v] = max (t[v + v], t[v + v + 1]);
return;
}
int get (int v, int tl, int tr, int l, int r) {
if (l <= tl && tr <= r) return t[v];
if (tr < l || r < tl) return 0;
int mid = (tl + tr) >> 1;
return max (get (v + v, tl, mid, l, r), get (v + v + 1, mid + 1, tr, l, r));
}
void Solution () {
cin >> n >> m;
for (int i = 1; i <= n; ++ i) cin >> a[i];
stack <int> s;
for (int i = 1; i <= m; ++ i) {
cin >> l[i] >> r[i] >> k[i];
qu[r[i]].pb (i);
}
s.push (0);
a[0] = INF;
for (int i = 1; i <= n; ++ i) {
while (a[s.top()] <= a[i]) s.pop();
if (s.top() != 0) upd (1, 1, n, s.top(), a[s.top()] + a[i]);
s.push (i);
for (auto to: qu[i]) if (get (1, 1, n, l[to], i) <= k[to]) res[to] = 1;
}
for (int i = 1; i <= m; ++ i) cout << res[i] << '\n';
return;
}
signed main () {
YOSIK();
// precalc();
int T = 1;
//cin >> T;
while (T --) Solution ();
exit (0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
3 |
Correct |
11 ms |
23760 KB |
Output is correct |
4 |
Correct |
12 ms |
23820 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23784 KB |
Output is correct |
7 |
Correct |
14 ms |
23872 KB |
Output is correct |
8 |
Correct |
15 ms |
23912 KB |
Output is correct |
9 |
Correct |
12 ms |
23884 KB |
Output is correct |
10 |
Correct |
12 ms |
23868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
3 |
Correct |
11 ms |
23760 KB |
Output is correct |
4 |
Correct |
12 ms |
23820 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23784 KB |
Output is correct |
7 |
Correct |
14 ms |
23872 KB |
Output is correct |
8 |
Correct |
15 ms |
23912 KB |
Output is correct |
9 |
Correct |
12 ms |
23884 KB |
Output is correct |
10 |
Correct |
12 ms |
23868 KB |
Output is correct |
11 |
Correct |
14 ms |
23948 KB |
Output is correct |
12 |
Correct |
14 ms |
24108 KB |
Output is correct |
13 |
Correct |
15 ms |
24064 KB |
Output is correct |
14 |
Correct |
15 ms |
24248 KB |
Output is correct |
15 |
Correct |
16 ms |
24276 KB |
Output is correct |
16 |
Correct |
16 ms |
24108 KB |
Output is correct |
17 |
Correct |
14 ms |
24156 KB |
Output is correct |
18 |
Correct |
16 ms |
24092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1393 ms |
93404 KB |
Output is correct |
2 |
Correct |
1414 ms |
93380 KB |
Output is correct |
3 |
Correct |
1515 ms |
93308 KB |
Output is correct |
4 |
Correct |
1444 ms |
93672 KB |
Output is correct |
5 |
Correct |
1229 ms |
85092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
119 ms |
32368 KB |
Output is correct |
2 |
Correct |
98 ms |
31756 KB |
Output is correct |
3 |
Correct |
94 ms |
29848 KB |
Output is correct |
4 |
Correct |
91 ms |
29980 KB |
Output is correct |
5 |
Correct |
94 ms |
30064 KB |
Output is correct |
6 |
Correct |
80 ms |
28640 KB |
Output is correct |
7 |
Correct |
83 ms |
28584 KB |
Output is correct |
8 |
Correct |
78 ms |
29964 KB |
Output is correct |
9 |
Correct |
59 ms |
28372 KB |
Output is correct |
10 |
Correct |
95 ms |
29916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
3 |
Correct |
11 ms |
23760 KB |
Output is correct |
4 |
Correct |
12 ms |
23820 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23784 KB |
Output is correct |
7 |
Correct |
14 ms |
23872 KB |
Output is correct |
8 |
Correct |
15 ms |
23912 KB |
Output is correct |
9 |
Correct |
12 ms |
23884 KB |
Output is correct |
10 |
Correct |
12 ms |
23868 KB |
Output is correct |
11 |
Correct |
14 ms |
23948 KB |
Output is correct |
12 |
Correct |
14 ms |
24108 KB |
Output is correct |
13 |
Correct |
15 ms |
24064 KB |
Output is correct |
14 |
Correct |
15 ms |
24248 KB |
Output is correct |
15 |
Correct |
16 ms |
24276 KB |
Output is correct |
16 |
Correct |
16 ms |
24108 KB |
Output is correct |
17 |
Correct |
14 ms |
24156 KB |
Output is correct |
18 |
Correct |
16 ms |
24092 KB |
Output is correct |
19 |
Correct |
240 ms |
40280 KB |
Output is correct |
20 |
Correct |
242 ms |
40052 KB |
Output is correct |
21 |
Correct |
204 ms |
39052 KB |
Output is correct |
22 |
Correct |
201 ms |
38964 KB |
Output is correct |
23 |
Correct |
219 ms |
38920 KB |
Output is correct |
24 |
Correct |
197 ms |
34836 KB |
Output is correct |
25 |
Correct |
184 ms |
34848 KB |
Output is correct |
26 |
Correct |
209 ms |
35320 KB |
Output is correct |
27 |
Correct |
207 ms |
35324 KB |
Output is correct |
28 |
Correct |
195 ms |
35460 KB |
Output is correct |
29 |
Correct |
228 ms |
36048 KB |
Output is correct |
30 |
Correct |
216 ms |
35984 KB |
Output is correct |
31 |
Correct |
202 ms |
35908 KB |
Output is correct |
32 |
Correct |
204 ms |
35996 KB |
Output is correct |
33 |
Correct |
207 ms |
36096 KB |
Output is correct |
34 |
Correct |
164 ms |
34528 KB |
Output is correct |
35 |
Correct |
158 ms |
34508 KB |
Output is correct |
36 |
Correct |
165 ms |
34676 KB |
Output is correct |
37 |
Correct |
219 ms |
34608 KB |
Output is correct |
38 |
Correct |
185 ms |
34592 KB |
Output is correct |
39 |
Correct |
174 ms |
37112 KB |
Output is correct |
40 |
Correct |
212 ms |
34876 KB |
Output is correct |
41 |
Correct |
176 ms |
35860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
3 |
Correct |
11 ms |
23760 KB |
Output is correct |
4 |
Correct |
12 ms |
23820 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23784 KB |
Output is correct |
7 |
Correct |
14 ms |
23872 KB |
Output is correct |
8 |
Correct |
15 ms |
23912 KB |
Output is correct |
9 |
Correct |
12 ms |
23884 KB |
Output is correct |
10 |
Correct |
12 ms |
23868 KB |
Output is correct |
11 |
Correct |
14 ms |
23948 KB |
Output is correct |
12 |
Correct |
14 ms |
24108 KB |
Output is correct |
13 |
Correct |
15 ms |
24064 KB |
Output is correct |
14 |
Correct |
15 ms |
24248 KB |
Output is correct |
15 |
Correct |
16 ms |
24276 KB |
Output is correct |
16 |
Correct |
16 ms |
24108 KB |
Output is correct |
17 |
Correct |
14 ms |
24156 KB |
Output is correct |
18 |
Correct |
16 ms |
24092 KB |
Output is correct |
19 |
Correct |
1393 ms |
93404 KB |
Output is correct |
20 |
Correct |
1414 ms |
93380 KB |
Output is correct |
21 |
Correct |
1515 ms |
93308 KB |
Output is correct |
22 |
Correct |
1444 ms |
93672 KB |
Output is correct |
23 |
Correct |
1229 ms |
85092 KB |
Output is correct |
24 |
Correct |
119 ms |
32368 KB |
Output is correct |
25 |
Correct |
98 ms |
31756 KB |
Output is correct |
26 |
Correct |
94 ms |
29848 KB |
Output is correct |
27 |
Correct |
91 ms |
29980 KB |
Output is correct |
28 |
Correct |
94 ms |
30064 KB |
Output is correct |
29 |
Correct |
80 ms |
28640 KB |
Output is correct |
30 |
Correct |
83 ms |
28584 KB |
Output is correct |
31 |
Correct |
78 ms |
29964 KB |
Output is correct |
32 |
Correct |
59 ms |
28372 KB |
Output is correct |
33 |
Correct |
95 ms |
29916 KB |
Output is correct |
34 |
Correct |
240 ms |
40280 KB |
Output is correct |
35 |
Correct |
242 ms |
40052 KB |
Output is correct |
36 |
Correct |
204 ms |
39052 KB |
Output is correct |
37 |
Correct |
201 ms |
38964 KB |
Output is correct |
38 |
Correct |
219 ms |
38920 KB |
Output is correct |
39 |
Correct |
197 ms |
34836 KB |
Output is correct |
40 |
Correct |
184 ms |
34848 KB |
Output is correct |
41 |
Correct |
209 ms |
35320 KB |
Output is correct |
42 |
Correct |
207 ms |
35324 KB |
Output is correct |
43 |
Correct |
195 ms |
35460 KB |
Output is correct |
44 |
Correct |
228 ms |
36048 KB |
Output is correct |
45 |
Correct |
216 ms |
35984 KB |
Output is correct |
46 |
Correct |
202 ms |
35908 KB |
Output is correct |
47 |
Correct |
204 ms |
35996 KB |
Output is correct |
48 |
Correct |
207 ms |
36096 KB |
Output is correct |
49 |
Correct |
164 ms |
34528 KB |
Output is correct |
50 |
Correct |
158 ms |
34508 KB |
Output is correct |
51 |
Correct |
165 ms |
34676 KB |
Output is correct |
52 |
Correct |
219 ms |
34608 KB |
Output is correct |
53 |
Correct |
185 ms |
34592 KB |
Output is correct |
54 |
Correct |
174 ms |
37112 KB |
Output is correct |
55 |
Correct |
212 ms |
34876 KB |
Output is correct |
56 |
Correct |
176 ms |
35860 KB |
Output is correct |
57 |
Correct |
1417 ms |
100416 KB |
Output is correct |
58 |
Correct |
1544 ms |
100444 KB |
Output is correct |
59 |
Correct |
1498 ms |
97720 KB |
Output is correct |
60 |
Correct |
1336 ms |
98008 KB |
Output is correct |
61 |
Correct |
1349 ms |
98460 KB |
Output is correct |
62 |
Correct |
1360 ms |
98000 KB |
Output is correct |
63 |
Correct |
849 ms |
78204 KB |
Output is correct |
64 |
Correct |
865 ms |
78008 KB |
Output is correct |
65 |
Correct |
1134 ms |
81580 KB |
Output is correct |
66 |
Correct |
1092 ms |
81516 KB |
Output is correct |
67 |
Correct |
1130 ms |
81448 KB |
Output is correct |
68 |
Correct |
1134 ms |
84512 KB |
Output is correct |
69 |
Correct |
1129 ms |
84276 KB |
Output is correct |
70 |
Correct |
1138 ms |
83796 KB |
Output is correct |
71 |
Correct |
1117 ms |
83888 KB |
Output is correct |
72 |
Correct |
1147 ms |
83764 KB |
Output is correct |
73 |
Correct |
830 ms |
76364 KB |
Output is correct |
74 |
Correct |
858 ms |
76392 KB |
Output is correct |
75 |
Correct |
931 ms |
76580 KB |
Output is correct |
76 |
Correct |
839 ms |
76284 KB |
Output is correct |
77 |
Correct |
812 ms |
76424 KB |
Output is correct |
78 |
Correct |
991 ms |
88040 KB |
Output is correct |
79 |
Correct |
801 ms |
76556 KB |
Output is correct |
80 |
Correct |
1059 ms |
83136 KB |
Output is correct |