답안 #1105454

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105454 2024-10-26T12:53:48 Z jerzyk 나일강 (IOI24_nile) C++17
100 / 100
74 ms 11596 KB
#include <bits/stdc++.h>
#include "nile.h"

using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const int II = 2 * 1000 * 1000 * 1000;
const ll M = 1000LL * 1000LL * 1000LL + 7LL;
const int N = 1<<17;

int fau[N], mi[N][2], l[N], r[N];
int cst[N]; ll cans = 0LL;

pair<int, int> joi[N];
pair<int, int> upd[N];

pair<int, int> tab[N];

pair<int, int> que[N];
vector<ll> answer;

int Find(int v)
{
    if(fau[v] == v) return v;
    return (fau[v] = Find(fau[v]));
}

inline void Calc(int a)
{
    cst[a] = 0;
    if(l[a] % 2 == r[a] % 2)
        cst[a] += mi[a][l[a] % 2];
}

void Union(int a, int b)
{
    a = Find(a); b = Find(b);
    cans -= (ll)(cst[a] + cst[b]);
    fau[b] = a;
    mi[a][0] = min(mi[a][0], mi[b][0]);
    mi[a][1] = min(mi[a][1], mi[b][1]);
    r[a] = r[b];
    Calc(a);
    cans += (ll)cst[a];
}

void Upd(int v)
{
    int x = tab[v].nd;
    v = Find(v);
    mi[v][0] = min(mi[v][0], x);
    mi[v][1] = min(mi[v][1], x);

    cans -= (ll)cst[v];
    Calc(v);
    cans += (ll)cst[v];
}

void Ans(int n, int q)
{
    for(int i = 1; i <= n; ++i)
    {
        mi[i][0] = II; mi[i][1] = II;
        mi[i][i % 2] = tab[i].nd;
        l[i] = i; r[i] = i; fau[i] = i;
        Calc(i);
        cans += cst[i];

        if(i < n)
            joi[i] = make_pair(tab[i + 1].st - tab[i].st, i);
        if(i > 1 && i < n)
            upd[i - 1] = make_pair(tab[i + 1].st - tab[i - 1].st, i);
    }
    //cerr << "Init: " << cans << "\n";
    if(n > 1)
        sort(joi + 1, joi + 1 + (n - 1));
    if(n > 2)
        sort(upd + 1, upd + 1 + (n - 2));
    int j1 = 0, j2 = 0;
    for(int i = 1; i <= q; ++i)
    {
        while(j1 < n - 1 && joi[j1 + 1].st <= que[i].st)
        {
            ++j1;
            Union(joi[j1].nd, joi[j1].nd + 1);
        }
        while(j2 < n - 2 && upd[j2 + 1].st <= que[i].st)
        {
            ++j2;
            Upd(upd[j2].nd);
        }
        answer[que[i].nd] += cans;
    }
}

vector<ll> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int>E)
{
    int n = W.size(), q = E.size();
    ll bans = 0LL;
    for(int i = 1; i <= n; ++i)
    {
        tab[i] = make_pair(W[i - 1], (ll)(A[i - 1] - B[i - 1]));
        bans += B[i - 1];
    }
    for(int i = 0; i < q; ++i)
    {answer.pb(bans); que[i + 1] = make_pair(E[i], i);}
    sort(tab + 1, tab + 1 + n);
    sort(que + 1, que + 1 + q);
    Ans(n, q);

    return answer;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 2 ms 4600 KB Output is correct
3 Correct 2 ms 4432 KB Output is correct
4 Correct 2 ms 4432 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 2 ms 4600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 8780 KB Output is correct
2 Correct 29 ms 8772 KB Output is correct
3 Correct 28 ms 8784 KB Output is correct
4 Correct 28 ms 8796 KB Output is correct
5 Correct 30 ms 8784 KB Output is correct
6 Correct 33 ms 8784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 8784 KB Output is correct
2 Correct 32 ms 9032 KB Output is correct
3 Correct 43 ms 8784 KB Output is correct
4 Correct 42 ms 8784 KB Output is correct
5 Correct 41 ms 8784 KB Output is correct
6 Correct 47 ms 8784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 2 ms 4600 KB Output is correct
3 Correct 2 ms 4432 KB Output is correct
4 Correct 2 ms 4432 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 2 ms 4600 KB Output is correct
7 Correct 2 ms 4432 KB Output is correct
8 Correct 2 ms 4432 KB Output is correct
9 Correct 2 ms 4432 KB Output is correct
10 Correct 2 ms 4432 KB Output is correct
11 Correct 2 ms 4432 KB Output is correct
12 Correct 2 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 2 ms 4600 KB Output is correct
3 Correct 2 ms 4432 KB Output is correct
4 Correct 2 ms 4432 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 2 ms 4600 KB Output is correct
7 Correct 29 ms 8780 KB Output is correct
8 Correct 29 ms 8772 KB Output is correct
9 Correct 28 ms 8784 KB Output is correct
10 Correct 28 ms 8796 KB Output is correct
11 Correct 30 ms 8784 KB Output is correct
12 Correct 33 ms 8784 KB Output is correct
13 Correct 31 ms 8784 KB Output is correct
14 Correct 32 ms 9032 KB Output is correct
15 Correct 43 ms 8784 KB Output is correct
16 Correct 42 ms 8784 KB Output is correct
17 Correct 41 ms 8784 KB Output is correct
18 Correct 47 ms 8784 KB Output is correct
19 Correct 2 ms 4432 KB Output is correct
20 Correct 2 ms 4432 KB Output is correct
21 Correct 2 ms 4432 KB Output is correct
22 Correct 2 ms 4432 KB Output is correct
23 Correct 2 ms 4432 KB Output is correct
24 Correct 2 ms 4432 KB Output is correct
25 Correct 34 ms 8784 KB Output is correct
26 Correct 38 ms 9200 KB Output is correct
27 Correct 48 ms 8944 KB Output is correct
28 Correct 48 ms 8776 KB Output is correct
29 Correct 46 ms 8784 KB Output is correct
30 Correct 57 ms 8776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 8784 KB Output is correct
2 Correct 32 ms 9032 KB Output is correct
3 Correct 43 ms 8784 KB Output is correct
4 Correct 42 ms 8784 KB Output is correct
5 Correct 41 ms 8784 KB Output is correct
6 Correct 47 ms 8784 KB Output is correct
7 Correct 55 ms 11448 KB Output is correct
8 Correct 53 ms 11452 KB Output is correct
9 Correct 64 ms 11480 KB Output is correct
10 Correct 72 ms 11596 KB Output is correct
11 Correct 67 ms 11452 KB Output is correct
12 Correct 72 ms 11452 KB Output is correct
13 Correct 64 ms 11452 KB Output is correct
14 Correct 59 ms 11452 KB Output is correct
15 Correct 66 ms 11452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 2 ms 4600 KB Output is correct
4 Correct 2 ms 4432 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 2 ms 4432 KB Output is correct
7 Correct 2 ms 4600 KB Output is correct
8 Correct 29 ms 8780 KB Output is correct
9 Correct 29 ms 8772 KB Output is correct
10 Correct 28 ms 8784 KB Output is correct
11 Correct 28 ms 8796 KB Output is correct
12 Correct 30 ms 8784 KB Output is correct
13 Correct 33 ms 8784 KB Output is correct
14 Correct 31 ms 8784 KB Output is correct
15 Correct 32 ms 9032 KB Output is correct
16 Correct 43 ms 8784 KB Output is correct
17 Correct 42 ms 8784 KB Output is correct
18 Correct 41 ms 8784 KB Output is correct
19 Correct 47 ms 8784 KB Output is correct
20 Correct 2 ms 4432 KB Output is correct
21 Correct 2 ms 4432 KB Output is correct
22 Correct 2 ms 4432 KB Output is correct
23 Correct 2 ms 4432 KB Output is correct
24 Correct 2 ms 4432 KB Output is correct
25 Correct 2 ms 4432 KB Output is correct
26 Correct 34 ms 8784 KB Output is correct
27 Correct 38 ms 9200 KB Output is correct
28 Correct 48 ms 8944 KB Output is correct
29 Correct 48 ms 8776 KB Output is correct
30 Correct 46 ms 8784 KB Output is correct
31 Correct 57 ms 8776 KB Output is correct
32 Correct 55 ms 11448 KB Output is correct
33 Correct 53 ms 11452 KB Output is correct
34 Correct 64 ms 11480 KB Output is correct
35 Correct 72 ms 11596 KB Output is correct
36 Correct 67 ms 11452 KB Output is correct
37 Correct 72 ms 11452 KB Output is correct
38 Correct 64 ms 11452 KB Output is correct
39 Correct 59 ms 11452 KB Output is correct
40 Correct 66 ms 11452 KB Output is correct
41 Correct 56 ms 11460 KB Output is correct
42 Correct 59 ms 11452 KB Output is correct
43 Correct 70 ms 11452 KB Output is correct
44 Correct 68 ms 11452 KB Output is correct
45 Correct 68 ms 11460 KB Output is correct
46 Correct 67 ms 11520 KB Output is correct
47 Correct 69 ms 11452 KB Output is correct
48 Correct 71 ms 11452 KB Output is correct
49 Correct 74 ms 11460 KB Output is correct