#include <bits/stdc++.h>
#define FOR(i,x,n) for(int i=x; i<n; i++)
#define F0R(i,n) FOR(i,0,n)
#define ROF(i,x,n) for(int i=n-1; i>=x; i--)
#define R0F(i,n) ROF(i,0,n)
#define WTF cout << "WTF" << endl
#define IOS ios::sync_with_stdio(false); cin.tie(0)
#define F first
#define S second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
const int MAXN = 1e6 + 7;
const int ALPHA = 27;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int LOG = 22;
struct Query {
int lo, hi, k;
int id;
inline bool operator < (const Query other) {
return hi < other.hi;
}
} qs[MAXN];
int n, q;
int ns[MAXN], agh[MAXN];
int tree[MAXN << 2], ans[MAXN];
int get(int lq, int rq, int now_on = 1, int ls = 0, int rs = n - 1) {
if (rq < lq || rq < ls || rs < lq)
return -INF;
if (lq <= ls && rs <= rq)
return tree[now_on];
int mid = (ls + rs) >> 1;
return max(get(lq, rq, now_on << 1, ls, mid), get(lq, rq, now_on << 1 | 1, mid + 1, rs));
}
void change(int id, int val, int now_on = 1, int ls = 0, int rs = n - 1) {
if (ls == rs) {
tree[now_on] = val;
return;
}
int mid = (ls + rs) >> 1;
if (id <= mid) change(id, val, now_on << 1, ls, mid);
else change(id, val, now_on << 1 | 1, mid + 1, rs);
tree[now_on] = max(tree[now_on << 1], tree[now_on << 1 | 1]);
return;
}
int main() {
IOS;
cin >> n >> q;
F0R(i, n) cin >> ns[i];
stack<int> keep;
F0R(i, n) {
while(!keep.empty() && ns[keep.top()] <= ns[i])
keep.pop();
if (keep.empty()) agh[i] = -1;
else agh[i] = keep.top();
keep.push(i);
}
/*
F0R(i, n) cout << agh[i] << ' ';
cout << endl;
*/
F0R(i, q) {
cin >> qs[i].lo >> qs[i].hi >> qs[i].k;
qs[i].lo--; qs[i].hi--; qs[i].id = i;
}
sort(qs, qs + q);
int ptr = 0;
F0R(i, n) {
if (agh[i] != -1) {
//cout << "for i = " << i << " changing " << agh[i] << " to " << ns[ agh[i] ] + ns[i] << endl;
change(agh[i], ns[ agh[i] ] + ns[i]);
}
while(ptr < q && qs[ptr].hi <= i) {
ans[ qs[ptr].id ] = (get(qs[ptr].lo, qs[ptr].hi) <= qs[ptr].k);
ptr++;
}
}
#define endl '\n'
F0R(i, q) cout << ans[i] << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
360 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
360 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
456 KB |
Output is correct |
12 |
Correct |
5 ms |
588 KB |
Output is correct |
13 |
Correct |
5 ms |
576 KB |
Output is correct |
14 |
Correct |
7 ms |
720 KB |
Output is correct |
15 |
Correct |
7 ms |
708 KB |
Output is correct |
16 |
Correct |
4 ms |
588 KB |
Output is correct |
17 |
Correct |
3 ms |
592 KB |
Output is correct |
18 |
Correct |
3 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1125 ms |
42192 KB |
Output is correct |
2 |
Correct |
1073 ms |
42280 KB |
Output is correct |
3 |
Correct |
1060 ms |
38112 KB |
Output is correct |
4 |
Correct |
1042 ms |
38196 KB |
Output is correct |
5 |
Correct |
882 ms |
60556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
6184 KB |
Output is correct |
2 |
Correct |
86 ms |
6196 KB |
Output is correct |
3 |
Correct |
73 ms |
5188 KB |
Output is correct |
4 |
Correct |
96 ms |
5176 KB |
Output is correct |
5 |
Correct |
71 ms |
5184 KB |
Output is correct |
6 |
Correct |
79 ms |
5024 KB |
Output is correct |
7 |
Correct |
64 ms |
5060 KB |
Output is correct |
8 |
Correct |
99 ms |
4992 KB |
Output is correct |
9 |
Correct |
40 ms |
3828 KB |
Output is correct |
10 |
Correct |
63 ms |
5000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
360 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
456 KB |
Output is correct |
12 |
Correct |
5 ms |
588 KB |
Output is correct |
13 |
Correct |
5 ms |
576 KB |
Output is correct |
14 |
Correct |
7 ms |
720 KB |
Output is correct |
15 |
Correct |
7 ms |
708 KB |
Output is correct |
16 |
Correct |
4 ms |
588 KB |
Output is correct |
17 |
Correct |
3 ms |
592 KB |
Output is correct |
18 |
Correct |
3 ms |
588 KB |
Output is correct |
19 |
Correct |
211 ms |
14776 KB |
Output is correct |
20 |
Correct |
214 ms |
14752 KB |
Output is correct |
21 |
Correct |
213 ms |
14612 KB |
Output is correct |
22 |
Correct |
218 ms |
14680 KB |
Output is correct |
23 |
Correct |
210 ms |
14688 KB |
Output is correct |
24 |
Correct |
152 ms |
12536 KB |
Output is correct |
25 |
Correct |
151 ms |
12484 KB |
Output is correct |
26 |
Correct |
160 ms |
12744 KB |
Output is correct |
27 |
Correct |
155 ms |
12712 KB |
Output is correct |
28 |
Correct |
160 ms |
12640 KB |
Output is correct |
29 |
Correct |
156 ms |
12796 KB |
Output is correct |
30 |
Correct |
165 ms |
12808 KB |
Output is correct |
31 |
Correct |
156 ms |
12796 KB |
Output is correct |
32 |
Correct |
161 ms |
12812 KB |
Output is correct |
33 |
Correct |
155 ms |
12744 KB |
Output is correct |
34 |
Correct |
157 ms |
12612 KB |
Output is correct |
35 |
Correct |
146 ms |
12356 KB |
Output is correct |
36 |
Correct |
140 ms |
12176 KB |
Output is correct |
37 |
Correct |
141 ms |
12184 KB |
Output is correct |
38 |
Correct |
153 ms |
12380 KB |
Output is correct |
39 |
Correct |
144 ms |
12024 KB |
Output is correct |
40 |
Correct |
109 ms |
10184 KB |
Output is correct |
41 |
Correct |
136 ms |
10948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
360 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
456 KB |
Output is correct |
12 |
Correct |
5 ms |
588 KB |
Output is correct |
13 |
Correct |
5 ms |
576 KB |
Output is correct |
14 |
Correct |
7 ms |
720 KB |
Output is correct |
15 |
Correct |
7 ms |
708 KB |
Output is correct |
16 |
Correct |
4 ms |
588 KB |
Output is correct |
17 |
Correct |
3 ms |
592 KB |
Output is correct |
18 |
Correct |
3 ms |
588 KB |
Output is correct |
19 |
Correct |
1125 ms |
42192 KB |
Output is correct |
20 |
Correct |
1073 ms |
42280 KB |
Output is correct |
21 |
Correct |
1060 ms |
38112 KB |
Output is correct |
22 |
Correct |
1042 ms |
38196 KB |
Output is correct |
23 |
Correct |
882 ms |
60556 KB |
Output is correct |
24 |
Correct |
93 ms |
6184 KB |
Output is correct |
25 |
Correct |
86 ms |
6196 KB |
Output is correct |
26 |
Correct |
73 ms |
5188 KB |
Output is correct |
27 |
Correct |
96 ms |
5176 KB |
Output is correct |
28 |
Correct |
71 ms |
5184 KB |
Output is correct |
29 |
Correct |
79 ms |
5024 KB |
Output is correct |
30 |
Correct |
64 ms |
5060 KB |
Output is correct |
31 |
Correct |
99 ms |
4992 KB |
Output is correct |
32 |
Correct |
40 ms |
3828 KB |
Output is correct |
33 |
Correct |
63 ms |
5000 KB |
Output is correct |
34 |
Correct |
211 ms |
14776 KB |
Output is correct |
35 |
Correct |
214 ms |
14752 KB |
Output is correct |
36 |
Correct |
213 ms |
14612 KB |
Output is correct |
37 |
Correct |
218 ms |
14680 KB |
Output is correct |
38 |
Correct |
210 ms |
14688 KB |
Output is correct |
39 |
Correct |
152 ms |
12536 KB |
Output is correct |
40 |
Correct |
151 ms |
12484 KB |
Output is correct |
41 |
Correct |
160 ms |
12744 KB |
Output is correct |
42 |
Correct |
155 ms |
12712 KB |
Output is correct |
43 |
Correct |
160 ms |
12640 KB |
Output is correct |
44 |
Correct |
156 ms |
12796 KB |
Output is correct |
45 |
Correct |
165 ms |
12808 KB |
Output is correct |
46 |
Correct |
156 ms |
12796 KB |
Output is correct |
47 |
Correct |
161 ms |
12812 KB |
Output is correct |
48 |
Correct |
155 ms |
12744 KB |
Output is correct |
49 |
Correct |
157 ms |
12612 KB |
Output is correct |
50 |
Correct |
146 ms |
12356 KB |
Output is correct |
51 |
Correct |
140 ms |
12176 KB |
Output is correct |
52 |
Correct |
141 ms |
12184 KB |
Output is correct |
53 |
Correct |
153 ms |
12380 KB |
Output is correct |
54 |
Correct |
144 ms |
12024 KB |
Output is correct |
55 |
Correct |
109 ms |
10184 KB |
Output is correct |
56 |
Correct |
136 ms |
10948 KB |
Output is correct |
57 |
Correct |
1051 ms |
71480 KB |
Output is correct |
58 |
Correct |
1022 ms |
71508 KB |
Output is correct |
59 |
Correct |
1040 ms |
71624 KB |
Output is correct |
60 |
Correct |
997 ms |
71412 KB |
Output is correct |
61 |
Correct |
993 ms |
71428 KB |
Output is correct |
62 |
Correct |
1004 ms |
71544 KB |
Output is correct |
63 |
Correct |
806 ms |
61608 KB |
Output is correct |
64 |
Correct |
797 ms |
61328 KB |
Output is correct |
65 |
Correct |
833 ms |
63164 KB |
Output is correct |
66 |
Correct |
861 ms |
63088 KB |
Output is correct |
67 |
Correct |
851 ms |
63204 KB |
Output is correct |
68 |
Correct |
833 ms |
63132 KB |
Output is correct |
69 |
Correct |
844 ms |
63168 KB |
Output is correct |
70 |
Correct |
826 ms |
63300 KB |
Output is correct |
71 |
Correct |
828 ms |
63092 KB |
Output is correct |
72 |
Correct |
827 ms |
63068 KB |
Output is correct |
73 |
Correct |
743 ms |
59820 KB |
Output is correct |
74 |
Correct |
796 ms |
60716 KB |
Output is correct |
75 |
Correct |
736 ms |
59572 KB |
Output is correct |
76 |
Correct |
743 ms |
59648 KB |
Output is correct |
77 |
Correct |
771 ms |
59580 KB |
Output is correct |
78 |
Correct |
763 ms |
59584 KB |
Output is correct |
79 |
Correct |
563 ms |
48532 KB |
Output is correct |
80 |
Correct |
757 ms |
54208 KB |
Output is correct |