Submission #918710

# Submission time Handle Problem Language Result Execution time Memory
918710 2024-01-30T09:45:54 Z Tuanlinh123 Constellation 3 (JOI20_constellation3) C++17
100 / 100
796 ms 135836 KB
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;

const ll maxn=200005;
pll sp[20][maxn];
vector <ll> A[maxn];
vector <pll> Q[maxn];
ll n, m, root, sum, dp[maxn], bit[maxn];
ll Time, tin[maxn], tout[maxn], jump[20][maxn];

pll query(ll l, ll r)
{
    ll j=__lg(r-l+1);
    return max(sp[j][l], sp[j][r-(1<<j)+1]);
}

void getedge(ll l, ll r, ll rt)
{
    if (l>r) return;
    ll p=query(l, r).se;
    if (rt) A[rt].pb(p);
    else root=p;
    getedge(l, p-1, p), getedge(p+1, r, p);
}

void dfs(ll u)
{
    tin[u]=++Time;
    for (ll i=1; i<20; i++)
        jump[i][u]=jump[i-1][jump[i-1][u]];
    for (ll v:A[u])
        jump[0][v]=u, dfs(v);
    tout[u]=Time;
}

void update(ll l, ll r, ll val)
{
    for (; l<=n; l+=l&(-l)) bit[l]+=val;
    for (++r; r<=n; r+=r&(-r)) bit[r]-=val;
}

ll query(ll i)
{
    ll ans=0;
    for (; i; i-=i&(-i)) ans+=bit[i];
    return ans;
}

void dfs2(ll u)
{
    ll s=0;
    for (ll v:A[u]) dfs2(v), s+=v, dp[u]+=dp[v];
    for (ll v:A[u]) if (v!=s)
        update(tin[v], tout[v], dp[s-v]);
    for (auto [x, c]:Q[u])
    {
        c+=query(tin[x]);
        for (ll v:A[x]) c+=dp[v];
        dp[u]=max(dp[u], c);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for (ll i=1; i<=n; i++)
        cin >> sp[0][i].fi, sp[0][i].se=i;
    for (ll i=1; i<20; i++)
        for (ll j=1; j+(1<<i)<=n+1; j++)
            sp[i][j]=max(sp[i-1][j], sp[i-1][j+(1<<i-1)]);
    getedge(1, n, 0), dfs(root); cin >> m;
    for (ll i=1; i<=m; i++)
    {
        ll x, y, c, p; cin >> x >> y >> c; p=x, sum+=c;
        for (ll j=19; j>=0; j--)
            if (jump[j][p] && sp[0][jump[j][p]].fi<y)
                p=jump[j][p];
        Q[p].pb({x, c});
    }
    dfs2(root);
    cout << sum-dp[root];
}

Compilation message

constellation3.cpp: In function 'int main()':
constellation3.cpp:79:53: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   79 |             sp[i][j]=max(sp[i-1][j], sp[i-1][j+(1<<i-1)]);
      |                                                    ~^~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 59992 KB Output is correct
2 Correct 10 ms 59996 KB Output is correct
3 Correct 10 ms 59996 KB Output is correct
4 Correct 10 ms 59996 KB Output is correct
5 Correct 10 ms 60016 KB Output is correct
6 Correct 11 ms 59828 KB Output is correct
7 Correct 11 ms 59992 KB Output is correct
8 Correct 12 ms 59996 KB Output is correct
9 Correct 11 ms 59880 KB Output is correct
10 Correct 11 ms 60028 KB Output is correct
11 Correct 10 ms 59996 KB Output is correct
12 Correct 11 ms 59996 KB Output is correct
13 Correct 11 ms 60024 KB Output is correct
14 Correct 11 ms 60248 KB Output is correct
15 Correct 11 ms 59996 KB Output is correct
16 Correct 11 ms 59996 KB Output is correct
17 Correct 11 ms 59996 KB Output is correct
18 Correct 11 ms 59992 KB Output is correct
19 Correct 10 ms 59996 KB Output is correct
20 Correct 11 ms 59996 KB Output is correct
21 Correct 11 ms 59960 KB Output is correct
22 Correct 11 ms 59996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 59992 KB Output is correct
2 Correct 10 ms 59996 KB Output is correct
3 Correct 10 ms 59996 KB Output is correct
4 Correct 10 ms 59996 KB Output is correct
5 Correct 10 ms 60016 KB Output is correct
6 Correct 11 ms 59828 KB Output is correct
7 Correct 11 ms 59992 KB Output is correct
8 Correct 12 ms 59996 KB Output is correct
9 Correct 11 ms 59880 KB Output is correct
10 Correct 11 ms 60028 KB Output is correct
11 Correct 10 ms 59996 KB Output is correct
12 Correct 11 ms 59996 KB Output is correct
13 Correct 11 ms 60024 KB Output is correct
14 Correct 11 ms 60248 KB Output is correct
15 Correct 11 ms 59996 KB Output is correct
16 Correct 11 ms 59996 KB Output is correct
17 Correct 11 ms 59996 KB Output is correct
18 Correct 11 ms 59992 KB Output is correct
19 Correct 10 ms 59996 KB Output is correct
20 Correct 11 ms 59996 KB Output is correct
21 Correct 11 ms 59960 KB Output is correct
22 Correct 11 ms 59996 KB Output is correct
23 Correct 12 ms 64092 KB Output is correct
24 Correct 12 ms 64120 KB Output is correct
25 Correct 13 ms 64092 KB Output is correct
26 Correct 12 ms 64092 KB Output is correct
27 Correct 13 ms 64192 KB Output is correct
28 Correct 12 ms 64092 KB Output is correct
29 Correct 12 ms 64092 KB Output is correct
30 Correct 12 ms 64236 KB Output is correct
31 Correct 12 ms 64088 KB Output is correct
32 Correct 12 ms 64348 KB Output is correct
33 Correct 12 ms 64544 KB Output is correct
34 Correct 12 ms 64144 KB Output is correct
35 Correct 12 ms 64248 KB Output is correct
36 Correct 12 ms 64348 KB Output is correct
37 Correct 12 ms 64228 KB Output is correct
38 Correct 12 ms 64348 KB Output is correct
39 Correct 12 ms 64280 KB Output is correct
40 Correct 13 ms 64344 KB Output is correct
41 Correct 13 ms 64092 KB Output is correct
42 Correct 12 ms 64200 KB Output is correct
43 Correct 12 ms 64348 KB Output is correct
44 Correct 12 ms 64244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 59992 KB Output is correct
2 Correct 10 ms 59996 KB Output is correct
3 Correct 10 ms 59996 KB Output is correct
4 Correct 10 ms 59996 KB Output is correct
5 Correct 10 ms 60016 KB Output is correct
6 Correct 11 ms 59828 KB Output is correct
7 Correct 11 ms 59992 KB Output is correct
8 Correct 12 ms 59996 KB Output is correct
9 Correct 11 ms 59880 KB Output is correct
10 Correct 11 ms 60028 KB Output is correct
11 Correct 10 ms 59996 KB Output is correct
12 Correct 11 ms 59996 KB Output is correct
13 Correct 11 ms 60024 KB Output is correct
14 Correct 11 ms 60248 KB Output is correct
15 Correct 11 ms 59996 KB Output is correct
16 Correct 11 ms 59996 KB Output is correct
17 Correct 11 ms 59996 KB Output is correct
18 Correct 11 ms 59992 KB Output is correct
19 Correct 10 ms 59996 KB Output is correct
20 Correct 11 ms 59996 KB Output is correct
21 Correct 11 ms 59960 KB Output is correct
22 Correct 11 ms 59996 KB Output is correct
23 Correct 12 ms 64092 KB Output is correct
24 Correct 12 ms 64120 KB Output is correct
25 Correct 13 ms 64092 KB Output is correct
26 Correct 12 ms 64092 KB Output is correct
27 Correct 13 ms 64192 KB Output is correct
28 Correct 12 ms 64092 KB Output is correct
29 Correct 12 ms 64092 KB Output is correct
30 Correct 12 ms 64236 KB Output is correct
31 Correct 12 ms 64088 KB Output is correct
32 Correct 12 ms 64348 KB Output is correct
33 Correct 12 ms 64544 KB Output is correct
34 Correct 12 ms 64144 KB Output is correct
35 Correct 12 ms 64248 KB Output is correct
36 Correct 12 ms 64348 KB Output is correct
37 Correct 12 ms 64228 KB Output is correct
38 Correct 12 ms 64348 KB Output is correct
39 Correct 12 ms 64280 KB Output is correct
40 Correct 13 ms 64344 KB Output is correct
41 Correct 13 ms 64092 KB Output is correct
42 Correct 12 ms 64200 KB Output is correct
43 Correct 12 ms 64348 KB Output is correct
44 Correct 12 ms 64244 KB Output is correct
45 Correct 365 ms 117840 KB Output is correct
46 Correct 388 ms 117584 KB Output is correct
47 Correct 359 ms 117840 KB Output is correct
48 Correct 354 ms 117432 KB Output is correct
49 Correct 338 ms 117588 KB Output is correct
50 Correct 340 ms 117316 KB Output is correct
51 Correct 394 ms 117328 KB Output is correct
52 Correct 370 ms 117868 KB Output is correct
53 Correct 431 ms 118140 KB Output is correct
54 Correct 796 ms 130380 KB Output is correct
55 Correct 681 ms 126700 KB Output is correct
56 Correct 671 ms 124368 KB Output is correct
57 Correct 636 ms 123360 KB Output is correct
58 Correct 407 ms 127592 KB Output is correct
59 Correct 322 ms 127568 KB Output is correct
60 Correct 151 ms 135836 KB Output is correct
61 Correct 338 ms 117164 KB Output is correct
62 Correct 764 ms 132708 KB Output is correct
63 Correct 331 ms 116844 KB Output is correct
64 Correct 295 ms 116948 KB Output is correct
65 Correct 624 ms 132692 KB Output is correct
66 Correct 311 ms 117072 KB Output is correct