Submission #1099755

# Submission time Handle Problem Language Result Execution time Memory
1099755 2024-10-12T05:10:59 Z model_code Nile (IOI24_nile) C++17
100 / 100
86 ms 17860 KB
// correct/betatester_solution.cpp

#include "nile.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;


#define rep(i, a, b) for(int i = (a); i < (b); ++ i)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back

const int maxn = 2e5 + 100;
const int inf = 1e9 + 100;

ll cost = 0;

int dsu[maxn];
int sz[maxn];
int mn[maxn][3];

int a[maxn];
int c[maxn];

int root(int v){
    if(dsu[v] == v) return v;
    return dsu[v] = root(dsu[v]);
}

inline int Calc(int v){
    assert(v == root(v));
    return ((sz[v] & 1) ? min(mn[v][2], mn[v][v & 1]) : 0);
}

void Vol(int i){
    assert(root(i) == root(i + 1) && root(i) == root(i - 1));
    int v = root(i);
    cost -= Calc(v);
    mn[v][2] = min(mn[v][2], c[i]);
    cost += Calc(v);
}

void Union(int v, int u){
    v = root(v);
    u = root(u);
    assert(v != u);
    if(v > u) swap(v, u);
    cost -= Calc(v);
    cost -= Calc(u);
    dsu[u] = v;
    sz[v] += sz[u];
    rep(i, 0, 3){
        mn[v][i] = min(mn[v][i], mn[u][i]);
    }
    cost += Calc(v);
}

vector<long long>calculate_costs(vector<int>W, vector<int>A, vector<int>B, vector<int>E) {
    vector<ll> ans(SZ(E));
	int n = SZ(W);
	ll s = 0;
	for(int i : B) s += i;
	vector<pii> vec(n);
	rep(i, 0, n){
		vec[i] = {W[i], A[i] - B[i]};
	}
	sort(all(vec));
	
	rep(i, 0, n){
		a[i] = vec[i].F;
		c[i] = vec[i].S;
        assert(c[i] < inf);
        assert(c[i] >= 0);
	}

    rep(i, 0, n){
        dsu[i] = i;
        sz[i] = 1;
        rep(j, 0, 3) mn[i][j] = inf;
        mn[i][i & 1] = c[i];
        cost += Calc(i);
    }

    vector<pair<int, pii> > sonic;

    rep(i, 1, n){
        sonic.pb({a[i] - a[i - 1], {0, i}});
    }
    rep(i, 1, n - 1){
        sonic.pb({a[i + 1] - a[i - 1], {1, i}});
    }
    rep(i, 0, SZ(E)){
        sonic.pb({E[i], {2, i}});
    }
    
    sort(all(sonic));

    for(auto x : sonic){
        int t = x.S.F;
        int i = x.S.S;
        if(t == 0){
            Union(i, i - 1);
        }
        else if(t == 1){
            Vol(i);
        }
        else{
            ans[i] = s + cost;
        }
    }
	
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 11992 KB Output is correct
2 Correct 32 ms 11464 KB Output is correct
3 Correct 32 ms 12244 KB Output is correct
4 Correct 32 ms 11476 KB Output is correct
5 Correct 31 ms 12760 KB Output is correct
6 Correct 33 ms 11472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 12228 KB Output is correct
2 Correct 38 ms 11984 KB Output is correct
3 Correct 44 ms 11464 KB Output is correct
4 Correct 47 ms 11976 KB Output is correct
5 Correct 51 ms 11464 KB Output is correct
6 Correct 49 ms 13012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 2 ms 4696 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
9 Correct 2 ms 4700 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 2 ms 4724 KB Output is correct
12 Correct 2 ms 4616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 31 ms 11992 KB Output is correct
8 Correct 32 ms 11464 KB Output is correct
9 Correct 32 ms 12244 KB Output is correct
10 Correct 32 ms 11476 KB Output is correct
11 Correct 31 ms 12760 KB Output is correct
12 Correct 33 ms 11472 KB Output is correct
13 Correct 35 ms 12228 KB Output is correct
14 Correct 38 ms 11984 KB Output is correct
15 Correct 44 ms 11464 KB Output is correct
16 Correct 47 ms 11976 KB Output is correct
17 Correct 51 ms 11464 KB Output is correct
18 Correct 49 ms 13012 KB Output is correct
19 Correct 2 ms 4696 KB Output is correct
20 Correct 2 ms 4700 KB Output is correct
21 Correct 2 ms 4700 KB Output is correct
22 Correct 2 ms 4700 KB Output is correct
23 Correct 2 ms 4724 KB Output is correct
24 Correct 2 ms 4616 KB Output is correct
25 Correct 52 ms 12748 KB Output is correct
26 Correct 51 ms 12404 KB Output is correct
27 Correct 57 ms 11460 KB Output is correct
28 Correct 53 ms 11468 KB Output is correct
29 Correct 53 ms 11476 KB Output is correct
30 Correct 56 ms 12740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 12228 KB Output is correct
2 Correct 38 ms 11984 KB Output is correct
3 Correct 44 ms 11464 KB Output is correct
4 Correct 47 ms 11976 KB Output is correct
5 Correct 51 ms 11464 KB Output is correct
6 Correct 49 ms 13012 KB Output is correct
7 Correct 69 ms 16580 KB Output is correct
8 Correct 66 ms 17360 KB Output is correct
9 Correct 73 ms 16324 KB Output is correct
10 Correct 70 ms 17480 KB Output is correct
11 Correct 72 ms 17600 KB Output is correct
12 Correct 71 ms 16836 KB Output is correct
13 Correct 72 ms 16836 KB Output is correct
14 Correct 68 ms 17100 KB Output is correct
15 Correct 76 ms 16336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 31 ms 11992 KB Output is correct
9 Correct 32 ms 11464 KB Output is correct
10 Correct 32 ms 12244 KB Output is correct
11 Correct 32 ms 11476 KB Output is correct
12 Correct 31 ms 12760 KB Output is correct
13 Correct 33 ms 11472 KB Output is correct
14 Correct 35 ms 12228 KB Output is correct
15 Correct 38 ms 11984 KB Output is correct
16 Correct 44 ms 11464 KB Output is correct
17 Correct 47 ms 11976 KB Output is correct
18 Correct 51 ms 11464 KB Output is correct
19 Correct 49 ms 13012 KB Output is correct
20 Correct 2 ms 4696 KB Output is correct
21 Correct 2 ms 4700 KB Output is correct
22 Correct 2 ms 4700 KB Output is correct
23 Correct 2 ms 4700 KB Output is correct
24 Correct 2 ms 4724 KB Output is correct
25 Correct 2 ms 4616 KB Output is correct
26 Correct 52 ms 12748 KB Output is correct
27 Correct 51 ms 12404 KB Output is correct
28 Correct 57 ms 11460 KB Output is correct
29 Correct 53 ms 11468 KB Output is correct
30 Correct 53 ms 11476 KB Output is correct
31 Correct 56 ms 12740 KB Output is correct
32 Correct 69 ms 16580 KB Output is correct
33 Correct 66 ms 17360 KB Output is correct
34 Correct 73 ms 16324 KB Output is correct
35 Correct 70 ms 17480 KB Output is correct
36 Correct 72 ms 17600 KB Output is correct
37 Correct 71 ms 16836 KB Output is correct
38 Correct 72 ms 16836 KB Output is correct
39 Correct 68 ms 17100 KB Output is correct
40 Correct 76 ms 16336 KB Output is correct
41 Correct 72 ms 17048 KB Output is correct
42 Correct 73 ms 16836 KB Output is correct
43 Correct 76 ms 16584 KB Output is correct
44 Correct 74 ms 17096 KB Output is correct
45 Correct 77 ms 17348 KB Output is correct
46 Correct 77 ms 16580 KB Output is correct
47 Correct 77 ms 16324 KB Output is correct
48 Correct 78 ms 17860 KB Output is correct
49 Correct 86 ms 16328 KB Output is correct