#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
using namespace std;
#define ll long long
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 1000000;
int v[1 + nmax];
vector<pair<int,int>> querys[1 + nmax];
vector<pair<int,int>> interval[1 + nmax];
int sol[1 + nmax];
int key[1 + nmax];
int aint[1 + nmax * 4];
void update(int node, int from, int to, int x, int val){
if(from < to){
int mid = (from + to) / 2;
if(x <= mid)
update(node * 2 , from, mid, x, val);
else
update(node * 2 + 1, mid + 1 , to, x, val);
aint[node] = MAX(aint[node * 2], aint[node * 2 + 1]);
} else
aint[node] = MAX(aint[node], val);
}
int query(int node,int from, int to, int x, int y){
if(from == x && to == y)
return aint[node];
else{
int mid = (from + to) / 2;
int result1 = 0, result2 = 0;
if(x <= mid)
result1 = query(node * 2, from, mid, x, MIN(y, mid));
if(mid + 1 <= y)
result2 = query(node * 2 + 1, mid + 1, to, MAX(mid + 1, x), y);
return MAX(result1, result2);
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
stack<int> st;
for(int i = 1; i <= n; i++) {
cin >> v[i];
while(0 < st.size() && v[st.top()] <= v[i])
st.pop();
if(0 < st.size())
interval[i].push_back({st.top(), v[st.top()] + v[i]});
st.push(i);
}
for(int i = 1;i <= m; i++){
int x, y;
cin >> x >> y >> key[i];
querys[y].push_back({x, i});
}
for(int i = 1;i <= n; i++){
for(int h = 0; h < interval[i].size(); h++)
update(1, 1, n, interval[i][h].first, interval[i][h].second);
for(int h = 0; h < querys[i].size(); h++)
sol[querys[i][h].second] = query(1, 1, n, querys[i][h].first , i);
}
for(int i = 1;i <= m; i++)
cout << (sol[i] <= key[i]) << '\n';
return 0;
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:73:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int h = 0; h < interval[i].size(); h++)
~~^~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:75:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int h = 0; h < querys[i].size(); h++)
~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
47352 KB |
Output is correct |
2 |
Correct |
54 ms |
47352 KB |
Output is correct |
3 |
Correct |
47 ms |
47396 KB |
Output is correct |
4 |
Correct |
55 ms |
47352 KB |
Output is correct |
5 |
Correct |
53 ms |
47324 KB |
Output is correct |
6 |
Correct |
55 ms |
47500 KB |
Output is correct |
7 |
Correct |
54 ms |
47352 KB |
Output is correct |
8 |
Correct |
46 ms |
47344 KB |
Output is correct |
9 |
Correct |
45 ms |
47224 KB |
Output is correct |
10 |
Correct |
46 ms |
47352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
47352 KB |
Output is correct |
2 |
Correct |
54 ms |
47352 KB |
Output is correct |
3 |
Correct |
47 ms |
47396 KB |
Output is correct |
4 |
Correct |
55 ms |
47352 KB |
Output is correct |
5 |
Correct |
53 ms |
47324 KB |
Output is correct |
6 |
Correct |
55 ms |
47500 KB |
Output is correct |
7 |
Correct |
54 ms |
47352 KB |
Output is correct |
8 |
Correct |
46 ms |
47344 KB |
Output is correct |
9 |
Correct |
45 ms |
47224 KB |
Output is correct |
10 |
Correct |
46 ms |
47352 KB |
Output is correct |
11 |
Correct |
48 ms |
47492 KB |
Output is correct |
12 |
Correct |
50 ms |
47740 KB |
Output is correct |
13 |
Correct |
50 ms |
47864 KB |
Output is correct |
14 |
Correct |
52 ms |
47992 KB |
Output is correct |
15 |
Correct |
50 ms |
47864 KB |
Output is correct |
16 |
Correct |
50 ms |
47608 KB |
Output is correct |
17 |
Correct |
150 ms |
47708 KB |
Output is correct |
18 |
Correct |
51 ms |
47668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1916 ms |
120716 KB |
Output is correct |
2 |
Correct |
1967 ms |
124960 KB |
Output is correct |
3 |
Correct |
1986 ms |
124956 KB |
Output is correct |
4 |
Correct |
2050 ms |
124856 KB |
Output is correct |
5 |
Correct |
1604 ms |
113772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
177 ms |
55092 KB |
Output is correct |
2 |
Correct |
164 ms |
54436 KB |
Output is correct |
3 |
Correct |
147 ms |
50552 KB |
Output is correct |
4 |
Correct |
154 ms |
50668 KB |
Output is correct |
5 |
Correct |
156 ms |
50756 KB |
Output is correct |
6 |
Correct |
129 ms |
50260 KB |
Output is correct |
7 |
Correct |
135 ms |
50272 KB |
Output is correct |
8 |
Correct |
166 ms |
52852 KB |
Output is correct |
9 |
Correct |
93 ms |
49520 KB |
Output is correct |
10 |
Correct |
144 ms |
52460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
47352 KB |
Output is correct |
2 |
Correct |
54 ms |
47352 KB |
Output is correct |
3 |
Correct |
47 ms |
47396 KB |
Output is correct |
4 |
Correct |
55 ms |
47352 KB |
Output is correct |
5 |
Correct |
53 ms |
47324 KB |
Output is correct |
6 |
Correct |
55 ms |
47500 KB |
Output is correct |
7 |
Correct |
54 ms |
47352 KB |
Output is correct |
8 |
Correct |
46 ms |
47344 KB |
Output is correct |
9 |
Correct |
45 ms |
47224 KB |
Output is correct |
10 |
Correct |
46 ms |
47352 KB |
Output is correct |
11 |
Correct |
48 ms |
47492 KB |
Output is correct |
12 |
Correct |
50 ms |
47740 KB |
Output is correct |
13 |
Correct |
50 ms |
47864 KB |
Output is correct |
14 |
Correct |
52 ms |
47992 KB |
Output is correct |
15 |
Correct |
50 ms |
47864 KB |
Output is correct |
16 |
Correct |
50 ms |
47608 KB |
Output is correct |
17 |
Correct |
150 ms |
47708 KB |
Output is correct |
18 |
Correct |
51 ms |
47668 KB |
Output is correct |
19 |
Correct |
366 ms |
62220 KB |
Output is correct |
20 |
Correct |
393 ms |
62404 KB |
Output is correct |
21 |
Correct |
347 ms |
61340 KB |
Output is correct |
22 |
Correct |
325 ms |
61216 KB |
Output is correct |
23 |
Correct |
369 ms |
61176 KB |
Output is correct |
24 |
Correct |
289 ms |
52692 KB |
Output is correct |
25 |
Correct |
288 ms |
52856 KB |
Output is correct |
26 |
Correct |
283 ms |
53240 KB |
Output is correct |
27 |
Correct |
319 ms |
53212 KB |
Output is correct |
28 |
Correct |
292 ms |
53536 KB |
Output is correct |
29 |
Correct |
312 ms |
54008 KB |
Output is correct |
30 |
Correct |
299 ms |
54136 KB |
Output is correct |
31 |
Correct |
298 ms |
54080 KB |
Output is correct |
32 |
Correct |
301 ms |
54008 KB |
Output is correct |
33 |
Correct |
339 ms |
54136 KB |
Output is correct |
34 |
Correct |
271 ms |
52600 KB |
Output is correct |
35 |
Correct |
253 ms |
52728 KB |
Output is correct |
36 |
Correct |
259 ms |
52752 KB |
Output is correct |
37 |
Correct |
250 ms |
52600 KB |
Output is correct |
38 |
Correct |
263 ms |
52472 KB |
Output is correct |
39 |
Correct |
307 ms |
56560 KB |
Output is correct |
40 |
Correct |
228 ms |
54332 KB |
Output is correct |
41 |
Correct |
271 ms |
57412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
47352 KB |
Output is correct |
2 |
Correct |
54 ms |
47352 KB |
Output is correct |
3 |
Correct |
47 ms |
47396 KB |
Output is correct |
4 |
Correct |
55 ms |
47352 KB |
Output is correct |
5 |
Correct |
53 ms |
47324 KB |
Output is correct |
6 |
Correct |
55 ms |
47500 KB |
Output is correct |
7 |
Correct |
54 ms |
47352 KB |
Output is correct |
8 |
Correct |
46 ms |
47344 KB |
Output is correct |
9 |
Correct |
45 ms |
47224 KB |
Output is correct |
10 |
Correct |
46 ms |
47352 KB |
Output is correct |
11 |
Correct |
48 ms |
47492 KB |
Output is correct |
12 |
Correct |
50 ms |
47740 KB |
Output is correct |
13 |
Correct |
50 ms |
47864 KB |
Output is correct |
14 |
Correct |
52 ms |
47992 KB |
Output is correct |
15 |
Correct |
50 ms |
47864 KB |
Output is correct |
16 |
Correct |
50 ms |
47608 KB |
Output is correct |
17 |
Correct |
150 ms |
47708 KB |
Output is correct |
18 |
Correct |
51 ms |
47668 KB |
Output is correct |
19 |
Correct |
1916 ms |
120716 KB |
Output is correct |
20 |
Correct |
1967 ms |
124960 KB |
Output is correct |
21 |
Correct |
1986 ms |
124956 KB |
Output is correct |
22 |
Correct |
2050 ms |
124856 KB |
Output is correct |
23 |
Correct |
1604 ms |
113772 KB |
Output is correct |
24 |
Correct |
177 ms |
55092 KB |
Output is correct |
25 |
Correct |
164 ms |
54436 KB |
Output is correct |
26 |
Correct |
147 ms |
50552 KB |
Output is correct |
27 |
Correct |
154 ms |
50668 KB |
Output is correct |
28 |
Correct |
156 ms |
50756 KB |
Output is correct |
29 |
Correct |
129 ms |
50260 KB |
Output is correct |
30 |
Correct |
135 ms |
50272 KB |
Output is correct |
31 |
Correct |
166 ms |
52852 KB |
Output is correct |
32 |
Correct |
93 ms |
49520 KB |
Output is correct |
33 |
Correct |
144 ms |
52460 KB |
Output is correct |
34 |
Correct |
366 ms |
62220 KB |
Output is correct |
35 |
Correct |
393 ms |
62404 KB |
Output is correct |
36 |
Correct |
347 ms |
61340 KB |
Output is correct |
37 |
Correct |
325 ms |
61216 KB |
Output is correct |
38 |
Correct |
369 ms |
61176 KB |
Output is correct |
39 |
Correct |
289 ms |
52692 KB |
Output is correct |
40 |
Correct |
288 ms |
52856 KB |
Output is correct |
41 |
Correct |
283 ms |
53240 KB |
Output is correct |
42 |
Correct |
319 ms |
53212 KB |
Output is correct |
43 |
Correct |
292 ms |
53536 KB |
Output is correct |
44 |
Correct |
312 ms |
54008 KB |
Output is correct |
45 |
Correct |
299 ms |
54136 KB |
Output is correct |
46 |
Correct |
298 ms |
54080 KB |
Output is correct |
47 |
Correct |
301 ms |
54008 KB |
Output is correct |
48 |
Correct |
339 ms |
54136 KB |
Output is correct |
49 |
Correct |
271 ms |
52600 KB |
Output is correct |
50 |
Correct |
253 ms |
52728 KB |
Output is correct |
51 |
Correct |
259 ms |
52752 KB |
Output is correct |
52 |
Correct |
250 ms |
52600 KB |
Output is correct |
53 |
Correct |
263 ms |
52472 KB |
Output is correct |
54 |
Correct |
307 ms |
56560 KB |
Output is correct |
55 |
Correct |
228 ms |
54332 KB |
Output is correct |
56 |
Correct |
271 ms |
57412 KB |
Output is correct |
57 |
Correct |
1916 ms |
124064 KB |
Output is correct |
58 |
Correct |
1888 ms |
124000 KB |
Output is correct |
59 |
Correct |
1886 ms |
121316 KB |
Output is correct |
60 |
Correct |
1904 ms |
121284 KB |
Output is correct |
61 |
Correct |
1896 ms |
121372 KB |
Output is correct |
62 |
Correct |
1854 ms |
121248 KB |
Output is correct |
63 |
Correct |
1278 ms |
104708 KB |
Output is correct |
64 |
Correct |
1252 ms |
104816 KB |
Output is correct |
65 |
Correct |
1571 ms |
110336 KB |
Output is correct |
66 |
Correct |
1481 ms |
110256 KB |
Output is correct |
67 |
Correct |
1494 ms |
110376 KB |
Output is correct |
68 |
Correct |
1506 ms |
113268 KB |
Output is correct |
69 |
Correct |
1607 ms |
113376 KB |
Output is correct |
70 |
Correct |
1521 ms |
112844 KB |
Output is correct |
71 |
Correct |
1514 ms |
112884 KB |
Output is correct |
72 |
Correct |
1549 ms |
112872 KB |
Output is correct |
73 |
Correct |
1154 ms |
101816 KB |
Output is correct |
74 |
Correct |
1162 ms |
102772 KB |
Output is correct |
75 |
Correct |
1166 ms |
101940 KB |
Output is correct |
76 |
Correct |
1163 ms |
101788 KB |
Output is correct |
77 |
Correct |
1172 ms |
101776 KB |
Output is correct |
78 |
Correct |
1377 ms |
104496 KB |
Output is correct |
79 |
Correct |
1032 ms |
81096 KB |
Output is correct |
80 |
Correct |
1366 ms |
110500 KB |
Output is correct |