# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1107943 |
2024-11-02T12:15:31 Z |
sleepntsheep |
Nile (IOI24_nile) |
C++17 |
|
146 ms |
19136 KB |
#include "nile.h"
#include <vector>
#include <array>
#include <set>
#include <tuple>
#include <algorithm>
using namespace std;
using ll = long long;
vector<ll> calculate_costs(vector<int> W, vector<int> A,
vector<int> B, vector<int> E) {
vector<tuple<int, int, int> > a;
int n = (int)W.size(), q = (int)E.size();
for (int i = 0; i < n; ++i) a.emplace_back(W[i], A[i], B[i]);
sort(a.begin(), a.end());
for (int i = 0; i < n; ++i) tie(W[i], A[i], B[i]) = a[i];
ll base = 0, added = 0;
for (int i = 0; i < n; ++i) base += B[i];
vector<pair<int, int> > gap1, gap2;
for (int i = 1; i < n; ++i) gap1.emplace_back(W[i] - W[i - 1], i - 1);
for (int i = 2; i < n; ++i) gap2.emplace_back(W[i] - W[i - 2], i - 2);
sort(gap1.begin(), gap1.end(), greater<>());
sort(gap2.begin(), gap2.end(), greater<>());
vector<pair<int, int> > E1;
for (int i = 0; i < q; ++i) E1.emplace_back(E[i], i);
sort(E1.begin(), E1.end());
vector<ll> ans(q);
struct Blk {
int l, r; ll pr[2], jmp;
bool operator<(const Blk&o) const { return r < o.r; }
ll cost() { return (l ^ r) % 2 ? 0ll : min({jmp, pr[l & 1]}); }
};
set<Blk> st;
const ll oo = 1e18;
for (int i = 0; i < n; ++i) {
Blk b = {i, i, {oo, oo}, oo};
b.pr[i & 1] = A[i] - B[i];
st.insert(b);
added += b.cost();
}
for (auto [QrE, QrEi] : E1) {
while (gap1.size() && gap1.back().first <= QrE) {
auto i = gap1.back().second; gap1.pop_back();
auto it = st.lower_bound({0, i, {0, 0}, 0}), it2 = next(it);
auto b = *it, bRig = *it2;
st.erase(it); st.erase(it2);
added -= b.cost() + bRig.cost();
b.r = bRig.r;
for (auto x : {0, 1}) b.pr[x] = min(b.pr[x], bRig.pr[x]);
b.jmp = min(b.jmp, bRig.jmp);
st.insert(b);
added += b.cost();
}
while (gap2.size() && gap2.back().first <= QrE) {
auto i = gap2.back().second; gap2.pop_back();
auto it = st.lower_bound({0, i, {0, 0}, 0});
ll cst = A[i + 1] - B[i + 1];
if (it->jmp > cst) {
auto b = *it; added -= b.cost(); b.jmp = cst;
st.erase(it); st.insert(b);
added += b.cost();
}
}
ans[QrEi] = base + added;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
15816 KB |
Output is correct |
2 |
Correct |
59 ms |
15808 KB |
Output is correct |
3 |
Correct |
54 ms |
15808 KB |
Output is correct |
4 |
Correct |
64 ms |
15808 KB |
Output is correct |
5 |
Correct |
56 ms |
15816 KB |
Output is correct |
6 |
Correct |
53 ms |
15808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
14272 KB |
Output is correct |
2 |
Correct |
66 ms |
14528 KB |
Output is correct |
3 |
Correct |
84 ms |
14536 KB |
Output is correct |
4 |
Correct |
86 ms |
14496 KB |
Output is correct |
5 |
Correct |
79 ms |
14528 KB |
Output is correct |
6 |
Correct |
90 ms |
14528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
592 KB |
Output is correct |
7 |
Correct |
62 ms |
15816 KB |
Output is correct |
8 |
Correct |
59 ms |
15808 KB |
Output is correct |
9 |
Correct |
54 ms |
15808 KB |
Output is correct |
10 |
Correct |
64 ms |
15808 KB |
Output is correct |
11 |
Correct |
56 ms |
15816 KB |
Output is correct |
12 |
Correct |
53 ms |
15808 KB |
Output is correct |
13 |
Correct |
55 ms |
14272 KB |
Output is correct |
14 |
Correct |
66 ms |
14528 KB |
Output is correct |
15 |
Correct |
84 ms |
14536 KB |
Output is correct |
16 |
Correct |
86 ms |
14496 KB |
Output is correct |
17 |
Correct |
79 ms |
14528 KB |
Output is correct |
18 |
Correct |
90 ms |
14528 KB |
Output is correct |
19 |
Correct |
2 ms |
592 KB |
Output is correct |
20 |
Correct |
2 ms |
592 KB |
Output is correct |
21 |
Correct |
2 ms |
592 KB |
Output is correct |
22 |
Correct |
2 ms |
592 KB |
Output is correct |
23 |
Correct |
2 ms |
592 KB |
Output is correct |
24 |
Correct |
2 ms |
592 KB |
Output is correct |
25 |
Correct |
65 ms |
15920 KB |
Output is correct |
26 |
Correct |
72 ms |
16124 KB |
Output is correct |
27 |
Correct |
93 ms |
16064 KB |
Output is correct |
28 |
Correct |
94 ms |
16044 KB |
Output is correct |
29 |
Correct |
79 ms |
16108 KB |
Output is correct |
30 |
Correct |
97 ms |
16064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
14272 KB |
Output is correct |
2 |
Correct |
66 ms |
14528 KB |
Output is correct |
3 |
Correct |
84 ms |
14536 KB |
Output is correct |
4 |
Correct |
86 ms |
14496 KB |
Output is correct |
5 |
Correct |
79 ms |
14528 KB |
Output is correct |
6 |
Correct |
90 ms |
14528 KB |
Output is correct |
7 |
Correct |
79 ms |
17344 KB |
Output is correct |
8 |
Correct |
97 ms |
17600 KB |
Output is correct |
9 |
Correct |
123 ms |
17600 KB |
Output is correct |
10 |
Correct |
110 ms |
17572 KB |
Output is correct |
11 |
Correct |
111 ms |
17584 KB |
Output is correct |
12 |
Correct |
112 ms |
17448 KB |
Output is correct |
13 |
Correct |
125 ms |
17444 KB |
Output is correct |
14 |
Correct |
96 ms |
17320 KB |
Output is correct |
15 |
Correct |
125 ms |
17528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
592 KB |
Output is correct |
8 |
Correct |
62 ms |
15816 KB |
Output is correct |
9 |
Correct |
59 ms |
15808 KB |
Output is correct |
10 |
Correct |
54 ms |
15808 KB |
Output is correct |
11 |
Correct |
64 ms |
15808 KB |
Output is correct |
12 |
Correct |
56 ms |
15816 KB |
Output is correct |
13 |
Correct |
53 ms |
15808 KB |
Output is correct |
14 |
Correct |
55 ms |
14272 KB |
Output is correct |
15 |
Correct |
66 ms |
14528 KB |
Output is correct |
16 |
Correct |
84 ms |
14536 KB |
Output is correct |
17 |
Correct |
86 ms |
14496 KB |
Output is correct |
18 |
Correct |
79 ms |
14528 KB |
Output is correct |
19 |
Correct |
90 ms |
14528 KB |
Output is correct |
20 |
Correct |
2 ms |
592 KB |
Output is correct |
21 |
Correct |
2 ms |
592 KB |
Output is correct |
22 |
Correct |
2 ms |
592 KB |
Output is correct |
23 |
Correct |
2 ms |
592 KB |
Output is correct |
24 |
Correct |
2 ms |
592 KB |
Output is correct |
25 |
Correct |
2 ms |
592 KB |
Output is correct |
26 |
Correct |
65 ms |
15920 KB |
Output is correct |
27 |
Correct |
72 ms |
16124 KB |
Output is correct |
28 |
Correct |
93 ms |
16064 KB |
Output is correct |
29 |
Correct |
94 ms |
16044 KB |
Output is correct |
30 |
Correct |
79 ms |
16108 KB |
Output is correct |
31 |
Correct |
97 ms |
16064 KB |
Output is correct |
32 |
Correct |
79 ms |
17344 KB |
Output is correct |
33 |
Correct |
97 ms |
17600 KB |
Output is correct |
34 |
Correct |
123 ms |
17600 KB |
Output is correct |
35 |
Correct |
110 ms |
17572 KB |
Output is correct |
36 |
Correct |
111 ms |
17584 KB |
Output is correct |
37 |
Correct |
112 ms |
17448 KB |
Output is correct |
38 |
Correct |
125 ms |
17444 KB |
Output is correct |
39 |
Correct |
96 ms |
17320 KB |
Output is correct |
40 |
Correct |
125 ms |
17528 KB |
Output is correct |
41 |
Correct |
86 ms |
18880 KB |
Output is correct |
42 |
Correct |
104 ms |
19120 KB |
Output is correct |
43 |
Correct |
146 ms |
19136 KB |
Output is correct |
44 |
Correct |
120 ms |
19100 KB |
Output is correct |
45 |
Correct |
123 ms |
19108 KB |
Output is correct |
46 |
Correct |
121 ms |
18880 KB |
Output is correct |
47 |
Correct |
121 ms |
19136 KB |
Output is correct |
48 |
Correct |
108 ms |
18880 KB |
Output is correct |
49 |
Correct |
129 ms |
18972 KB |
Output is correct |