#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define lwb lower_bound
#define upb upper_bound
#define TASKNAME "NAME"
void init()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
///freopen(TASKNAME".INP","r",stdin); freopen(TASKNAME".OUT","w",stdout);
}
const int SZ = 1e6+5;
const ll INF = INT_MAX / 2, MOD = 1e9+7, INFLL = 2e18;
const double epsilon = 1e-3;
struct Query
{
int lo, hi, k, id;
Query(int _lo = 0, int _hi = 0, int _k = 0, int _id = 0) : lo(_lo), hi(_hi), k(_k), id(_id) {}
bool operator < (const Query& other) const
{
return hi < other.hi;
}
} b[SZ];
struct SegTree
{
int nodes[4*SZ], lazy[4*SZ];
void down(int id)
{
int t = lazy[id];
lazy[id] = 0;
nodes[2*id] = max(nodes[2*id],t);
lazy[2*id] = max(lazy[2*id], t);
nodes[2*id+1] = max(nodes[2*id+1],t);
lazy[2*id+1] = max(lazy[2*id+1],t);
}
void update(int id, int lo, int hi, int u, int v, int val)
{
if(lo > v || hi < u) return;
if(lo >= u && hi <= v)
{
nodes[id] = max(nodes[id], val);
lazy[id] = max(lazy[id], val);
return;
}
down(id);
int mid = (lo + hi) / 2;
update(2*id, lo, mid, u, v, val);
update(2*id+1, mid+1, hi, u, v, val);
nodes[id] = max(nodes[2*id], nodes[2*id+1]);
}
int query(int id, int lo, int hi, int u, int v)
{
if(lo > v || hi < u) return 0;
if(lo >= u && hi <= v)
{
//cout << "query " << lo << " " << hi << " " << nodes[id] << '\n';
return nodes[id];
}
down(id);
int mid = (lo + hi) / 2;
return max(query(2*id,lo, mid , u, v), query(2*id+1, mid+1, hi, u, v));
}
} seg;
int n,m, a[SZ], res[SZ];
stack<int> st;
int main()
{
init();
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
for(int i = 1; i <= m; i++)
{
cin >> b[i].lo >> b[i].hi >> b[i].k;
b[i].id = i;
}
sort(b + 1, b + m + 1);
int j = 1;
st.push(0);
for(int i = 1; i <= m; i++)
{
int lo = b[i].lo, hi = b[i].hi, k = b[i].k, id = b[i].id;
while(j <= hi)
{
while(st.size() > 1 && a[st.top()] <= a[j]) st.pop();
if(st.size() > 1)
{
int cur = st.top();
st.pop();
seg.update(1, 1, n, st.top() + 1, cur, a[j] + a[cur]);
//cout << "update " << st.top() + 1 << " " << cur << " " << a[j] + a[cur] << '\n';
st.push(cur);
}
st.push(j);
j++;
}
ll trol = seg.query(1, 1, n, lo, hi);
//cout << lo << " " << hi << " " << k << " " << trol << '\n';
res[id] = (trol <= k ? 1 : 0);
}
for(int i = 1; i <= m; i++)
{
cout << res[i] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
22364 KB |
Output is correct |
2 |
Correct |
4 ms |
22244 KB |
Output is correct |
3 |
Correct |
5 ms |
22108 KB |
Output is correct |
4 |
Correct |
7 ms |
22260 KB |
Output is correct |
5 |
Correct |
5 ms |
22104 KB |
Output is correct |
6 |
Correct |
5 ms |
22108 KB |
Output is correct |
7 |
Correct |
6 ms |
22108 KB |
Output is correct |
8 |
Correct |
5 ms |
22108 KB |
Output is correct |
9 |
Correct |
5 ms |
22108 KB |
Output is correct |
10 |
Correct |
6 ms |
22108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
22364 KB |
Output is correct |
2 |
Correct |
4 ms |
22244 KB |
Output is correct |
3 |
Correct |
5 ms |
22108 KB |
Output is correct |
4 |
Correct |
7 ms |
22260 KB |
Output is correct |
5 |
Correct |
5 ms |
22104 KB |
Output is correct |
6 |
Correct |
5 ms |
22108 KB |
Output is correct |
7 |
Correct |
6 ms |
22108 KB |
Output is correct |
8 |
Correct |
5 ms |
22108 KB |
Output is correct |
9 |
Correct |
5 ms |
22108 KB |
Output is correct |
10 |
Correct |
6 ms |
22108 KB |
Output is correct |
11 |
Correct |
7 ms |
22364 KB |
Output is correct |
12 |
Correct |
7 ms |
22364 KB |
Output is correct |
13 |
Correct |
8 ms |
22364 KB |
Output is correct |
14 |
Correct |
9 ms |
22360 KB |
Output is correct |
15 |
Correct |
8 ms |
22364 KB |
Output is correct |
16 |
Correct |
8 ms |
22364 KB |
Output is correct |
17 |
Correct |
7 ms |
22220 KB |
Output is correct |
18 |
Correct |
8 ms |
22364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1090 ms |
74744 KB |
Output is correct |
2 |
Correct |
1109 ms |
77376 KB |
Output is correct |
3 |
Correct |
1097 ms |
77204 KB |
Output is correct |
4 |
Correct |
1104 ms |
77128 KB |
Output is correct |
5 |
Correct |
835 ms |
77268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
30036 KB |
Output is correct |
2 |
Correct |
82 ms |
30148 KB |
Output is correct |
3 |
Correct |
69 ms |
30364 KB |
Output is correct |
4 |
Correct |
65 ms |
30036 KB |
Output is correct |
5 |
Correct |
64 ms |
30136 KB |
Output is correct |
6 |
Correct |
55 ms |
28500 KB |
Output is correct |
7 |
Correct |
56 ms |
28500 KB |
Output is correct |
8 |
Correct |
72 ms |
29844 KB |
Output is correct |
9 |
Correct |
34 ms |
25808 KB |
Output is correct |
10 |
Correct |
63 ms |
29776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
22364 KB |
Output is correct |
2 |
Correct |
4 ms |
22244 KB |
Output is correct |
3 |
Correct |
5 ms |
22108 KB |
Output is correct |
4 |
Correct |
7 ms |
22260 KB |
Output is correct |
5 |
Correct |
5 ms |
22104 KB |
Output is correct |
6 |
Correct |
5 ms |
22108 KB |
Output is correct |
7 |
Correct |
6 ms |
22108 KB |
Output is correct |
8 |
Correct |
5 ms |
22108 KB |
Output is correct |
9 |
Correct |
5 ms |
22108 KB |
Output is correct |
10 |
Correct |
6 ms |
22108 KB |
Output is correct |
11 |
Correct |
7 ms |
22364 KB |
Output is correct |
12 |
Correct |
7 ms |
22364 KB |
Output is correct |
13 |
Correct |
8 ms |
22364 KB |
Output is correct |
14 |
Correct |
9 ms |
22360 KB |
Output is correct |
15 |
Correct |
8 ms |
22364 KB |
Output is correct |
16 |
Correct |
8 ms |
22364 KB |
Output is correct |
17 |
Correct |
7 ms |
22220 KB |
Output is correct |
18 |
Correct |
8 ms |
22364 KB |
Output is correct |
19 |
Correct |
186 ms |
37036 KB |
Output is correct |
20 |
Correct |
188 ms |
37152 KB |
Output is correct |
21 |
Correct |
174 ms |
36708 KB |
Output is correct |
22 |
Correct |
179 ms |
36684 KB |
Output is correct |
23 |
Correct |
179 ms |
36680 KB |
Output is correct |
24 |
Correct |
125 ms |
33604 KB |
Output is correct |
25 |
Correct |
128 ms |
33364 KB |
Output is correct |
26 |
Correct |
137 ms |
35924 KB |
Output is correct |
27 |
Correct |
138 ms |
35928 KB |
Output is correct |
28 |
Correct |
139 ms |
36960 KB |
Output is correct |
29 |
Correct |
145 ms |
36820 KB |
Output is correct |
30 |
Correct |
143 ms |
36944 KB |
Output is correct |
31 |
Correct |
147 ms |
36948 KB |
Output is correct |
32 |
Correct |
148 ms |
36928 KB |
Output is correct |
33 |
Correct |
143 ms |
37016 KB |
Output is correct |
34 |
Correct |
122 ms |
32988 KB |
Output is correct |
35 |
Correct |
123 ms |
33052 KB |
Output is correct |
36 |
Correct |
121 ms |
32852 KB |
Output is correct |
37 |
Correct |
124 ms |
32848 KB |
Output is correct |
38 |
Correct |
120 ms |
33096 KB |
Output is correct |
39 |
Correct |
141 ms |
35672 KB |
Output is correct |
40 |
Correct |
93 ms |
32848 KB |
Output is correct |
41 |
Correct |
135 ms |
35156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
22364 KB |
Output is correct |
2 |
Correct |
4 ms |
22244 KB |
Output is correct |
3 |
Correct |
5 ms |
22108 KB |
Output is correct |
4 |
Correct |
7 ms |
22260 KB |
Output is correct |
5 |
Correct |
5 ms |
22104 KB |
Output is correct |
6 |
Correct |
5 ms |
22108 KB |
Output is correct |
7 |
Correct |
6 ms |
22108 KB |
Output is correct |
8 |
Correct |
5 ms |
22108 KB |
Output is correct |
9 |
Correct |
5 ms |
22108 KB |
Output is correct |
10 |
Correct |
6 ms |
22108 KB |
Output is correct |
11 |
Correct |
7 ms |
22364 KB |
Output is correct |
12 |
Correct |
7 ms |
22364 KB |
Output is correct |
13 |
Correct |
8 ms |
22364 KB |
Output is correct |
14 |
Correct |
9 ms |
22360 KB |
Output is correct |
15 |
Correct |
8 ms |
22364 KB |
Output is correct |
16 |
Correct |
8 ms |
22364 KB |
Output is correct |
17 |
Correct |
7 ms |
22220 KB |
Output is correct |
18 |
Correct |
8 ms |
22364 KB |
Output is correct |
19 |
Correct |
1090 ms |
74744 KB |
Output is correct |
20 |
Correct |
1109 ms |
77376 KB |
Output is correct |
21 |
Correct |
1097 ms |
77204 KB |
Output is correct |
22 |
Correct |
1104 ms |
77128 KB |
Output is correct |
23 |
Correct |
835 ms |
77268 KB |
Output is correct |
24 |
Correct |
98 ms |
30036 KB |
Output is correct |
25 |
Correct |
82 ms |
30148 KB |
Output is correct |
26 |
Correct |
69 ms |
30364 KB |
Output is correct |
27 |
Correct |
65 ms |
30036 KB |
Output is correct |
28 |
Correct |
64 ms |
30136 KB |
Output is correct |
29 |
Correct |
55 ms |
28500 KB |
Output is correct |
30 |
Correct |
56 ms |
28500 KB |
Output is correct |
31 |
Correct |
72 ms |
29844 KB |
Output is correct |
32 |
Correct |
34 ms |
25808 KB |
Output is correct |
33 |
Correct |
63 ms |
29776 KB |
Output is correct |
34 |
Correct |
186 ms |
37036 KB |
Output is correct |
35 |
Correct |
188 ms |
37152 KB |
Output is correct |
36 |
Correct |
174 ms |
36708 KB |
Output is correct |
37 |
Correct |
179 ms |
36684 KB |
Output is correct |
38 |
Correct |
179 ms |
36680 KB |
Output is correct |
39 |
Correct |
125 ms |
33604 KB |
Output is correct |
40 |
Correct |
128 ms |
33364 KB |
Output is correct |
41 |
Correct |
137 ms |
35924 KB |
Output is correct |
42 |
Correct |
138 ms |
35928 KB |
Output is correct |
43 |
Correct |
139 ms |
36960 KB |
Output is correct |
44 |
Correct |
145 ms |
36820 KB |
Output is correct |
45 |
Correct |
143 ms |
36944 KB |
Output is correct |
46 |
Correct |
147 ms |
36948 KB |
Output is correct |
47 |
Correct |
148 ms |
36928 KB |
Output is correct |
48 |
Correct |
143 ms |
37016 KB |
Output is correct |
49 |
Correct |
122 ms |
32988 KB |
Output is correct |
50 |
Correct |
123 ms |
33052 KB |
Output is correct |
51 |
Correct |
121 ms |
32852 KB |
Output is correct |
52 |
Correct |
124 ms |
32848 KB |
Output is correct |
53 |
Correct |
120 ms |
33096 KB |
Output is correct |
54 |
Correct |
141 ms |
35672 KB |
Output is correct |
55 |
Correct |
93 ms |
32848 KB |
Output is correct |
56 |
Correct |
135 ms |
35156 KB |
Output is correct |
57 |
Correct |
1063 ms |
77760 KB |
Output is correct |
58 |
Correct |
1033 ms |
77904 KB |
Output is correct |
59 |
Correct |
1002 ms |
78168 KB |
Output is correct |
60 |
Correct |
994 ms |
77904 KB |
Output is correct |
61 |
Correct |
1000 ms |
77768 KB |
Output is correct |
62 |
Correct |
1044 ms |
77832 KB |
Output is correct |
63 |
Correct |
651 ms |
60276 KB |
Output is correct |
64 |
Correct |
659 ms |
60708 KB |
Output is correct |
65 |
Correct |
759 ms |
76796 KB |
Output is correct |
66 |
Correct |
803 ms |
76888 KB |
Output is correct |
67 |
Correct |
767 ms |
77840 KB |
Output is correct |
68 |
Correct |
822 ms |
77796 KB |
Output is correct |
69 |
Correct |
804 ms |
78164 KB |
Output is correct |
70 |
Correct |
812 ms |
77768 KB |
Output is correct |
71 |
Correct |
808 ms |
77892 KB |
Output is correct |
72 |
Correct |
829 ms |
77904 KB |
Output is correct |
73 |
Correct |
609 ms |
58452 KB |
Output is correct |
74 |
Correct |
615 ms |
59452 KB |
Output is correct |
75 |
Correct |
613 ms |
58704 KB |
Output is correct |
76 |
Correct |
608 ms |
58564 KB |
Output is correct |
77 |
Correct |
613 ms |
58696 KB |
Output is correct |
78 |
Correct |
719 ms |
71876 KB |
Output is correct |
79 |
Correct |
479 ms |
58836 KB |
Output is correct |
80 |
Correct |
822 ms |
68752 KB |
Output is correct |