# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1102198 |
2024-10-17T16:11:03 Z |
nhphuc |
Nile (IOI24_nile) |
C++17 |
|
64 ms |
14028 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
void init (vector<int32_t> &a, vector<pair<int32_t, int32_t>> &b){
vector<int32_t> tmp = a;
for (int i = 0; i < b.size(); ++i)
a[i] = tmp[b[i].second];
return;
}
const int N = 100007;
vector<int> par(N), mn(N), sum(N), sz(N), val(N);
int acs (int u){
return (u == par[u] ? u : par[u] = acs(par[u]));
}
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();
vector<int> ans(q), c(n); vector<pair<int32_t, int32_t>> d(q), x(n), events;
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(a.begin(), a.end(), 0ll);
for (int i = 0; i < n; ++i){
par[i] = i;
sz[i] = 1;
sum[i] = b[i];
c[i] = a[i] - b[i];
mn[i] = c[i];
val[i] = a[i];
}
for (int i = 0; i < n - 1; ++i)
events.push_back({w[i + 1] - w[i], i});
sort(events.begin(), events.end());
int j = 0;
for (auto [x, y] : d){
while (j < events.size() && events[j].first <= x){
int i = events[j].second;
int u = acs(i);
int v = acs(i + 1);
res -= val[u] + val[v];
if (sz[u] < sz[v])
swap(u, v);
par[v] = u;
sz[u] += sz[v];
mn[u] = min(mn[u], mn[v]);
sum[u] += sum[v];
val[u] = (sz[u] % 2 ? sum[u] + mn[u] : sum[u]);
res += val[u];
++j;
}
ans[y] = res;
}
return ans;
}
// int32_t main (){
// #define task "test"
// if (fopen(task".inp", "r")){
// freopen(task".inp", "r", stdin);
// freopen(task".out", "w", stdout);
// }
// int n, q; cin >> n >> q;
// vector<int32_t> w(n), a(n), b(n), e(q);
// for (int32_t &x : w) cin >> x;
// for (int32_t &x : a) cin >> x;
// for (int32_t &x : b) cin >> x;
// for (int32_t &x : e) cin >> x;
// vector<int> ans = calculate_costs(w, a, b, e);
// for (int x : ans)
// cout << x << " ";
// }
Compilation message
nile.cpp: In function 'void init(std::vector<int>&, std::vector<std::pair<int, int> >&)':
nile.cpp:9:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, 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:51:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | while (j < events.size() && events[j].first <= x){
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4432 KB |
Output is correct |
2 |
Correct |
4 ms |
4432 KB |
Output is correct |
3 |
Correct |
3 ms |
4432 KB |
Output is correct |
4 |
Correct |
4 ms |
4432 KB |
Output is correct |
5 |
Correct |
4 ms |
4432 KB |
Output is correct |
6 |
Correct |
3 ms |
4432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
12224 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
10944 KB |
Output is correct |
2 |
Correct |
32 ms |
10960 KB |
Output is correct |
3 |
Correct |
37 ms |
11124 KB |
Output is correct |
4 |
Correct |
38 ms |
10944 KB |
Output is correct |
5 |
Correct |
37 ms |
11028 KB |
Output is correct |
6 |
Correct |
41 ms |
11116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4432 KB |
Output is correct |
2 |
Correct |
4 ms |
4432 KB |
Output is correct |
3 |
Correct |
3 ms |
4432 KB |
Output is correct |
4 |
Correct |
4 ms |
4432 KB |
Output is correct |
5 |
Correct |
4 ms |
4432 KB |
Output is correct |
6 |
Correct |
3 ms |
4432 KB |
Output is correct |
7 |
Incorrect |
4 ms |
4432 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4432 KB |
Output is correct |
2 |
Correct |
4 ms |
4432 KB |
Output is correct |
3 |
Correct |
3 ms |
4432 KB |
Output is correct |
4 |
Correct |
4 ms |
4432 KB |
Output is correct |
5 |
Correct |
4 ms |
4432 KB |
Output is correct |
6 |
Correct |
3 ms |
4432 KB |
Output is correct |
7 |
Incorrect |
33 ms |
12224 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
10944 KB |
Output is correct |
2 |
Correct |
32 ms |
10960 KB |
Output is correct |
3 |
Correct |
37 ms |
11124 KB |
Output is correct |
4 |
Correct |
38 ms |
10944 KB |
Output is correct |
5 |
Correct |
37 ms |
11028 KB |
Output is correct |
6 |
Correct |
41 ms |
11116 KB |
Output is correct |
7 |
Correct |
53 ms |
13700 KB |
Output is correct |
8 |
Correct |
64 ms |
14016 KB |
Output is correct |
9 |
Correct |
61 ms |
14028 KB |
Output is correct |
10 |
Correct |
59 ms |
14016 KB |
Output is correct |
11 |
Correct |
58 ms |
14016 KB |
Output is correct |
12 |
Correct |
57 ms |
13964 KB |
Output is correct |
13 |
Correct |
58 ms |
14016 KB |
Output is correct |
14 |
Correct |
56 ms |
13732 KB |
Output is correct |
15 |
Correct |
61 ms |
13964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4176 KB |
Output is correct |
2 |
Correct |
4 ms |
4432 KB |
Output is correct |
3 |
Correct |
4 ms |
4432 KB |
Output is correct |
4 |
Correct |
3 ms |
4432 KB |
Output is correct |
5 |
Correct |
4 ms |
4432 KB |
Output is correct |
6 |
Correct |
4 ms |
4432 KB |
Output is correct |
7 |
Correct |
3 ms |
4432 KB |
Output is correct |
8 |
Incorrect |
33 ms |
12224 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |