#include<bits/stdc++.h>
#define INF 1e18
#define fi first
#define se second
#define FOR(i, k, n) for(int i = k; i <= n; i++)
#define FOR1(i, k, n) for(int i = k; i >= n; i--)
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define ll long long
#define vll vector<ll>
#define pll pair<ll, ll>
#define re return 0
#define mii map<int, int>
#define input "DANCE.inp"
#define output "DANCE.out"
#define rf freopen(input, "r", stdin); freopen(output, "w", stdout)
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
struct shape{
int pos, id, k;
};
vector<shape> event[maxn];
ll T[maxn * 4];
int a[maxn], kq[maxn];
void update(int id, int l, int r, int pos, ll val)
{
if(l == r)
{
T[id] = max(T[id], val);
return;
}
int mid = (l + r) >> 1;
if(pos <= mid)
update(id * 2, l, mid, pos, val);
else
update(id * 2 + 1, mid + 1, r, pos, val);
T[id] = max(T[id * 2], T[id * 2 + 1]);
}
ll get(int id, int l, int r, int u, int v)
{
if(l > v || r < u)
return 0;
if(l >= u && r <= v)
return T[id];
int mid = (l + r) >> 1;
return max(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
}
int main()
{
fastio;
int n, q;
cin >> n >> q;
FOR(i, 1, n)
cin >> a[i];
FOR(i, 1, q)
{
int l, r, k;
cin >> l >> r >> k;
event[r].pb({l, i, k});
}
vi v;
v.pb(0);
a[0] = 1e9 + 7;
FOR(i, 1, n)
{
while(a[v.back()] <= a[i])
v.pop_back();
if(v.back() != 0)
{
update(1, 1, n, v.back(), a[i] + a[v.back()]);
}
for(auto x : event[i])
{
int id = x.id;
int l = x.pos;
int k = x.k;
ll res = get(1, 1, n, l, i);
if(res <= k)
kq[id] = 1;
else
kq[id] = 0;
}
v.pb(i);
}
FOR(i, 1, q)
cout << kq[i] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
27992 KB |
Output is correct |
2 |
Correct |
3 ms |
27996 KB |
Output is correct |
3 |
Correct |
4 ms |
28036 KB |
Output is correct |
4 |
Correct |
4 ms |
27992 KB |
Output is correct |
5 |
Correct |
4 ms |
27996 KB |
Output is correct |
6 |
Correct |
4 ms |
27992 KB |
Output is correct |
7 |
Correct |
4 ms |
27996 KB |
Output is correct |
8 |
Correct |
4 ms |
27996 KB |
Output is correct |
9 |
Correct |
4 ms |
27996 KB |
Output is correct |
10 |
Correct |
3 ms |
27996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
27992 KB |
Output is correct |
2 |
Correct |
3 ms |
27996 KB |
Output is correct |
3 |
Correct |
4 ms |
28036 KB |
Output is correct |
4 |
Correct |
4 ms |
27992 KB |
Output is correct |
5 |
Correct |
4 ms |
27996 KB |
Output is correct |
6 |
Correct |
4 ms |
27992 KB |
Output is correct |
7 |
Correct |
4 ms |
27996 KB |
Output is correct |
8 |
Correct |
4 ms |
27996 KB |
Output is correct |
9 |
Correct |
4 ms |
27996 KB |
Output is correct |
10 |
Correct |
3 ms |
27996 KB |
Output is correct |
11 |
Correct |
5 ms |
27996 KB |
Output is correct |
12 |
Correct |
5 ms |
28184 KB |
Output is correct |
13 |
Correct |
5 ms |
28252 KB |
Output is correct |
14 |
Correct |
6 ms |
28252 KB |
Output is correct |
15 |
Correct |
6 ms |
28252 KB |
Output is correct |
16 |
Correct |
6 ms |
28100 KB |
Output is correct |
17 |
Correct |
5 ms |
27996 KB |
Output is correct |
18 |
Correct |
5 ms |
27996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
754 ms |
73812 KB |
Output is correct |
2 |
Correct |
737 ms |
73856 KB |
Output is correct |
3 |
Correct |
774 ms |
73840 KB |
Output is correct |
4 |
Correct |
740 ms |
73812 KB |
Output is correct |
5 |
Correct |
614 ms |
57936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
37972 KB |
Output is correct |
2 |
Correct |
49 ms |
37676 KB |
Output is correct |
3 |
Correct |
48 ms |
34388 KB |
Output is correct |
4 |
Correct |
48 ms |
34384 KB |
Output is correct |
5 |
Correct |
53 ms |
34420 KB |
Output is correct |
6 |
Correct |
40 ms |
36176 KB |
Output is correct |
7 |
Correct |
38 ms |
36188 KB |
Output is correct |
8 |
Correct |
43 ms |
34316 KB |
Output is correct |
9 |
Correct |
24 ms |
31752 KB |
Output is correct |
10 |
Correct |
41 ms |
34316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
27992 KB |
Output is correct |
2 |
Correct |
3 ms |
27996 KB |
Output is correct |
3 |
Correct |
4 ms |
28036 KB |
Output is correct |
4 |
Correct |
4 ms |
27992 KB |
Output is correct |
5 |
Correct |
4 ms |
27996 KB |
Output is correct |
6 |
Correct |
4 ms |
27992 KB |
Output is correct |
7 |
Correct |
4 ms |
27996 KB |
Output is correct |
8 |
Correct |
4 ms |
27996 KB |
Output is correct |
9 |
Correct |
4 ms |
27996 KB |
Output is correct |
10 |
Correct |
3 ms |
27996 KB |
Output is correct |
11 |
Correct |
5 ms |
27996 KB |
Output is correct |
12 |
Correct |
5 ms |
28184 KB |
Output is correct |
13 |
Correct |
5 ms |
28252 KB |
Output is correct |
14 |
Correct |
6 ms |
28252 KB |
Output is correct |
15 |
Correct |
6 ms |
28252 KB |
Output is correct |
16 |
Correct |
6 ms |
28100 KB |
Output is correct |
17 |
Correct |
5 ms |
27996 KB |
Output is correct |
18 |
Correct |
5 ms |
27996 KB |
Output is correct |
19 |
Correct |
122 ms |
42456 KB |
Output is correct |
20 |
Correct |
118 ms |
42324 KB |
Output is correct |
21 |
Correct |
103 ms |
41812 KB |
Output is correct |
22 |
Correct |
109 ms |
42148 KB |
Output is correct |
23 |
Correct |
104 ms |
41812 KB |
Output is correct |
24 |
Correct |
87 ms |
36228 KB |
Output is correct |
25 |
Correct |
85 ms |
36180 KB |
Output is correct |
26 |
Correct |
95 ms |
36436 KB |
Output is correct |
27 |
Correct |
104 ms |
36432 KB |
Output is correct |
28 |
Correct |
99 ms |
36624 KB |
Output is correct |
29 |
Correct |
110 ms |
36688 KB |
Output is correct |
30 |
Correct |
105 ms |
36692 KB |
Output is correct |
31 |
Correct |
111 ms |
36860 KB |
Output is correct |
32 |
Correct |
103 ms |
36692 KB |
Output is correct |
33 |
Correct |
101 ms |
36692 KB |
Output is correct |
34 |
Correct |
80 ms |
37968 KB |
Output is correct |
35 |
Correct |
81 ms |
38076 KB |
Output is correct |
36 |
Correct |
81 ms |
38068 KB |
Output is correct |
37 |
Correct |
80 ms |
37992 KB |
Output is correct |
38 |
Correct |
82 ms |
37964 KB |
Output is correct |
39 |
Correct |
94 ms |
37892 KB |
Output is correct |
40 |
Correct |
83 ms |
36100 KB |
Output is correct |
41 |
Correct |
97 ms |
36612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
27992 KB |
Output is correct |
2 |
Correct |
3 ms |
27996 KB |
Output is correct |
3 |
Correct |
4 ms |
28036 KB |
Output is correct |
4 |
Correct |
4 ms |
27992 KB |
Output is correct |
5 |
Correct |
4 ms |
27996 KB |
Output is correct |
6 |
Correct |
4 ms |
27992 KB |
Output is correct |
7 |
Correct |
4 ms |
27996 KB |
Output is correct |
8 |
Correct |
4 ms |
27996 KB |
Output is correct |
9 |
Correct |
4 ms |
27996 KB |
Output is correct |
10 |
Correct |
3 ms |
27996 KB |
Output is correct |
11 |
Correct |
5 ms |
27996 KB |
Output is correct |
12 |
Correct |
5 ms |
28184 KB |
Output is correct |
13 |
Correct |
5 ms |
28252 KB |
Output is correct |
14 |
Correct |
6 ms |
28252 KB |
Output is correct |
15 |
Correct |
6 ms |
28252 KB |
Output is correct |
16 |
Correct |
6 ms |
28100 KB |
Output is correct |
17 |
Correct |
5 ms |
27996 KB |
Output is correct |
18 |
Correct |
5 ms |
27996 KB |
Output is correct |
19 |
Correct |
754 ms |
73812 KB |
Output is correct |
20 |
Correct |
737 ms |
73856 KB |
Output is correct |
21 |
Correct |
774 ms |
73840 KB |
Output is correct |
22 |
Correct |
740 ms |
73812 KB |
Output is correct |
23 |
Correct |
614 ms |
57936 KB |
Output is correct |
24 |
Correct |
54 ms |
37972 KB |
Output is correct |
25 |
Correct |
49 ms |
37676 KB |
Output is correct |
26 |
Correct |
48 ms |
34388 KB |
Output is correct |
27 |
Correct |
48 ms |
34384 KB |
Output is correct |
28 |
Correct |
53 ms |
34420 KB |
Output is correct |
29 |
Correct |
40 ms |
36176 KB |
Output is correct |
30 |
Correct |
38 ms |
36188 KB |
Output is correct |
31 |
Correct |
43 ms |
34316 KB |
Output is correct |
32 |
Correct |
24 ms |
31752 KB |
Output is correct |
33 |
Correct |
41 ms |
34316 KB |
Output is correct |
34 |
Correct |
122 ms |
42456 KB |
Output is correct |
35 |
Correct |
118 ms |
42324 KB |
Output is correct |
36 |
Correct |
103 ms |
41812 KB |
Output is correct |
37 |
Correct |
109 ms |
42148 KB |
Output is correct |
38 |
Correct |
104 ms |
41812 KB |
Output is correct |
39 |
Correct |
87 ms |
36228 KB |
Output is correct |
40 |
Correct |
85 ms |
36180 KB |
Output is correct |
41 |
Correct |
95 ms |
36436 KB |
Output is correct |
42 |
Correct |
104 ms |
36432 KB |
Output is correct |
43 |
Correct |
99 ms |
36624 KB |
Output is correct |
44 |
Correct |
110 ms |
36688 KB |
Output is correct |
45 |
Correct |
105 ms |
36692 KB |
Output is correct |
46 |
Correct |
111 ms |
36860 KB |
Output is correct |
47 |
Correct |
103 ms |
36692 KB |
Output is correct |
48 |
Correct |
101 ms |
36692 KB |
Output is correct |
49 |
Correct |
80 ms |
37968 KB |
Output is correct |
50 |
Correct |
81 ms |
38076 KB |
Output is correct |
51 |
Correct |
81 ms |
38068 KB |
Output is correct |
52 |
Correct |
80 ms |
37992 KB |
Output is correct |
53 |
Correct |
82 ms |
37964 KB |
Output is correct |
54 |
Correct |
94 ms |
37892 KB |
Output is correct |
55 |
Correct |
83 ms |
36100 KB |
Output is correct |
56 |
Correct |
97 ms |
36612 KB |
Output is correct |
57 |
Correct |
735 ms |
73312 KB |
Output is correct |
58 |
Correct |
736 ms |
73296 KB |
Output is correct |
59 |
Correct |
654 ms |
71760 KB |
Output is correct |
60 |
Correct |
631 ms |
71760 KB |
Output is correct |
61 |
Correct |
636 ms |
71760 KB |
Output is correct |
62 |
Correct |
645 ms |
71912 KB |
Output is correct |
63 |
Correct |
432 ms |
54608 KB |
Output is correct |
64 |
Correct |
452 ms |
54656 KB |
Output is correct |
65 |
Correct |
574 ms |
55916 KB |
Output is correct |
66 |
Correct |
549 ms |
55760 KB |
Output is correct |
67 |
Correct |
548 ms |
55904 KB |
Output is correct |
68 |
Correct |
622 ms |
57424 KB |
Output is correct |
69 |
Correct |
632 ms |
57428 KB |
Output is correct |
70 |
Correct |
587 ms |
57192 KB |
Output is correct |
71 |
Correct |
581 ms |
57168 KB |
Output is correct |
72 |
Correct |
582 ms |
57168 KB |
Output is correct |
73 |
Correct |
409 ms |
56144 KB |
Output is correct |
74 |
Correct |
404 ms |
56148 KB |
Output is correct |
75 |
Correct |
394 ms |
56144 KB |
Output is correct |
76 |
Correct |
407 ms |
56404 KB |
Output is correct |
77 |
Correct |
410 ms |
56148 KB |
Output is correct |
78 |
Correct |
540 ms |
61184 KB |
Output is correct |
79 |
Correct |
378 ms |
51440 KB |
Output is correct |
80 |
Correct |
492 ms |
56456 KB |
Output is correct |