# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
155966 |
2019-10-02T10:38:16 Z |
faremy |
Triple Jump (JOI19_jumps) |
C++14 |
|
1831 ms |
90064 KB |
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <utility>
class Interval
{
int left, right;
public:
Interval(int l, int r) : left(l), right(r) {}
bool IsIncludedIn(const Interval &other) const
{
return (other.left <= left && right <= other.right);
}
bool IsDisjointFrom(const Interval &other) const
{
return (other.right <= left || right <= other.left);
}
Interval Left() const
{
return Interval(left, (left + right) / 2);
}
Interval Right() const
{
return Interval((left + right) / 2, right);
}
};
const int MAXN = 5e5;
const int LEAVES = 1 << 19;
const int TSIZE = LEAVES << 1;
const Interval ROOTCOVER = { 0, LEAVES };
int firmness[MAXN];
std::stack<int> useful;
std::vector<std::pair<int, int>> seg[MAXN];
std::vector<std::pair<int, int>> query[MAXN];
int maxFirm[TSIZE];
int bestScore[TSIZE], lazy[TSIZE];
int answer[MAXN];
void createusefulsegments(int positions)
{
for (int iPos = 0; iPos < positions; iPos++)
{
while (!useful.empty() && firmness[useful.top()] < firmness[iPos])
{
seg[useful.top()].emplace_back(2 * iPos - useful.top(), firmness[iPos] + firmness[useful.top()]);
useful.pop();
}
if (!useful.empty())
seg[useful.top()].emplace_back(2 * iPos - useful.top(), firmness[iPos] + firmness[useful.top()]);
useful.emplace(iPos);
}
}
void setup(int positions)
{
for (int iPos = 0; iPos < positions; iPos++)
maxFirm[iPos + LEAVES] = firmness[iPos];
for (int iNode = LEAVES - 1; iNode > 0; iNode--)
maxFirm[iNode] = std::max(maxFirm[iNode * 2], maxFirm[iNode * 2 + 1]);
}
void push(int node)
{
bestScore[node] = std::max(bestScore[node], maxFirm[node] + lazy[node]);
if (node < LEAVES)
{
lazy[node * 2] = std::max(lazy[node * 2], lazy[node]);
lazy[node * 2 + 1] = std::max(lazy[node * 2 + 1], lazy[node]);
}
}
void update(int node, Interval covered, Interval requested, int value)
{
push(node);
if (covered.IsIncludedIn(requested))
{
lazy[node] = std::max(lazy[node], value);
push(node);
}
else if (!covered.IsDisjointFrom(requested))
{
update(node * 2, covered.Left(), requested, value);
update(node * 2 + 1, covered.Right(), requested, value);
bestScore[node] = std::max(bestScore[node], std::max(bestScore[node * 2], bestScore[node * 2 + 1]));
}
}
int request(int node, Interval covered, Interval requested)
{
push(node);
if (covered.IsIncludedIn(requested))
return bestScore[node];
if (covered.IsDisjointFrom(requested))
return 0;
return std::max(request(node * 2, covered.Left(), requested), request(node * 2 + 1, covered.Right(), requested));
}
int main()
{
std::ios::sync_with_stdio(false);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
int positions; std::cin >> positions;
for (int iPos = 0; iPos < positions; iPos++)
std::cin >> firmness[iPos];
createusefulsegments(positions);
setup(positions);
int queries; std::cin >> queries;
for (int iQuery = 0; iQuery < queries; iQuery++)
{
int left, right;
std::cin >> left >> right;
query[left - 1].emplace_back(iQuery, right);
}
for (int iPos = positions - 1; iPos > -1; iPos--)
{
for (std::pair<int, int> &add : seg[iPos])
if (add.first < positions)
update(1, ROOTCOVER, Interval(add.first, positions), add.second);
for (std::pair<int, int> &ask : query[iPos])
answer[ask.first] = request(1, ROOTCOVER, Interval(iPos, ask.second));
}
for (int iQuery = 0; iQuery < queries; iQuery++)
std::cout << answer[iQuery] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
25976 KB |
Output is correct |
2 |
Correct |
32 ms |
26156 KB |
Output is correct |
3 |
Correct |
31 ms |
25976 KB |
Output is correct |
4 |
Correct |
26 ms |
25976 KB |
Output is correct |
5 |
Correct |
32 ms |
25976 KB |
Output is correct |
6 |
Correct |
32 ms |
25976 KB |
Output is correct |
7 |
Correct |
27 ms |
26104 KB |
Output is correct |
8 |
Correct |
32 ms |
25976 KB |
Output is correct |
9 |
Correct |
27 ms |
26104 KB |
Output is correct |
10 |
Correct |
26 ms |
25976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
25976 KB |
Output is correct |
2 |
Correct |
32 ms |
26156 KB |
Output is correct |
3 |
Correct |
31 ms |
25976 KB |
Output is correct |
4 |
Correct |
26 ms |
25976 KB |
Output is correct |
5 |
Correct |
32 ms |
25976 KB |
Output is correct |
6 |
Correct |
32 ms |
25976 KB |
Output is correct |
7 |
Correct |
27 ms |
26104 KB |
Output is correct |
8 |
Correct |
32 ms |
25976 KB |
Output is correct |
9 |
Correct |
27 ms |
26104 KB |
Output is correct |
10 |
Correct |
26 ms |
25976 KB |
Output is correct |
11 |
Correct |
517 ms |
44344 KB |
Output is correct |
12 |
Correct |
513 ms |
44348 KB |
Output is correct |
13 |
Correct |
520 ms |
44240 KB |
Output is correct |
14 |
Correct |
519 ms |
44612 KB |
Output is correct |
15 |
Correct |
520 ms |
44360 KB |
Output is correct |
16 |
Correct |
518 ms |
43768 KB |
Output is correct |
17 |
Correct |
516 ms |
43640 KB |
Output is correct |
18 |
Correct |
522 ms |
43640 KB |
Output is correct |
19 |
Correct |
514 ms |
44320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
362 ms |
39884 KB |
Output is correct |
2 |
Correct |
207 ms |
38776 KB |
Output is correct |
3 |
Correct |
210 ms |
39500 KB |
Output is correct |
4 |
Correct |
363 ms |
39952 KB |
Output is correct |
5 |
Correct |
363 ms |
39932 KB |
Output is correct |
6 |
Correct |
361 ms |
39280 KB |
Output is correct |
7 |
Correct |
370 ms |
39092 KB |
Output is correct |
8 |
Correct |
366 ms |
39260 KB |
Output is correct |
9 |
Correct |
369 ms |
39464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
25976 KB |
Output is correct |
2 |
Correct |
32 ms |
26156 KB |
Output is correct |
3 |
Correct |
31 ms |
25976 KB |
Output is correct |
4 |
Correct |
26 ms |
25976 KB |
Output is correct |
5 |
Correct |
32 ms |
25976 KB |
Output is correct |
6 |
Correct |
32 ms |
25976 KB |
Output is correct |
7 |
Correct |
27 ms |
26104 KB |
Output is correct |
8 |
Correct |
32 ms |
25976 KB |
Output is correct |
9 |
Correct |
27 ms |
26104 KB |
Output is correct |
10 |
Correct |
26 ms |
25976 KB |
Output is correct |
11 |
Correct |
517 ms |
44344 KB |
Output is correct |
12 |
Correct |
513 ms |
44348 KB |
Output is correct |
13 |
Correct |
520 ms |
44240 KB |
Output is correct |
14 |
Correct |
519 ms |
44612 KB |
Output is correct |
15 |
Correct |
520 ms |
44360 KB |
Output is correct |
16 |
Correct |
518 ms |
43768 KB |
Output is correct |
17 |
Correct |
516 ms |
43640 KB |
Output is correct |
18 |
Correct |
522 ms |
43640 KB |
Output is correct |
19 |
Correct |
514 ms |
44320 KB |
Output is correct |
20 |
Correct |
362 ms |
39884 KB |
Output is correct |
21 |
Correct |
207 ms |
38776 KB |
Output is correct |
22 |
Correct |
210 ms |
39500 KB |
Output is correct |
23 |
Correct |
363 ms |
39952 KB |
Output is correct |
24 |
Correct |
363 ms |
39932 KB |
Output is correct |
25 |
Correct |
361 ms |
39280 KB |
Output is correct |
26 |
Correct |
370 ms |
39092 KB |
Output is correct |
27 |
Correct |
366 ms |
39260 KB |
Output is correct |
28 |
Correct |
369 ms |
39464 KB |
Output is correct |
29 |
Correct |
1783 ms |
84436 KB |
Output is correct |
30 |
Correct |
1385 ms |
81072 KB |
Output is correct |
31 |
Correct |
1411 ms |
83164 KB |
Output is correct |
32 |
Correct |
1777 ms |
84424 KB |
Output is correct |
33 |
Correct |
1762 ms |
84388 KB |
Output is correct |
34 |
Correct |
1735 ms |
81944 KB |
Output is correct |
35 |
Correct |
1809 ms |
81856 KB |
Output is correct |
36 |
Correct |
1831 ms |
81776 KB |
Output is correct |
37 |
Correct |
1795 ms |
83104 KB |
Output is correct |
38 |
Correct |
1384 ms |
90064 KB |
Output is correct |
39 |
Correct |
1394 ms |
89920 KB |
Output is correct |
40 |
Correct |
1375 ms |
86664 KB |
Output is correct |
41 |
Correct |
1407 ms |
86116 KB |
Output is correct |
42 |
Correct |
1432 ms |
86240 KB |
Output is correct |
43 |
Correct |
1390 ms |
87984 KB |
Output is correct |
44 |
Correct |
1469 ms |
89248 KB |
Output is correct |
45 |
Correct |
1482 ms |
89540 KB |
Output is correct |
46 |
Correct |
1511 ms |
86264 KB |
Output is correct |
47 |
Correct |
1490 ms |
85852 KB |
Output is correct |
48 |
Correct |
1478 ms |
85868 KB |
Output is correct |
49 |
Correct |
1458 ms |
87928 KB |
Output is correct |
50 |
Correct |
1704 ms |
87428 KB |
Output is correct |
51 |
Correct |
1586 ms |
87400 KB |
Output is correct |
52 |
Correct |
1553 ms |
85068 KB |
Output is correct |
53 |
Correct |
1566 ms |
84728 KB |
Output is correct |
54 |
Correct |
1600 ms |
84844 KB |
Output is correct |
55 |
Correct |
1557 ms |
86432 KB |
Output is correct |