# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1109436 |
2024-11-06T17:24:34 Z |
Ludissey |
Nile (IOI24_nile) |
C++17 |
|
90 ms |
21076 KB |
#include "nile.h"
#include <bits/stdc++.h>
#define int long long
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
vector<int> parent;
vector<int> sz;
vector<int> mnDEF;
vector<pair<int,pair<int,int>>> _a;
vector<int> mnEV;
vector<int> mnUV;
vector<pair<int,int>> mnBORDER;
vector<int> mn;
int sm=0;
int getParent(int x){
if(parent[x]==x) return x;
return parent[x]=getParent(parent[x]);
}
void unite(int a, int b){
a=getParent(a); b=getParent(b);
if(a==b) return;
parent[b]=a;
if(sz[a]%2) sm-=mn[a];
if(sz[b]%2) sm-=mn[b];
if(sz[a]%2){
mnEV[a]=min(mnEV[a], mnUV[b]);
mnUV[a]=min(mnUV[a], mnEV[b]);
}else{
mnEV[a]=min(mnEV[a], mnEV[b]);
mnUV[a]=min(mnUV[a], mnUV[b]);
}
mnBORDER[a].second=mnBORDER[b].second;
sz[a]+=sz[b];
mnDEF[a]=min(mnDEF[a],mnDEF[b]);
mn[a]=min(mnDEF[a],min(mnEV[a],min(mnBORDER[a].first,mnBORDER[a].second)));
if(sz[a]%2) sm+=mn[a];
}
void addMN(int x){
int p=getParent(x);
mnDEF[p]=min(mnDEF[p],(_a[x].second.first-_a[x].second.second));
if(sz[p]%2) sm-=mn[p];
mn[p]=min(mn[p],mnDEF[p]);
if(sz[p]%2) sm+=mn[p];
}
std::vector<int> calculate_costs(std::vector<signed> W, std::vector<signed> A, std::vector<signed> B, std::vector<signed> E) {
int q = sz(E);
int n=sz(W);
mn.resize(n,1e17); sz.resize(n); parent.resize(n);
mnDEF.resize(n,1e17);
mnEV.resize(n,1e17);
mnUV.resize(n,1e17);
mnBORDER.resize(n,{1e17,1e17});
vector<pair<int,int>> e(q);
_a.resize(n);
for (int i = 0; i < q; i++) e[i]={E[i],i};
for (int i = 0; i < n; i++) _a[i]={W[i],{A[i],B[i]}};
sort(all(_a));
sort(all(e));
vector<pair<int,int>> df(n-1);
vector<pair<int,int>> df2(n-2);
for (int i = 0; i < n-1; i++) df[i]={_a[i+1].first-_a[i].first,i};
for (int i = 0; i < n-2; i++) df2[i]={_a[i+2].first-_a[i].first,i};
sm=0;
for (int i = 0; i < n; i++)
{
sm+=_a[i].second.first;
sz[i]=1;
parent[i]=i;
mn[i]=_a[i].second.first-_a[i].second.second;
mnEV[i]=_a[i].second.first-_a[i].second.second;
mnBORDER[i]={_a[i].second.first-_a[i].second.second,_a[i].second.first-_a[i].second.second};
}
sort(all(df));
sort(all(df2));
std::vector<int> R(q, 0);
int j=0;
int j2=0;
for (int i = 0; i < q; i++)
{
while(j<n-1){
if(df[j].first>e[i].first) break;
unite(df[j].second,df[j].second+1);
j++;
}
while(j2<n-2){
if(df2[j2].first>e[i].first) break;
addMN(df2[j2].second+1);
j2++;
}
R[e[i].second]=sm;
}
return R;
}
# |
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 |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
1 ms |
712 KB |
Output is correct |
6 |
Correct |
2 ms |
932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
14416 KB |
Output is correct |
2 |
Correct |
38 ms |
16968 KB |
Output is correct |
3 |
Correct |
42 ms |
16828 KB |
Output is correct |
4 |
Correct |
37 ms |
16968 KB |
Output is correct |
5 |
Correct |
39 ms |
16968 KB |
Output is correct |
6 |
Correct |
39 ms |
16976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
15296 KB |
Output is correct |
2 |
Correct |
41 ms |
15944 KB |
Output is correct |
3 |
Correct |
51 ms |
15696 KB |
Output is correct |
4 |
Correct |
53 ms |
15820 KB |
Output is correct |
5 |
Correct |
49 ms |
15860 KB |
Output is correct |
6 |
Correct |
53 ms |
15676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
1 ms |
712 KB |
Output is correct |
6 |
Correct |
2 ms |
932 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 |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
1 ms |
712 KB |
Output is correct |
6 |
Correct |
2 ms |
932 KB |
Output is correct |
7 |
Correct |
41 ms |
14416 KB |
Output is correct |
8 |
Correct |
38 ms |
16968 KB |
Output is correct |
9 |
Correct |
42 ms |
16828 KB |
Output is correct |
10 |
Correct |
37 ms |
16968 KB |
Output is correct |
11 |
Correct |
39 ms |
16968 KB |
Output is correct |
12 |
Correct |
39 ms |
16976 KB |
Output is correct |
13 |
Correct |
36 ms |
15296 KB |
Output is correct |
14 |
Correct |
41 ms |
15944 KB |
Output is correct |
15 |
Correct |
51 ms |
15696 KB |
Output is correct |
16 |
Correct |
53 ms |
15820 KB |
Output is correct |
17 |
Correct |
49 ms |
15860 KB |
Output is correct |
18 |
Correct |
53 ms |
15676 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 |
46 ms |
16976 KB |
Output is correct |
26 |
Correct |
49 ms |
17724 KB |
Output is correct |
27 |
Correct |
58 ms |
17372 KB |
Output is correct |
28 |
Correct |
67 ms |
17224 KB |
Output is correct |
29 |
Correct |
53 ms |
17264 KB |
Output is correct |
30 |
Correct |
60 ms |
17228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
15296 KB |
Output is correct |
2 |
Correct |
41 ms |
15944 KB |
Output is correct |
3 |
Correct |
51 ms |
15696 KB |
Output is correct |
4 |
Correct |
53 ms |
15820 KB |
Output is correct |
5 |
Correct |
49 ms |
15860 KB |
Output is correct |
6 |
Correct |
53 ms |
15676 KB |
Output is correct |
7 |
Correct |
57 ms |
19272 KB |
Output is correct |
8 |
Correct |
58 ms |
19544 KB |
Output is correct |
9 |
Correct |
68 ms |
19528 KB |
Output is correct |
10 |
Correct |
69 ms |
19524 KB |
Output is correct |
11 |
Correct |
67 ms |
19468 KB |
Output is correct |
12 |
Correct |
67 ms |
19528 KB |
Output is correct |
13 |
Correct |
68 ms |
19512 KB |
Output is correct |
14 |
Correct |
65 ms |
19224 KB |
Output is correct |
15 |
Correct |
74 ms |
19528 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 |
592 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
712 KB |
Output is correct |
7 |
Correct |
2 ms |
932 KB |
Output is correct |
8 |
Correct |
41 ms |
14416 KB |
Output is correct |
9 |
Correct |
38 ms |
16968 KB |
Output is correct |
10 |
Correct |
42 ms |
16828 KB |
Output is correct |
11 |
Correct |
37 ms |
16968 KB |
Output is correct |
12 |
Correct |
39 ms |
16968 KB |
Output is correct |
13 |
Correct |
39 ms |
16976 KB |
Output is correct |
14 |
Correct |
36 ms |
15296 KB |
Output is correct |
15 |
Correct |
41 ms |
15944 KB |
Output is correct |
16 |
Correct |
51 ms |
15696 KB |
Output is correct |
17 |
Correct |
53 ms |
15820 KB |
Output is correct |
18 |
Correct |
49 ms |
15860 KB |
Output is correct |
19 |
Correct |
53 ms |
15676 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 |
46 ms |
16976 KB |
Output is correct |
27 |
Correct |
49 ms |
17724 KB |
Output is correct |
28 |
Correct |
58 ms |
17372 KB |
Output is correct |
29 |
Correct |
67 ms |
17224 KB |
Output is correct |
30 |
Correct |
53 ms |
17264 KB |
Output is correct |
31 |
Correct |
60 ms |
17228 KB |
Output is correct |
32 |
Correct |
57 ms |
19272 KB |
Output is correct |
33 |
Correct |
58 ms |
19544 KB |
Output is correct |
34 |
Correct |
68 ms |
19528 KB |
Output is correct |
35 |
Correct |
69 ms |
19524 KB |
Output is correct |
36 |
Correct |
67 ms |
19468 KB |
Output is correct |
37 |
Correct |
67 ms |
19528 KB |
Output is correct |
38 |
Correct |
68 ms |
19512 KB |
Output is correct |
39 |
Correct |
65 ms |
19224 KB |
Output is correct |
40 |
Correct |
74 ms |
19528 KB |
Output is correct |
41 |
Correct |
64 ms |
20816 KB |
Output is correct |
42 |
Correct |
68 ms |
21064 KB |
Output is correct |
43 |
Correct |
83 ms |
21064 KB |
Output is correct |
44 |
Correct |
83 ms |
20916 KB |
Output is correct |
45 |
Correct |
83 ms |
21064 KB |
Output is correct |
46 |
Correct |
85 ms |
21064 KB |
Output is correct |
47 |
Correct |
85 ms |
21076 KB |
Output is correct |
48 |
Correct |
76 ms |
20904 KB |
Output is correct |
49 |
Correct |
90 ms |
21064 KB |
Output is correct |