답안 #965067

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
965067 2024-04-18T04:58:53 Z gaga999 Reconstruction Project (JOI22_reconstruction) C++17
100 / 100
337 ms 29112 KB
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx,avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define lowbit(x) ((x) & -(x))
#define ml(a, b) ((1ll * (a) * (b)) % M)
#define tml(a, b) (a) = ((1ll * (a) * (b)) % M)
#define ad(a, b) ((0ll + (a) + (b)) % M)
#define tad(a, b) (a) = ((0ll + (a) + (b)) % M)
#define mi(a, b) ((0ll + M + (a) - (b)) % M)
#define tmi(a, b) (a) = ((0ll + M + (a) - (b)) % M)
#define tmin(a, b) (a) = min((a), (b))
#define tmax(a, b) (a) = max((a), (b))
#define iter(a) (a).begin(), (a).end()
#define riter(a) (a).rbegin(), (a).rend()
#define init(a, b) memset((a), (b), sizeof(a))
#define cpy(a, b) memcpy((a), (b), sizeof(a))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define size(x) (int)x.size()
#define pb emplace_back
#define mpr make_pair
#define ls(i) ((i) << 1)
#define rs(i) ((i) << 1 | 1)
#define INF 0x3f3f3f3f
#define NIF 0xc0c0c0c0
#define eps 1e-9
#define F first
#define S second
#define AC cin.tie(0)->sync_with_stdio(0)
using namespace std;
typedef long long llt;
typedef __int128_t lll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<llt, llt> pll;
typedef complex<double> cd;
// const int M = 998244353;

// random_device rm;
// mt19937 rg(rm());
// default_random_engine rg(rm());
// uniform_int_distribution<int> rd(INT_MIN, INT_MAX);
// uniform_real_distribution<double> rd(0, M_PI);

void db() { cerr << "\n"; }
template <class T, class... U>
void db(T a, U... b) { cerr << a << " ", db(b...); }

inline char gc()
{
    const static int SZ = 1 << 16;
    static char buf[SZ], *p1, *p2;
    if (p1 == p2 && (p2 = buf + fread(p1 = buf, 1, SZ, stdin), p1 == p2))
        return -1;
    return *p1++;
}
void rd() {}
template <typename T, typename... U>
void rd(T &x, U &...y)
{
    x = 0;
    bool f = 0;
    char c = gc();
    while (!isdigit(c))
        f ^= !(c ^ 45), c = gc();
    while (isdigit(c))
        x = (x << 1) + (x << 3) + (c ^ 48), c = gc();
    f && (x = -x), rd(y...);
}

template <typename T>
void prt(T x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        prt(x / 10);
    putchar((x % 10) ^ 48);
}

const int N = 505, M = 1e5 + 5;
struct E
{
    int a, b, w;
    bool operator<(const E &rh) const { return w < rh.w; }
    inline void ini() { rd(a, b, w); }
} eg[M];
vector<pii> e[N];
vector<E> qy;
int ln;

int dfs(int u, int t, int fa)
{
    for (pii v : e[u])
    {
        if (v.F == fa)
            continue;
        if (v.F == t)
            return v.S;
        if (int tp = dfs(v.F, t, u))
            return eg[tp].w < eg[v.S].w ? tp : v.S;
    }
    return 0;
}

signed main()
{
    int n, m, q, x;
    rd(n, m);
    for (int i = 1; i <= m; i++)
        eg[i].ini();
    sort(eg + 1, eg + m + 1);
    for (int i = 1; i <= m; i++)
    {
        if (int tp = dfs(eg[i].a, eg[i].b, -1))
        {
            e[eg[tp].a].erase(find(iter(e[eg[tp].a]), pii(eg[tp].b, tp)));
            e[eg[tp].b].erase(find(iter(e[eg[tp].b]), pii(eg[tp].a, tp)));
            qy.pb(E{-2, eg[i].w + eg[tp].w, (eg[i].w + eg[tp].w + 1) >> 1});
        }
        else
            qy.pb(E{-1, eg[i].w, -INF});
        qy.pb(E{2, -(eg[i].w << 1), eg[i].w});
        e[eg[i].a].pb(eg[i].b, i);
        e[eg[i].b].pb(eg[i].a, i);
    }
    sort(iter(qy));
    rd(q);
    llt sum = 0, num = 0;
    while (q--)
    {
        rd(x);
        while (ln < size(qy) && qy[ln].w <= x)
            num += qy[ln].a, sum += qy[ln].b, ln++;
        prt(sum + x * num), putchar('\n');
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 255 ms 7340 KB Output is correct
21 Correct 139 ms 6592 KB Output is correct
22 Correct 197 ms 6424 KB Output is correct
23 Correct 206 ms 6624 KB Output is correct
24 Correct 207 ms 7884 KB Output is correct
25 Correct 253 ms 6608 KB Output is correct
26 Correct 242 ms 6476 KB Output is correct
27 Correct 249 ms 7256 KB Output is correct
28 Correct 252 ms 7184 KB Output is correct
29 Correct 215 ms 8000 KB Output is correct
30 Correct 247 ms 6600 KB Output is correct
31 Correct 259 ms 6460 KB Output is correct
32 Correct 256 ms 6504 KB Output is correct
33 Correct 254 ms 7628 KB Output is correct
34 Correct 219 ms 7412 KB Output is correct
35 Correct 243 ms 6628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 203 ms 26496 KB Output is correct
5 Correct 189 ms 27020 KB Output is correct
6 Correct 197 ms 26484 KB Output is correct
7 Correct 113 ms 28832 KB Output is correct
8 Correct 109 ms 28424 KB Output is correct
9 Correct 112 ms 28772 KB Output is correct
10 Correct 197 ms 26664 KB Output is correct
11 Correct 123 ms 29112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 86 ms 22352 KB Output is correct
21 Correct 87 ms 22620 KB Output is correct
22 Correct 78 ms 22396 KB Output is correct
23 Correct 82 ms 22424 KB Output is correct
24 Correct 78 ms 22352 KB Output is correct
25 Correct 84 ms 22520 KB Output is correct
26 Correct 90 ms 22676 KB Output is correct
27 Correct 82 ms 22584 KB Output is correct
28 Correct 77 ms 22352 KB Output is correct
29 Correct 85 ms 22440 KB Output is correct
30 Correct 90 ms 22572 KB Output is correct
31 Correct 86 ms 22380 KB Output is correct
32 Correct 83 ms 23068 KB Output is correct
33 Correct 86 ms 22360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 255 ms 7340 KB Output is correct
21 Correct 139 ms 6592 KB Output is correct
22 Correct 197 ms 6424 KB Output is correct
23 Correct 206 ms 6624 KB Output is correct
24 Correct 207 ms 7884 KB Output is correct
25 Correct 253 ms 6608 KB Output is correct
26 Correct 242 ms 6476 KB Output is correct
27 Correct 249 ms 7256 KB Output is correct
28 Correct 252 ms 7184 KB Output is correct
29 Correct 215 ms 8000 KB Output is correct
30 Correct 247 ms 6600 KB Output is correct
31 Correct 259 ms 6460 KB Output is correct
32 Correct 256 ms 6504 KB Output is correct
33 Correct 254 ms 7628 KB Output is correct
34 Correct 219 ms 7412 KB Output is correct
35 Correct 243 ms 6628 KB Output is correct
36 Correct 255 ms 6720 KB Output is correct
37 Correct 129 ms 7260 KB Output is correct
38 Correct 212 ms 7756 KB Output is correct
39 Correct 218 ms 6672 KB Output is correct
40 Correct 200 ms 7660 KB Output is correct
41 Correct 236 ms 6772 KB Output is correct
42 Correct 253 ms 8000 KB Output is correct
43 Correct 248 ms 6788 KB Output is correct
44 Correct 254 ms 6832 KB Output is correct
45 Correct 204 ms 7908 KB Output is correct
46 Correct 259 ms 7384 KB Output is correct
47 Correct 251 ms 7428 KB Output is correct
48 Correct 252 ms 6664 KB Output is correct
49 Correct 259 ms 7608 KB Output is correct
50 Correct 193 ms 7712 KB Output is correct
51 Correct 251 ms 6760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 255 ms 7340 KB Output is correct
21 Correct 139 ms 6592 KB Output is correct
22 Correct 197 ms 6424 KB Output is correct
23 Correct 206 ms 6624 KB Output is correct
24 Correct 207 ms 7884 KB Output is correct
25 Correct 253 ms 6608 KB Output is correct
26 Correct 242 ms 6476 KB Output is correct
27 Correct 249 ms 7256 KB Output is correct
28 Correct 252 ms 7184 KB Output is correct
29 Correct 215 ms 8000 KB Output is correct
30 Correct 247 ms 6600 KB Output is correct
31 Correct 259 ms 6460 KB Output is correct
32 Correct 256 ms 6504 KB Output is correct
33 Correct 254 ms 7628 KB Output is correct
34 Correct 219 ms 7412 KB Output is correct
35 Correct 243 ms 6628 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 203 ms 26496 KB Output is correct
40 Correct 189 ms 27020 KB Output is correct
41 Correct 197 ms 26484 KB Output is correct
42 Correct 113 ms 28832 KB Output is correct
43 Correct 109 ms 28424 KB Output is correct
44 Correct 112 ms 28772 KB Output is correct
45 Correct 197 ms 26664 KB Output is correct
46 Correct 123 ms 29112 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 86 ms 22352 KB Output is correct
49 Correct 87 ms 22620 KB Output is correct
50 Correct 78 ms 22396 KB Output is correct
51 Correct 82 ms 22424 KB Output is correct
52 Correct 78 ms 22352 KB Output is correct
53 Correct 84 ms 22520 KB Output is correct
54 Correct 90 ms 22676 KB Output is correct
55 Correct 82 ms 22584 KB Output is correct
56 Correct 77 ms 22352 KB Output is correct
57 Correct 85 ms 22440 KB Output is correct
58 Correct 90 ms 22572 KB Output is correct
59 Correct 86 ms 22380 KB Output is correct
60 Correct 83 ms 23068 KB Output is correct
61 Correct 86 ms 22360 KB Output is correct
62 Correct 255 ms 6720 KB Output is correct
63 Correct 129 ms 7260 KB Output is correct
64 Correct 212 ms 7756 KB Output is correct
65 Correct 218 ms 6672 KB Output is correct
66 Correct 200 ms 7660 KB Output is correct
67 Correct 236 ms 6772 KB Output is correct
68 Correct 253 ms 8000 KB Output is correct
69 Correct 248 ms 6788 KB Output is correct
70 Correct 254 ms 6832 KB Output is correct
71 Correct 204 ms 7908 KB Output is correct
72 Correct 259 ms 7384 KB Output is correct
73 Correct 251 ms 7428 KB Output is correct
74 Correct 252 ms 6664 KB Output is correct
75 Correct 259 ms 7608 KB Output is correct
76 Correct 193 ms 7712 KB Output is correct
77 Correct 251 ms 6760 KB Output is correct
78 Correct 323 ms 25580 KB Output is correct
79 Correct 213 ms 27648 KB Output is correct
80 Correct 283 ms 27052 KB Output is correct
81 Correct 292 ms 26740 KB Output is correct
82 Correct 294 ms 25836 KB Output is correct
83 Correct 301 ms 25600 KB Output is correct
84 Correct 310 ms 26200 KB Output is correct
85 Correct 321 ms 25580 KB Output is correct
86 Correct 303 ms 25552 KB Output is correct
87 Correct 290 ms 27840 KB Output is correct
88 Correct 324 ms 25392 KB Output is correct
89 Correct 312 ms 26072 KB Output is correct
90 Correct 321 ms 25568 KB Output is correct
91 Correct 320 ms 25508 KB Output is correct
92 Correct 282 ms 29052 KB Output is correct
93 Correct 337 ms 27012 KB Output is correct