#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = 1e9 + 177013;
const int MAXN = 1e6 + 123;
int w[MAXN];
int pv[MAXN];
int get_max(int l, int r) {
int mx = -INF;
int ans = 0;
for (int i = l; i < r; ++i) {
if (mx > w[i])
ans = max(ans, mx + w[i]);
else
mx = w[i];
}
return ans;
}
void merg_add(vector<pair<int, int>>& a, pair<int, int> vl) {
while (a.size() && a.back().second <= vl.second) {
a.pop_back();
}
a.push_back(vl);
}
vector<pair<int, int>> merg(vector<pair<int, int>> a, vector<pair<int, int>> b) {
vector<pair<int, int>> ans;
int n = a.size();
int m = b.size();
int j = 0;
for (int i = 0; i < n; ++i) {
while (j < m && b[j] < a[i]) {
merg_add(ans, b[j]);
++j;
}
merg_add(ans, a[i]);
}
while (j < m) {
merg_add(ans, b[j]);
++j;
}
return ans;
}
struct stree {
void resize(int n) {
sz = n;
t.resize(sz * 2 - 1);
init(0, 0, sz);
}
int get(int l, int r) {
return get(0, 0, sz, l, r);
}
private:
int sz;
vector<vector<pair<int, int>>> t;
void init(int ind, int lnd, int rnd) {
if (rnd - lnd == 1) {
if (pv[lnd] >= 0)
t[ind] = {{pv[lnd], w[lnd] + w[pv[lnd]]}};
} else {
int mnd = (lnd + rnd) / 2;
int chd = ind + (mnd - lnd) * 2;
init(ind + 1, lnd, mnd);
init(chd, mnd, rnd);
t[ind] = merg(t[ind + 1], t[chd]);
}
}
int get(int ind, int lnd, int rnd, int l, int r) {
int mnd = (lnd + rnd) / 2;
int chd = ind + (mnd - lnd) * 2;
if (lnd >= l && rnd <= r) {
int i = lower_bound(t[ind].begin(), t[ind].end(), pair<int, int>(l, -1)) - t[ind].begin();
if (i == t[ind].size())
return 0;
return t[ind][i].second;
}
if (lnd >= r || rnd <= l)
return 0;
return max(get(ind + 1, lnd, mnd, l, r), get(chd, mnd, rnd, l, r));
}
};
signed main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i)
cin >> w[i];
vector<pair<int, int>> previnit = {{INF, -1}};
for (int i = 0; i < n; ++i) {
while (previnit.back().first <= w[i]) {
previnit.pop_back();
}
pv[i] = previnit.back().second;
previnit.push_back({w[i], i});
}
stree tr;
tr.resize(n);
for (int i = 0; i < m; ++i) {
int l, r, k;
cin >> l >> r >> k;
--l;
if (tr.get(l, r) > k) {
cout << 0 << '\n';
} else {
cout << 1 << '\n';
}
}
}
Compilation message
sortbooks.cpp: In member function 'int stree::get(int, int, int, int, int)':
sortbooks.cpp:82:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | if (i == t[ind].size())
| ~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
2 ms |
320 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
316 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
2 ms |
320 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
316 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
10 ms |
580 KB |
Output is correct |
12 |
Correct |
15 ms |
1064 KB |
Output is correct |
13 |
Correct |
13 ms |
980 KB |
Output is correct |
14 |
Correct |
19 ms |
1072 KB |
Output is correct |
15 |
Correct |
20 ms |
1108 KB |
Output is correct |
16 |
Correct |
14 ms |
724 KB |
Output is correct |
17 |
Correct |
13 ms |
724 KB |
Output is correct |
18 |
Correct |
13 ms |
920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3068 ms |
153820 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
366 ms |
15360 KB |
Output is correct |
2 |
Correct |
311 ms |
15348 KB |
Output is correct |
3 |
Correct |
282 ms |
7960 KB |
Output is correct |
4 |
Correct |
273 ms |
7964 KB |
Output is correct |
5 |
Correct |
283 ms |
7880 KB |
Output is correct |
6 |
Correct |
255 ms |
8380 KB |
Output is correct |
7 |
Correct |
265 ms |
8364 KB |
Output is correct |
8 |
Correct |
259 ms |
12052 KB |
Output is correct |
9 |
Correct |
202 ms |
1740 KB |
Output is correct |
10 |
Correct |
268 ms |
11228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
2 ms |
320 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
316 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
10 ms |
580 KB |
Output is correct |
12 |
Correct |
15 ms |
1064 KB |
Output is correct |
13 |
Correct |
13 ms |
980 KB |
Output is correct |
14 |
Correct |
19 ms |
1072 KB |
Output is correct |
15 |
Correct |
20 ms |
1108 KB |
Output is correct |
16 |
Correct |
14 ms |
724 KB |
Output is correct |
17 |
Correct |
13 ms |
724 KB |
Output is correct |
18 |
Correct |
13 ms |
920 KB |
Output is correct |
19 |
Correct |
819 ms |
33160 KB |
Output is correct |
20 |
Correct |
783 ms |
32980 KB |
Output is correct |
21 |
Correct |
707 ms |
32812 KB |
Output is correct |
22 |
Correct |
719 ms |
32936 KB |
Output is correct |
23 |
Correct |
712 ms |
32816 KB |
Output is correct |
24 |
Correct |
602 ms |
17976 KB |
Output is correct |
25 |
Correct |
586 ms |
17980 KB |
Output is correct |
26 |
Correct |
632 ms |
18164 KB |
Output is correct |
27 |
Correct |
625 ms |
18108 KB |
Output is correct |
28 |
Correct |
639 ms |
18124 KB |
Output is correct |
29 |
Correct |
625 ms |
18276 KB |
Output is correct |
30 |
Correct |
657 ms |
18232 KB |
Output is correct |
31 |
Correct |
637 ms |
18300 KB |
Output is correct |
32 |
Correct |
642 ms |
18252 KB |
Output is correct |
33 |
Correct |
658 ms |
18216 KB |
Output is correct |
34 |
Correct |
594 ms |
18004 KB |
Output is correct |
35 |
Correct |
585 ms |
17868 KB |
Output is correct |
36 |
Correct |
613 ms |
17632 KB |
Output is correct |
37 |
Correct |
580 ms |
17580 KB |
Output is correct |
38 |
Correct |
584 ms |
17904 KB |
Output is correct |
39 |
Correct |
619 ms |
21764 KB |
Output is correct |
40 |
Correct |
535 ms |
14444 KB |
Output is correct |
41 |
Correct |
609 ms |
23580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
2 ms |
320 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
316 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
10 ms |
580 KB |
Output is correct |
12 |
Correct |
15 ms |
1064 KB |
Output is correct |
13 |
Correct |
13 ms |
980 KB |
Output is correct |
14 |
Correct |
19 ms |
1072 KB |
Output is correct |
15 |
Correct |
20 ms |
1108 KB |
Output is correct |
16 |
Correct |
14 ms |
724 KB |
Output is correct |
17 |
Correct |
13 ms |
724 KB |
Output is correct |
18 |
Correct |
13 ms |
920 KB |
Output is correct |
19 |
Execution timed out |
3068 ms |
153820 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |