#include <bits/stdc++.h>
/*
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
#define mp make_pair
#define ll long long
#define ld long double
#define pb push_back
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fs first
#define sc second
#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define endl '\n'
#define con continue
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
const int INF = 2000000005;
const ll BIG_INF = 2000000000000000005;
const int mod = 1000000007;
const int P = 31;
const ld PI = 3.141592653589793238462643;
const double eps = 1e-9;
using namespace std;
vector< pair<int, int> > dir = {
{
-1, 0
},
{
0, 1
},
{
1, 0
},
{
0, -1
}
};
bool valid(int x, int y, int n, int m) {
return x >= 0 && y >= 0 && x < n && y < m;
}
mt19937 rng(1999999973);
const int N = 1000000 + 5;
int order[N], l[N], r[N], k[N], t[4 * N], a[N], ans[N], nxt[N], n, m;
stack<int> st;
inline void init() {
for (int i = 0; i < 4 * N; i++)
t[i] = -1;
for (int i = 0; i < N; i++)
nxt[i] = -1;
}
void add(int v, int tl, int tr, int pos, int val) {
if (!(pos >= tl && pos <= tr))
return;
t[v] = max(t[v], val);
if (tl == tr)
return;
int tm = (tl + tr) / 2;
add(v * 2, tl, tm, pos, val);
add(v * 2 + 1, tm + 1, tr, pos, val);
}
int getMax(int v, int tl, int tr, int l, int r) {
if (tl >= l && tr <= r)
return t[v];
if (tl > r || tr < l)
return -1;
int tm = (tl + tr) / 2;
return max(getMax(v * 2, tl, tm, l, r), getMax(v * 2 + 1, tm + 1, tr, l, r));
}
bool comp(int x, int y) {
return r[x] < r[y];
}
signed main() {
fast_io;
init();
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i] >> k[i];
l[i]--, r[i]--;
order[i] = i;
}
sort(order, order + m, comp);
for (int i = 0; i < n; i++) {
while(!st.empty() && a[st.top()] <= a[i])
st.pop();
if (!st.empty())
nxt[i] = st.top();
st.push(i);
}
int pointer = -1;
for (int v = 0; v < m; v++) {
int i = order[v];
while(pointer < r[i]) {
pointer++;
if (nxt[pointer] != -1)
add(1, 0, n - 1, nxt[pointer], a[nxt[pointer]] + a[pointer]);
}
ans[i] = (getMax(1, 0, n - 1, l[i], r[i]) <= k[i]);
}
for (int i = 0; i < m; i++)
cout << ans[i] << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
19960 KB |
Output is correct |
2 |
Correct |
19 ms |
19960 KB |
Output is correct |
3 |
Correct |
20 ms |
19960 KB |
Output is correct |
4 |
Correct |
19 ms |
19960 KB |
Output is correct |
5 |
Correct |
19 ms |
19932 KB |
Output is correct |
6 |
Correct |
20 ms |
19960 KB |
Output is correct |
7 |
Correct |
23 ms |
19960 KB |
Output is correct |
8 |
Correct |
20 ms |
19932 KB |
Output is correct |
9 |
Correct |
23 ms |
19960 KB |
Output is correct |
10 |
Correct |
23 ms |
19976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
19960 KB |
Output is correct |
2 |
Correct |
19 ms |
19960 KB |
Output is correct |
3 |
Correct |
20 ms |
19960 KB |
Output is correct |
4 |
Correct |
19 ms |
19960 KB |
Output is correct |
5 |
Correct |
19 ms |
19932 KB |
Output is correct |
6 |
Correct |
20 ms |
19960 KB |
Output is correct |
7 |
Correct |
23 ms |
19960 KB |
Output is correct |
8 |
Correct |
20 ms |
19932 KB |
Output is correct |
9 |
Correct |
23 ms |
19960 KB |
Output is correct |
10 |
Correct |
23 ms |
19976 KB |
Output is correct |
11 |
Correct |
22 ms |
20088 KB |
Output is correct |
12 |
Correct |
22 ms |
20172 KB |
Output is correct |
13 |
Correct |
41 ms |
20188 KB |
Output is correct |
14 |
Correct |
25 ms |
20216 KB |
Output is correct |
15 |
Correct |
25 ms |
20216 KB |
Output is correct |
16 |
Correct |
23 ms |
20180 KB |
Output is correct |
17 |
Correct |
23 ms |
20188 KB |
Output is correct |
18 |
Correct |
23 ms |
20216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1841 ms |
76988 KB |
Output is correct |
2 |
Correct |
1762 ms |
78300 KB |
Output is correct |
3 |
Correct |
1752 ms |
78088 KB |
Output is correct |
4 |
Correct |
1739 ms |
78356 KB |
Output is correct |
5 |
Correct |
1519 ms |
78268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
24540 KB |
Output is correct |
2 |
Correct |
128 ms |
24444 KB |
Output is correct |
3 |
Correct |
120 ms |
24440 KB |
Output is correct |
4 |
Correct |
123 ms |
24568 KB |
Output is correct |
5 |
Correct |
124 ms |
24504 KB |
Output is correct |
6 |
Correct |
106 ms |
24312 KB |
Output is correct |
7 |
Correct |
107 ms |
24312 KB |
Output is correct |
8 |
Correct |
111 ms |
24184 KB |
Output is correct |
9 |
Correct |
72 ms |
23416 KB |
Output is correct |
10 |
Correct |
111 ms |
24188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
19960 KB |
Output is correct |
2 |
Correct |
19 ms |
19960 KB |
Output is correct |
3 |
Correct |
20 ms |
19960 KB |
Output is correct |
4 |
Correct |
19 ms |
19960 KB |
Output is correct |
5 |
Correct |
19 ms |
19932 KB |
Output is correct |
6 |
Correct |
20 ms |
19960 KB |
Output is correct |
7 |
Correct |
23 ms |
19960 KB |
Output is correct |
8 |
Correct |
20 ms |
19932 KB |
Output is correct |
9 |
Correct |
23 ms |
19960 KB |
Output is correct |
10 |
Correct |
23 ms |
19976 KB |
Output is correct |
11 |
Correct |
22 ms |
20088 KB |
Output is correct |
12 |
Correct |
22 ms |
20172 KB |
Output is correct |
13 |
Correct |
41 ms |
20188 KB |
Output is correct |
14 |
Correct |
25 ms |
20216 KB |
Output is correct |
15 |
Correct |
25 ms |
20216 KB |
Output is correct |
16 |
Correct |
23 ms |
20180 KB |
Output is correct |
17 |
Correct |
23 ms |
20188 KB |
Output is correct |
18 |
Correct |
23 ms |
20216 KB |
Output is correct |
19 |
Correct |
318 ms |
31736 KB |
Output is correct |
20 |
Correct |
323 ms |
31676 KB |
Output is correct |
21 |
Correct |
273 ms |
31480 KB |
Output is correct |
22 |
Correct |
279 ms |
31608 KB |
Output is correct |
23 |
Correct |
288 ms |
31584 KB |
Output is correct |
24 |
Correct |
242 ms |
31344 KB |
Output is correct |
25 |
Correct |
237 ms |
31480 KB |
Output is correct |
26 |
Correct |
259 ms |
31560 KB |
Output is correct |
27 |
Correct |
279 ms |
31704 KB |
Output is correct |
28 |
Correct |
308 ms |
31736 KB |
Output is correct |
29 |
Correct |
274 ms |
31676 KB |
Output is correct |
30 |
Correct |
269 ms |
31716 KB |
Output is correct |
31 |
Correct |
270 ms |
31676 KB |
Output is correct |
32 |
Correct |
292 ms |
31720 KB |
Output is correct |
33 |
Correct |
269 ms |
31736 KB |
Output is correct |
34 |
Correct |
236 ms |
31276 KB |
Output is correct |
35 |
Correct |
252 ms |
31312 KB |
Output is correct |
36 |
Correct |
238 ms |
31248 KB |
Output is correct |
37 |
Correct |
229 ms |
31096 KB |
Output is correct |
38 |
Correct |
230 ms |
31224 KB |
Output is correct |
39 |
Correct |
255 ms |
30344 KB |
Output is correct |
40 |
Correct |
200 ms |
29284 KB |
Output is correct |
41 |
Correct |
235 ms |
29788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
19960 KB |
Output is correct |
2 |
Correct |
19 ms |
19960 KB |
Output is correct |
3 |
Correct |
20 ms |
19960 KB |
Output is correct |
4 |
Correct |
19 ms |
19960 KB |
Output is correct |
5 |
Correct |
19 ms |
19932 KB |
Output is correct |
6 |
Correct |
20 ms |
19960 KB |
Output is correct |
7 |
Correct |
23 ms |
19960 KB |
Output is correct |
8 |
Correct |
20 ms |
19932 KB |
Output is correct |
9 |
Correct |
23 ms |
19960 KB |
Output is correct |
10 |
Correct |
23 ms |
19976 KB |
Output is correct |
11 |
Correct |
22 ms |
20088 KB |
Output is correct |
12 |
Correct |
22 ms |
20172 KB |
Output is correct |
13 |
Correct |
41 ms |
20188 KB |
Output is correct |
14 |
Correct |
25 ms |
20216 KB |
Output is correct |
15 |
Correct |
25 ms |
20216 KB |
Output is correct |
16 |
Correct |
23 ms |
20180 KB |
Output is correct |
17 |
Correct |
23 ms |
20188 KB |
Output is correct |
18 |
Correct |
23 ms |
20216 KB |
Output is correct |
19 |
Correct |
1841 ms |
76988 KB |
Output is correct |
20 |
Correct |
1762 ms |
78300 KB |
Output is correct |
21 |
Correct |
1752 ms |
78088 KB |
Output is correct |
22 |
Correct |
1739 ms |
78356 KB |
Output is correct |
23 |
Correct |
1519 ms |
78268 KB |
Output is correct |
24 |
Correct |
144 ms |
24540 KB |
Output is correct |
25 |
Correct |
128 ms |
24444 KB |
Output is correct |
26 |
Correct |
120 ms |
24440 KB |
Output is correct |
27 |
Correct |
123 ms |
24568 KB |
Output is correct |
28 |
Correct |
124 ms |
24504 KB |
Output is correct |
29 |
Correct |
106 ms |
24312 KB |
Output is correct |
30 |
Correct |
107 ms |
24312 KB |
Output is correct |
31 |
Correct |
111 ms |
24184 KB |
Output is correct |
32 |
Correct |
72 ms |
23416 KB |
Output is correct |
33 |
Correct |
111 ms |
24188 KB |
Output is correct |
34 |
Correct |
318 ms |
31736 KB |
Output is correct |
35 |
Correct |
323 ms |
31676 KB |
Output is correct |
36 |
Correct |
273 ms |
31480 KB |
Output is correct |
37 |
Correct |
279 ms |
31608 KB |
Output is correct |
38 |
Correct |
288 ms |
31584 KB |
Output is correct |
39 |
Correct |
242 ms |
31344 KB |
Output is correct |
40 |
Correct |
237 ms |
31480 KB |
Output is correct |
41 |
Correct |
259 ms |
31560 KB |
Output is correct |
42 |
Correct |
279 ms |
31704 KB |
Output is correct |
43 |
Correct |
308 ms |
31736 KB |
Output is correct |
44 |
Correct |
274 ms |
31676 KB |
Output is correct |
45 |
Correct |
269 ms |
31716 KB |
Output is correct |
46 |
Correct |
270 ms |
31676 KB |
Output is correct |
47 |
Correct |
292 ms |
31720 KB |
Output is correct |
48 |
Correct |
269 ms |
31736 KB |
Output is correct |
49 |
Correct |
236 ms |
31276 KB |
Output is correct |
50 |
Correct |
252 ms |
31312 KB |
Output is correct |
51 |
Correct |
238 ms |
31248 KB |
Output is correct |
52 |
Correct |
229 ms |
31096 KB |
Output is correct |
53 |
Correct |
230 ms |
31224 KB |
Output is correct |
54 |
Correct |
255 ms |
30344 KB |
Output is correct |
55 |
Correct |
200 ms |
29284 KB |
Output is correct |
56 |
Correct |
235 ms |
29788 KB |
Output is correct |
57 |
Correct |
1720 ms |
78940 KB |
Output is correct |
58 |
Correct |
1828 ms |
78984 KB |
Output is correct |
59 |
Correct |
1703 ms |
78912 KB |
Output is correct |
60 |
Correct |
1690 ms |
78860 KB |
Output is correct |
61 |
Correct |
1670 ms |
78856 KB |
Output is correct |
62 |
Correct |
1688 ms |
78784 KB |
Output is correct |
63 |
Correct |
1301 ms |
77072 KB |
Output is correct |
64 |
Correct |
1339 ms |
77048 KB |
Output is correct |
65 |
Correct |
1508 ms |
78904 KB |
Output is correct |
66 |
Correct |
1681 ms |
78892 KB |
Output is correct |
67 |
Correct |
1506 ms |
78796 KB |
Output is correct |
68 |
Correct |
1518 ms |
79012 KB |
Output is correct |
69 |
Correct |
1651 ms |
78872 KB |
Output is correct |
70 |
Correct |
1508 ms |
78880 KB |
Output is correct |
71 |
Correct |
1525 ms |
79008 KB |
Output is correct |
72 |
Correct |
1584 ms |
78888 KB |
Output is correct |
73 |
Correct |
1257 ms |
75468 KB |
Output is correct |
74 |
Correct |
1269 ms |
76444 KB |
Output is correct |
75 |
Correct |
1259 ms |
75420 KB |
Output is correct |
76 |
Correct |
1253 ms |
75512 KB |
Output is correct |
77 |
Correct |
1349 ms |
75420 KB |
Output is correct |
78 |
Correct |
1394 ms |
72812 KB |
Output is correct |
79 |
Correct |
1024 ms |
66168 KB |
Output is correct |
80 |
Correct |
1378 ms |
70044 KB |
Output is correct |