# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1099754 |
2024-10-12T05:10:47 Z |
model_code |
Nile (IOI24_nile) |
C++17 |
|
129 ms |
15048 KB |
// correct/hazem_full_set_nlogn.cpp
#include "bits/stdc++.h"
#include "nile.h"
using namespace std;
const int INF = 1e9;
vector<long long> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) {
int n = W.size();
int q = E.size();
vector<int> ordW(n);
iota(ordW.begin() ,ordW.end() ,0);
sort(ordW.begin() ,ordW.end() ,[&](int i ,int j){
return W[i] < W[j];
});
vector <int> ordE(q);
iota(ordE.begin() ,ordE.end() ,0);
sort(ordE.begin() ,ordE.end() ,[&](int i ,int j){
return E[i] < E[j];
});
vector<int> w(n), c(n);
for(int i = 0; i < n; i++){
int j = ordW[i];
w[i] = W[j];
c[i] = A[j] - B[j];
}
vector<array<int, 3>> edges;
for(int i = 0; i < n; i++){
if(i+1 < n) edges.push_back({w[i+1] - w[i], i, 1});
if(i+2 < n) edges.push_back({w[i+2] - w[i], i, 0});
}
sort(edges.rbegin(), edges.rend());
set<int> act;
vector<int> len(n);
vector<array<int, 3>> mnc(n);
long long tot = 0;
for(int i = 0; i < n; i++){
act.insert(i);
len[i] = 1;
mnc[i] = {INF, INF, INF};
mnc[i][i % 2] = c[i];
tot += c[i];
}
auto cost = [&](int i){
int idx = mnc[i][i % 2] < mnc[i][2]? (i % 2) : 2;
return mnc[i][idx] * (len[i] % 2);
};
auto mrg = [&](int i){
int j = *prev(act.upper_bound(i));
int k = i + 1;
tot -= cost(j);
tot -= cost(k);
act.erase(k);
len[j] += len[k];
for(int p = 0; p < 3; p++)
mnc[j][p] = min(mnc[j][p], mnc[k][p]);
tot += cost(j);
};
auto upd = [&](int i){
int j = *prev(act.upper_bound(i));
tot -= cost(j);
mnc[j][2] = min(mnc[j][2], c[i]);
tot += cost(j);
};
vector<long long> R(q, accumulate(B.begin(), B.end(), 0LL));
for(int i = 0; i < q; i++){
while(!edges.empty() && edges.back()[0] <= E[ordE[i]]){
auto [_, x, t] = edges.back(); edges.pop_back();
if(t) mrg(x);
else upd(x + 1);
}
R[ordE[i]] += tot;
}
return R;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
12480 KB |
Output is correct |
2 |
Correct |
70 ms |
12480 KB |
Output is correct |
3 |
Correct |
71 ms |
13048 KB |
Output is correct |
4 |
Correct |
62 ms |
13000 KB |
Output is correct |
5 |
Correct |
61 ms |
12480 KB |
Output is correct |
6 |
Correct |
57 ms |
12488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
12992 KB |
Output is correct |
2 |
Correct |
66 ms |
12484 KB |
Output is correct |
3 |
Correct |
88 ms |
12488 KB |
Output is correct |
4 |
Correct |
86 ms |
12336 KB |
Output is correct |
5 |
Correct |
76 ms |
12484 KB |
Output is correct |
6 |
Correct |
94 ms |
12496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
69 ms |
12480 KB |
Output is correct |
8 |
Correct |
70 ms |
12480 KB |
Output is correct |
9 |
Correct |
71 ms |
13048 KB |
Output is correct |
10 |
Correct |
62 ms |
13000 KB |
Output is correct |
11 |
Correct |
61 ms |
12480 KB |
Output is correct |
12 |
Correct |
57 ms |
12488 KB |
Output is correct |
13 |
Correct |
60 ms |
12992 KB |
Output is correct |
14 |
Correct |
66 ms |
12484 KB |
Output is correct |
15 |
Correct |
88 ms |
12488 KB |
Output is correct |
16 |
Correct |
86 ms |
12336 KB |
Output is correct |
17 |
Correct |
76 ms |
12484 KB |
Output is correct |
18 |
Correct |
94 ms |
12496 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
600 KB |
Output is correct |
24 |
Correct |
2 ms |
604 KB |
Output is correct |
25 |
Correct |
65 ms |
12488 KB |
Output is correct |
26 |
Correct |
69 ms |
12488 KB |
Output is correct |
27 |
Correct |
99 ms |
12472 KB |
Output is correct |
28 |
Correct |
100 ms |
12496 KB |
Output is correct |
29 |
Correct |
89 ms |
12740 KB |
Output is correct |
30 |
Correct |
109 ms |
12364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
12992 KB |
Output is correct |
2 |
Correct |
66 ms |
12484 KB |
Output is correct |
3 |
Correct |
88 ms |
12488 KB |
Output is correct |
4 |
Correct |
86 ms |
12336 KB |
Output is correct |
5 |
Correct |
76 ms |
12484 KB |
Output is correct |
6 |
Correct |
94 ms |
12496 KB |
Output is correct |
7 |
Correct |
90 ms |
14280 KB |
Output is correct |
8 |
Correct |
106 ms |
14280 KB |
Output is correct |
9 |
Correct |
116 ms |
14276 KB |
Output is correct |
10 |
Correct |
119 ms |
14840 KB |
Output is correct |
11 |
Correct |
114 ms |
14812 KB |
Output is correct |
12 |
Correct |
125 ms |
14280 KB |
Output is correct |
13 |
Correct |
115 ms |
14668 KB |
Output is correct |
14 |
Correct |
96 ms |
15048 KB |
Output is correct |
15 |
Correct |
124 ms |
14652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
69 ms |
12480 KB |
Output is correct |
9 |
Correct |
70 ms |
12480 KB |
Output is correct |
10 |
Correct |
71 ms |
13048 KB |
Output is correct |
11 |
Correct |
62 ms |
13000 KB |
Output is correct |
12 |
Correct |
61 ms |
12480 KB |
Output is correct |
13 |
Correct |
57 ms |
12488 KB |
Output is correct |
14 |
Correct |
60 ms |
12992 KB |
Output is correct |
15 |
Correct |
66 ms |
12484 KB |
Output is correct |
16 |
Correct |
88 ms |
12488 KB |
Output is correct |
17 |
Correct |
86 ms |
12336 KB |
Output is correct |
18 |
Correct |
76 ms |
12484 KB |
Output is correct |
19 |
Correct |
94 ms |
12496 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
600 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
65 ms |
12488 KB |
Output is correct |
27 |
Correct |
69 ms |
12488 KB |
Output is correct |
28 |
Correct |
99 ms |
12472 KB |
Output is correct |
29 |
Correct |
100 ms |
12496 KB |
Output is correct |
30 |
Correct |
89 ms |
12740 KB |
Output is correct |
31 |
Correct |
109 ms |
12364 KB |
Output is correct |
32 |
Correct |
90 ms |
14280 KB |
Output is correct |
33 |
Correct |
106 ms |
14280 KB |
Output is correct |
34 |
Correct |
116 ms |
14276 KB |
Output is correct |
35 |
Correct |
119 ms |
14840 KB |
Output is correct |
36 |
Correct |
114 ms |
14812 KB |
Output is correct |
37 |
Correct |
125 ms |
14280 KB |
Output is correct |
38 |
Correct |
115 ms |
14668 KB |
Output is correct |
39 |
Correct |
96 ms |
15048 KB |
Output is correct |
40 |
Correct |
124 ms |
14652 KB |
Output is correct |
41 |
Correct |
95 ms |
15044 KB |
Output is correct |
42 |
Correct |
95 ms |
14536 KB |
Output is correct |
43 |
Correct |
124 ms |
14528 KB |
Output is correct |
44 |
Correct |
125 ms |
14444 KB |
Output is correct |
45 |
Correct |
123 ms |
14408 KB |
Output is correct |
46 |
Correct |
124 ms |
14280 KB |
Output is correct |
47 |
Correct |
117 ms |
14972 KB |
Output is correct |
48 |
Correct |
108 ms |
14280 KB |
Output is correct |
49 |
Correct |
129 ms |
14264 KB |
Output is correct |