# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1102258 |
2024-10-18T01:11:41 Z |
nhphuc |
Nile (IOI24_nile) |
C++17 |
|
132 ms |
22220 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
void init (vector<int32_t> &a, vector<pair<int, int>> &b){
vector<int32_t> tmp = a;
for (int i = 0; i < b.size(); ++i)
a[i] = tmp[b[i].second];
return;
}
bool cmp (array<int, 3> a, array<int, 3> b){
for (int i = 0; i < 3; ++i)
if (a[i] < b[i])
return true;
else
if (a[i] > b[i])
return false;
return true;
}
const int inf = 1e12;
vector<int> calculate_costs (
vector<int32_t> w, vector<int32_t> a,
vector<int32_t> b, vector<int32_t> e
){
int n = a.size(), q = e.size();
set<int> st;
vector<int> ans(q), c(n), sz(n);
vector<pair<int, int>> d(q), x(n);
vector<array<int, 3>> events, mn(n, {inf, inf, inf});
for (int i = 0; i < n; ++i)
x[i] = {w[i], i};
for (int i = 0; i < q; ++i)
d[i] = {e[i], i};
sort(d.begin(), d.end());
sort(x.begin(), x.end());
init(a, x);
init(b, x);
init(w, x);
int res = accumulate(b.begin(), b.end(), 0ll), add = 0;
for (int i = 0; i < n; ++i){
st.insert(i);
c[i] = a[i] - b[i];
sz[i] = 1;
mn[i][i & 1] = c[i];
add += c[i];
if (i + 1 < n)
events.push_back({w[i + 1] - w[i], i, 0});
if (i + 2 < n)
events.push_back({w[i + 2] - w[i], i, 1});
}
sort(events.begin(), events.end());
auto fi = [&] (int i){
return min(mn[i][i & 1], mn[i][2]) * (sz[i] & 1);
};
auto u1 = [&] (int i){
int j = *prev(st.upper_bound(i));
int k = i + 1;
add -= (fi(j) + fi(k));
st.erase(k);
sz[j] += sz[k];
for (int l = 0; l < 3; ++l)
mn[j][l] = min(mn[j][l], mn[k][l]);
add += fi(j);
};
auto u2 = [&] (int i){
int j = *prev(st.upper_bound(i));
add -= fi(j);
mn[j][2] = min(mn[j][2], c[i + 1]);
add += fi(j);
};
int j = 0;
for (auto [x, y] : d){
while (j < events.size() && events[j][0] <= x){
int i = events[j][1];
if (events[j][2])
u2(i);
else
u1(i);
++j;
}
ans[y] = res + add;
}
return ans;
}
Compilation message
nile.cpp: In function 'void init(std::vector<int>&, std::vector<std::pair<long long int, long long int> >&)':
nile.cpp:9:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | for (int i = 0; i < b.size(); ++i)
| ~~^~~~~~~~~~
nile.cpp: In function 'std::vector<long long int> calculate_costs(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
nile.cpp:78:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | while (j < events.size() && events[j][0] <= x){
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
2 ms |
760 KB |
Output is correct |
5 |
Correct |
1 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
18948 KB |
Output is correct |
2 |
Correct |
61 ms |
18868 KB |
Output is correct |
3 |
Correct |
60 ms |
18892 KB |
Output is correct |
4 |
Correct |
79 ms |
18868 KB |
Output is correct |
5 |
Correct |
62 ms |
18908 KB |
Output is correct |
6 |
Correct |
61 ms |
19120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
19048 KB |
Output is correct |
2 |
Correct |
69 ms |
18868 KB |
Output is correct |
3 |
Correct |
92 ms |
18868 KB |
Output is correct |
4 |
Correct |
90 ms |
19132 KB |
Output is correct |
5 |
Correct |
77 ms |
19124 KB |
Output is correct |
6 |
Correct |
99 ms |
19124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
2 ms |
760 KB |
Output is correct |
5 |
Correct |
1 ms |
592 KB |
Output is correct |
6 |
Correct |
2 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 |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
2 ms |
760 KB |
Output is correct |
5 |
Correct |
1 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
66 ms |
18948 KB |
Output is correct |
8 |
Correct |
61 ms |
18868 KB |
Output is correct |
9 |
Correct |
60 ms |
18892 KB |
Output is correct |
10 |
Correct |
79 ms |
18868 KB |
Output is correct |
11 |
Correct |
62 ms |
18908 KB |
Output is correct |
12 |
Correct |
61 ms |
19120 KB |
Output is correct |
13 |
Correct |
67 ms |
19048 KB |
Output is correct |
14 |
Correct |
69 ms |
18868 KB |
Output is correct |
15 |
Correct |
92 ms |
18868 KB |
Output is correct |
16 |
Correct |
90 ms |
19132 KB |
Output is correct |
17 |
Correct |
77 ms |
19124 KB |
Output is correct |
18 |
Correct |
99 ms |
19124 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 |
68 ms |
18868 KB |
Output is correct |
26 |
Correct |
88 ms |
19036 KB |
Output is correct |
27 |
Correct |
96 ms |
19136 KB |
Output is correct |
28 |
Correct |
99 ms |
18872 KB |
Output is correct |
29 |
Correct |
92 ms |
19124 KB |
Output is correct |
30 |
Correct |
109 ms |
18932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
19048 KB |
Output is correct |
2 |
Correct |
69 ms |
18868 KB |
Output is correct |
3 |
Correct |
92 ms |
18868 KB |
Output is correct |
4 |
Correct |
90 ms |
19132 KB |
Output is correct |
5 |
Correct |
77 ms |
19124 KB |
Output is correct |
6 |
Correct |
99 ms |
19124 KB |
Output is correct |
7 |
Correct |
87 ms |
22008 KB |
Output is correct |
8 |
Correct |
90 ms |
22196 KB |
Output is correct |
9 |
Correct |
116 ms |
22196 KB |
Output is correct |
10 |
Correct |
115 ms |
22204 KB |
Output is correct |
11 |
Correct |
110 ms |
22196 KB |
Output is correct |
12 |
Correct |
111 ms |
22100 KB |
Output is correct |
13 |
Correct |
124 ms |
22064 KB |
Output is correct |
14 |
Correct |
96 ms |
22196 KB |
Output is correct |
15 |
Correct |
120 ms |
22196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
592 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 |
760 KB |
Output is correct |
6 |
Correct |
1 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
66 ms |
18948 KB |
Output is correct |
9 |
Correct |
61 ms |
18868 KB |
Output is correct |
10 |
Correct |
60 ms |
18892 KB |
Output is correct |
11 |
Correct |
79 ms |
18868 KB |
Output is correct |
12 |
Correct |
62 ms |
18908 KB |
Output is correct |
13 |
Correct |
61 ms |
19120 KB |
Output is correct |
14 |
Correct |
67 ms |
19048 KB |
Output is correct |
15 |
Correct |
69 ms |
18868 KB |
Output is correct |
16 |
Correct |
92 ms |
18868 KB |
Output is correct |
17 |
Correct |
90 ms |
19132 KB |
Output is correct |
18 |
Correct |
77 ms |
19124 KB |
Output is correct |
19 |
Correct |
99 ms |
19124 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 |
68 ms |
18868 KB |
Output is correct |
27 |
Correct |
88 ms |
19036 KB |
Output is correct |
28 |
Correct |
96 ms |
19136 KB |
Output is correct |
29 |
Correct |
99 ms |
18872 KB |
Output is correct |
30 |
Correct |
92 ms |
19124 KB |
Output is correct |
31 |
Correct |
109 ms |
18932 KB |
Output is correct |
32 |
Correct |
87 ms |
22008 KB |
Output is correct |
33 |
Correct |
90 ms |
22196 KB |
Output is correct |
34 |
Correct |
116 ms |
22196 KB |
Output is correct |
35 |
Correct |
115 ms |
22204 KB |
Output is correct |
36 |
Correct |
110 ms |
22196 KB |
Output is correct |
37 |
Correct |
111 ms |
22100 KB |
Output is correct |
38 |
Correct |
124 ms |
22064 KB |
Output is correct |
39 |
Correct |
96 ms |
22196 KB |
Output is correct |
40 |
Correct |
120 ms |
22196 KB |
Output is correct |
41 |
Correct |
88 ms |
22072 KB |
Output is correct |
42 |
Correct |
103 ms |
22196 KB |
Output is correct |
43 |
Correct |
118 ms |
22196 KB |
Output is correct |
44 |
Correct |
126 ms |
22196 KB |
Output is correct |
45 |
Correct |
132 ms |
22196 KB |
Output is correct |
46 |
Correct |
130 ms |
22196 KB |
Output is correct |
47 |
Correct |
122 ms |
22196 KB |
Output is correct |
48 |
Correct |
105 ms |
22196 KB |
Output is correct |
49 |
Correct |
131 ms |
22220 KB |
Output is correct |