Submission #956700

# Submission time Handle Problem Language Result Execution time Memory
956700 2024-04-02T11:04:04 Z andrei_boaca Constellation 3 (JOI20_constellation3) C++17
100 / 100
585 ms 96632 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll n,A[300005],m,total;
ll up[300005],down[300005];
vector<ll> who[300005];
vector<ll> add[300005];
ll in[300005],out[300005],timp,dp[300005];
struct star
{
    ll x,y,c;
} v[300005];
struct event
{
    ll tip,poz; /// 0 -> zid, 1 -> stea
};
vector<event> ev[300005];
set<pair<pll,ll>> setik;
ll par[300005];
vector<ll> muchii[300005];
bool comp(event a, event b)
{
    return a.tip<b.tip;
}
int nrnodes;
void build(int nod)
{
    timp++;
    in[nod]=timp;
    for(int i:muchii[nod])
        if(i!=par[nod])
        {
            par[i]=nod;
            build(i);
        }
    out[nod]=timp;
}
ll aib[300005];
ll lsb(ll x)
{
    return x&(-x);
}
void update(ll poz,ll val)
{
    for(int i=poz;i<=nrnodes;i+=lsb(i))
        aib[i]+=val;
}
ll suma(ll poz)
{
    ll rez=0;
    for(int i=poz;i>=1;i-=lsb(i))
        rez+=aib[i];
    return rez;
}
void intervupd(ll l,ll r,ll val)
{
    update(l,val);
    update(r+1,-val);
}
void dfs(int nod)
{
    ll sum=0;
    for(ll i:muchii[nod])
    {
        dfs(i);
        sum+=dp[i];
    }
    intervupd(in[nod],in[nod],sum);
    for(ll i:muchii[nod])
    {
        sum-=dp[i];
        intervupd(in[i],out[i],sum);
        sum+=dp[i];
    }
    dp[nod]=sum;
    for(ll ind:add[nod])
    {
        ll val=suma(in[down[ind]])+v[ind].c;
        dp[nod]=max(dp[nod],val);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>A[i];
        ev[A[i]].push_back({0,i});
    }
    cin>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>v[i].x>>v[i].y>>v[i].c;
        total+=v[i].c;
        ev[v[i].y].push_back({1,i});
        who[v[i].x].push_back(i);
    }
    setik.insert({{1,n},1});
    nrnodes=1;
    for(int lin=n;lin>=1;lin--)
    {
        sort(ev[lin].begin(),ev[lin].end(),comp);
        for(event p:ev[lin])
        {
            int tip=p.tip;
            if(tip==0)
            {
                int poz=p.poz;
                auto it=prev(setik.lower_bound({{poz+1,0},0}));
                int l=(*it).first.first;
                int r=(*it).first.second;
                int nod=(*it).second;
                for(int i:who[poz])
                    down[i]=nod;
                setik.erase(it);
                int l1=l,r1=poz-1;
                int l2=poz+1,r2=r;
                if(l1<=r1)
                {
                    nrnodes++;
                    setik.insert({{l1,r1},nrnodes});
                    muchii[nod].push_back(nrnodes);
                    par[nrnodes]=nod;
                }
                if(l2<=r2)
                {
                    nrnodes++;
                    setik.insert({{l2,r2},nrnodes});
                    muchii[nod].push_back(nrnodes);
                    par[nrnodes]=nod;
                }
            }
            else
            {
                int ind=p.poz;
                auto it=prev(setik.lower_bound({{v[ind].x+1,0},0}));
                int nod=(*it).second;
                up[ind]=nod;
                add[nod].push_back(ind);
            }
        }
    }
    build(1);
    dfs(1);
    cout<<total-dp[1];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 43504 KB Output is correct
2 Correct 11 ms 43356 KB Output is correct
3 Correct 10 ms 43612 KB Output is correct
4 Correct 10 ms 43356 KB Output is correct
5 Correct 11 ms 43356 KB Output is correct
6 Correct 9 ms 43612 KB Output is correct
7 Correct 9 ms 43356 KB Output is correct
8 Correct 9 ms 43356 KB Output is correct
9 Correct 9 ms 43356 KB Output is correct
10 Correct 9 ms 43448 KB Output is correct
11 Correct 10 ms 43612 KB Output is correct
12 Correct 10 ms 43544 KB Output is correct
13 Correct 9 ms 43612 KB Output is correct
14 Correct 9 ms 43352 KB Output is correct
15 Correct 9 ms 43612 KB Output is correct
16 Correct 9 ms 43540 KB Output is correct
17 Correct 9 ms 43612 KB Output is correct
18 Correct 9 ms 43608 KB Output is correct
19 Correct 9 ms 43356 KB Output is correct
20 Correct 9 ms 43612 KB Output is correct
21 Correct 9 ms 43608 KB Output is correct
22 Correct 9 ms 43356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 43504 KB Output is correct
2 Correct 11 ms 43356 KB Output is correct
3 Correct 10 ms 43612 KB Output is correct
4 Correct 10 ms 43356 KB Output is correct
5 Correct 11 ms 43356 KB Output is correct
6 Correct 9 ms 43612 KB Output is correct
7 Correct 9 ms 43356 KB Output is correct
8 Correct 9 ms 43356 KB Output is correct
9 Correct 9 ms 43356 KB Output is correct
10 Correct 9 ms 43448 KB Output is correct
11 Correct 10 ms 43612 KB Output is correct
12 Correct 10 ms 43544 KB Output is correct
13 Correct 9 ms 43612 KB Output is correct
14 Correct 9 ms 43352 KB Output is correct
15 Correct 9 ms 43612 KB Output is correct
16 Correct 9 ms 43540 KB Output is correct
17 Correct 9 ms 43612 KB Output is correct
18 Correct 9 ms 43608 KB Output is correct
19 Correct 9 ms 43356 KB Output is correct
20 Correct 9 ms 43612 KB Output is correct
21 Correct 9 ms 43608 KB Output is correct
22 Correct 9 ms 43356 KB Output is correct
23 Correct 11 ms 43808 KB Output is correct
24 Correct 11 ms 43868 KB Output is correct
25 Correct 12 ms 43864 KB Output is correct
26 Correct 11 ms 43928 KB Output is correct
27 Correct 10 ms 43868 KB Output is correct
28 Correct 10 ms 43868 KB Output is correct
29 Correct 10 ms 43736 KB Output is correct
30 Correct 11 ms 43868 KB Output is correct
31 Correct 10 ms 43868 KB Output is correct
32 Correct 10 ms 43868 KB Output is correct
33 Correct 10 ms 43864 KB Output is correct
34 Correct 10 ms 43868 KB Output is correct
35 Correct 10 ms 44168 KB Output is correct
36 Correct 10 ms 43868 KB Output is correct
37 Correct 11 ms 43756 KB Output is correct
38 Correct 10 ms 43992 KB Output is correct
39 Correct 10 ms 43612 KB Output is correct
40 Correct 9 ms 43744 KB Output is correct
41 Correct 11 ms 43612 KB Output is correct
42 Correct 10 ms 43744 KB Output is correct
43 Correct 10 ms 43728 KB Output is correct
44 Correct 10 ms 43612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 43504 KB Output is correct
2 Correct 11 ms 43356 KB Output is correct
3 Correct 10 ms 43612 KB Output is correct
4 Correct 10 ms 43356 KB Output is correct
5 Correct 11 ms 43356 KB Output is correct
6 Correct 9 ms 43612 KB Output is correct
7 Correct 9 ms 43356 KB Output is correct
8 Correct 9 ms 43356 KB Output is correct
9 Correct 9 ms 43356 KB Output is correct
10 Correct 9 ms 43448 KB Output is correct
11 Correct 10 ms 43612 KB Output is correct
12 Correct 10 ms 43544 KB Output is correct
13 Correct 9 ms 43612 KB Output is correct
14 Correct 9 ms 43352 KB Output is correct
15 Correct 9 ms 43612 KB Output is correct
16 Correct 9 ms 43540 KB Output is correct
17 Correct 9 ms 43612 KB Output is correct
18 Correct 9 ms 43608 KB Output is correct
19 Correct 9 ms 43356 KB Output is correct
20 Correct 9 ms 43612 KB Output is correct
21 Correct 9 ms 43608 KB Output is correct
22 Correct 9 ms 43356 KB Output is correct
23 Correct 11 ms 43808 KB Output is correct
24 Correct 11 ms 43868 KB Output is correct
25 Correct 12 ms 43864 KB Output is correct
26 Correct 11 ms 43928 KB Output is correct
27 Correct 10 ms 43868 KB Output is correct
28 Correct 10 ms 43868 KB Output is correct
29 Correct 10 ms 43736 KB Output is correct
30 Correct 11 ms 43868 KB Output is correct
31 Correct 10 ms 43868 KB Output is correct
32 Correct 10 ms 43868 KB Output is correct
33 Correct 10 ms 43864 KB Output is correct
34 Correct 10 ms 43868 KB Output is correct
35 Correct 10 ms 44168 KB Output is correct
36 Correct 10 ms 43868 KB Output is correct
37 Correct 11 ms 43756 KB Output is correct
38 Correct 10 ms 43992 KB Output is correct
39 Correct 10 ms 43612 KB Output is correct
40 Correct 9 ms 43744 KB Output is correct
41 Correct 11 ms 43612 KB Output is correct
42 Correct 10 ms 43744 KB Output is correct
43 Correct 10 ms 43728 KB Output is correct
44 Correct 10 ms 43612 KB Output is correct
45 Correct 507 ms 82604 KB Output is correct
46 Correct 518 ms 82344 KB Output is correct
47 Correct 581 ms 82512 KB Output is correct
48 Correct 514 ms 82260 KB Output is correct
49 Correct 494 ms 81784 KB Output is correct
50 Correct 486 ms 81748 KB Output is correct
51 Correct 492 ms 81872 KB Output is correct
52 Correct 510 ms 82812 KB Output is correct
53 Correct 585 ms 82256 KB Output is correct
54 Correct 247 ms 90772 KB Output is correct
55 Correct 292 ms 87540 KB Output is correct
56 Correct 250 ms 85628 KB Output is correct
57 Correct 252 ms 84568 KB Output is correct
58 Correct 215 ms 80384 KB Output is correct
59 Correct 224 ms 80444 KB Output is correct
60 Correct 138 ms 96632 KB Output is correct
61 Correct 239 ms 76424 KB Output is correct
62 Correct 255 ms 92916 KB Output is correct
63 Correct 284 ms 76132 KB Output is correct
64 Correct 259 ms 75644 KB Output is correct
65 Correct 295 ms 92756 KB Output is correct
66 Correct 244 ms 76368 KB Output is correct