Submission #938888

# Submission time Handle Problem Language Result Execution time Memory
938888 2024-03-05T18:46:22 Z andrei_boaca Reconstruction Project (JOI22_reconstruction) C++17
100 / 100
1767 ms 38828 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll INF=1e9;
ll n,m;
struct date
{
    ll a,b,c;
} v[100005];
struct ev
{
    ll poz,c1,c0;
};
vector<ev> events;
bool comp(date a, date b)
{
    return a.c<b.c;
}
bool bypoz(ev a, ev b)
{
    return a.poz<b.poz;
}
ll par[505],sz[505];
ll getpar(ll a)
{
    if(a==par[a])
        return a;
    par[a]=getpar(par[a]);
    return par[a];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        ll a,b,c;
        cin>>a>>b>>c;
        v[i]={a,b,c};
    }
    sort(v+1,v+m+1,comp);
    for(int i=1;i<=m;i++)
    {
        bool ok=0;
        if(i==3)
            ok=1;
        for(int j=1;j<=n;j++)
        {
            par[j]=j;
            sz[j]=1;
        }
        int nrcomp=n;
        int j=i-1;
        while(j>0)
        {
            int a=getpar(v[j].a);
            int b=getpar(v[j].b);
            if(a!=b)
            {
                if(sz[a]<sz[b])
                    swap(a,b);
                par[a]=b;
                sz[a]+=sz[b];
                nrcomp--;
                if(getpar(v[i].a)==getpar(v[i].b))
                    break;
            }
            j--;
        }
        if(j==0)
        {
            events.push_back({1,-1,v[i].c});
            events.push_back({v[i].c+1,1,-v[i].c});
        }
        else
        {
            ll poz=(v[i].c+v[j].c)/2;
            while(poz-v[j].c<=v[i].c-poz)
                poz++;
            events.push_back({poz,-1,v[i].c});
            events.push_back({v[i].c+1,1,-v[i].c});
        }
    }
    for(int i=m;i>=1;i--)
    {
        for(int j=1;j<=n;j++)
        {
            par[j]=j;
            sz[j]=1;
        }
        int nrcomp=n;
        int j=i+1;
        while(j<=m)
        {
            int a=getpar(v[j].a);
            int b=getpar(v[j].b);
            if(a!=b)
            {
                if(sz[a]<sz[b])
                    swap(a,b);
                par[a]=b;
                sz[a]+=sz[b];
                nrcomp--;
                if(getpar(v[i].a)==getpar(v[i].b))
                    break;
            }
            j++;
        }
        if(j==m+1)
        {
            events.push_back({v[i].c+1,1,-v[i].c});
            events.push_back({INF+1,-1,v[i].c});
        }
        else
        {
            ll poz=(v[i].c+v[j].c)/2;
            while(poz-v[i].c>v[j].c-poz)
                poz--;
            events.push_back({v[i].c+1,1,-v[i].c});
            events.push_back({poz+1,-1,v[i].c});
        }
    }
    sort(events.begin(),events.end(),bypoz);
    reverse(events.begin(),events.end());
    ll c0=0,c1=0;
    ll q;
    cin>>q;
    while(q--)
    {
        ll x;
        cin>>x;
        while(!events.empty()&&events.back().poz<=x)
        {
            c0+=events.back().c0;
            c1+=events.back().c1;
            events.pop_back();
        }
        ll ans=c1*x+c0;
        cout<<ans<<'\n';
    }
    return 0;
}

Compilation message

reconstruction.cpp: In function 'int main()':
reconstruction.cpp:46:14: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
   46 |         bool ok=0;
      |              ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 392 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 464 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 464 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 392 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 464 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 464 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1534 ms 17080 KB Output is correct
21 Correct 802 ms 18872 KB Output is correct
22 Correct 863 ms 18668 KB Output is correct
23 Correct 1049 ms 18068 KB Output is correct
24 Correct 1323 ms 16908 KB Output is correct
25 Correct 1596 ms 18124 KB Output is correct
26 Correct 1546 ms 19124 KB Output is correct
27 Correct 1557 ms 18336 KB Output is correct
28 Correct 1532 ms 17352 KB Output is correct
29 Correct 1499 ms 18872 KB Output is correct
30 Correct 1542 ms 17724 KB Output is correct
31 Correct 1541 ms 17808 KB Output is correct
32 Correct 1534 ms 17336 KB Output is correct
33 Correct 1559 ms 18096 KB Output is correct
34 Correct 1498 ms 17336 KB Output is correct
35 Correct 1546 ms 17332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 924 ms 34752 KB Output is correct
5 Correct 934 ms 35240 KB Output is correct
6 Correct 933 ms 36088 KB Output is correct
7 Correct 607 ms 37436 KB Output is correct
8 Correct 526 ms 37552 KB Output is correct
9 Correct 423 ms 38320 KB Output is correct
10 Correct 933 ms 34948 KB Output is correct
11 Correct 528 ms 38828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 392 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 464 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 464 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 161 ms 22520 KB Output is correct
21 Correct 153 ms 22732 KB Output is correct
22 Correct 158 ms 22612 KB Output is correct
23 Correct 177 ms 22504 KB Output is correct
24 Correct 164 ms 22608 KB Output is correct
25 Correct 157 ms 22608 KB Output is correct
26 Correct 160 ms 22424 KB Output is correct
27 Correct 172 ms 22576 KB Output is correct
28 Correct 158 ms 22624 KB Output is correct
29 Correct 160 ms 22628 KB Output is correct
30 Correct 159 ms 22704 KB Output is correct
31 Correct 157 ms 22356 KB Output is correct
32 Correct 159 ms 23164 KB Output is correct
33 Correct 162 ms 22352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 392 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 464 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 464 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1534 ms 17080 KB Output is correct
21 Correct 802 ms 18872 KB Output is correct
22 Correct 863 ms 18668 KB Output is correct
23 Correct 1049 ms 18068 KB Output is correct
24 Correct 1323 ms 16908 KB Output is correct
25 Correct 1596 ms 18124 KB Output is correct
26 Correct 1546 ms 19124 KB Output is correct
27 Correct 1557 ms 18336 KB Output is correct
28 Correct 1532 ms 17352 KB Output is correct
29 Correct 1499 ms 18872 KB Output is correct
30 Correct 1542 ms 17724 KB Output is correct
31 Correct 1541 ms 17808 KB Output is correct
32 Correct 1534 ms 17336 KB Output is correct
33 Correct 1559 ms 18096 KB Output is correct
34 Correct 1498 ms 17336 KB Output is correct
35 Correct 1546 ms 17332 KB Output is correct
36 Correct 1553 ms 18112 KB Output is correct
37 Correct 798 ms 19240 KB Output is correct
38 Correct 878 ms 18284 KB Output is correct
39 Correct 1061 ms 17144 KB Output is correct
40 Correct 1323 ms 17600 KB Output is correct
41 Correct 1639 ms 18544 KB Output is correct
42 Correct 1549 ms 18960 KB Output is correct
43 Correct 1544 ms 17672 KB Output is correct
44 Correct 1518 ms 17560 KB Output is correct
45 Correct 1529 ms 17652 KB Output is correct
46 Correct 1536 ms 18356 KB Output is correct
47 Correct 1554 ms 17696 KB Output is correct
48 Correct 1568 ms 18292 KB Output is correct
49 Correct 1527 ms 17156 KB Output is correct
50 Correct 1521 ms 18200 KB Output is correct
51 Correct 1546 ms 17844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 392 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 464 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 464 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1534 ms 17080 KB Output is correct
21 Correct 802 ms 18872 KB Output is correct
22 Correct 863 ms 18668 KB Output is correct
23 Correct 1049 ms 18068 KB Output is correct
24 Correct 1323 ms 16908 KB Output is correct
25 Correct 1596 ms 18124 KB Output is correct
26 Correct 1546 ms 19124 KB Output is correct
27 Correct 1557 ms 18336 KB Output is correct
28 Correct 1532 ms 17352 KB Output is correct
29 Correct 1499 ms 18872 KB Output is correct
30 Correct 1542 ms 17724 KB Output is correct
31 Correct 1541 ms 17808 KB Output is correct
32 Correct 1534 ms 17336 KB Output is correct
33 Correct 1559 ms 18096 KB Output is correct
34 Correct 1498 ms 17336 KB Output is correct
35 Correct 1546 ms 17332 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 348 KB Output is correct
39 Correct 924 ms 34752 KB Output is correct
40 Correct 934 ms 35240 KB Output is correct
41 Correct 933 ms 36088 KB Output is correct
42 Correct 607 ms 37436 KB Output is correct
43 Correct 526 ms 37552 KB Output is correct
44 Correct 423 ms 38320 KB Output is correct
45 Correct 933 ms 34948 KB Output is correct
46 Correct 528 ms 38828 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 161 ms 22520 KB Output is correct
49 Correct 153 ms 22732 KB Output is correct
50 Correct 158 ms 22612 KB Output is correct
51 Correct 177 ms 22504 KB Output is correct
52 Correct 164 ms 22608 KB Output is correct
53 Correct 157 ms 22608 KB Output is correct
54 Correct 160 ms 22424 KB Output is correct
55 Correct 172 ms 22576 KB Output is correct
56 Correct 158 ms 22624 KB Output is correct
57 Correct 160 ms 22628 KB Output is correct
58 Correct 159 ms 22704 KB Output is correct
59 Correct 157 ms 22356 KB Output is correct
60 Correct 159 ms 23164 KB Output is correct
61 Correct 162 ms 22352 KB Output is correct
62 Correct 1553 ms 18112 KB Output is correct
63 Correct 798 ms 19240 KB Output is correct
64 Correct 878 ms 18284 KB Output is correct
65 Correct 1061 ms 17144 KB Output is correct
66 Correct 1323 ms 17600 KB Output is correct
67 Correct 1639 ms 18544 KB Output is correct
68 Correct 1549 ms 18960 KB Output is correct
69 Correct 1544 ms 17672 KB Output is correct
70 Correct 1518 ms 17560 KB Output is correct
71 Correct 1529 ms 17652 KB Output is correct
72 Correct 1536 ms 18356 KB Output is correct
73 Correct 1554 ms 17696 KB Output is correct
74 Correct 1568 ms 18292 KB Output is correct
75 Correct 1527 ms 17156 KB Output is correct
76 Correct 1521 ms 18200 KB Output is correct
77 Correct 1546 ms 17844 KB Output is correct
78 Correct 1681 ms 34632 KB Output is correct
79 Correct 946 ms 37544 KB Output is correct
80 Correct 1010 ms 34816 KB Output is correct
81 Correct 1197 ms 36120 KB Output is correct
82 Correct 1479 ms 34656 KB Output is correct
83 Correct 1767 ms 34668 KB Output is correct
84 Correct 1683 ms 34824 KB Output is correct
85 Correct 1679 ms 35696 KB Output is correct
86 Correct 1671 ms 35288 KB Output is correct
87 Correct 1648 ms 36400 KB Output is correct
88 Correct 1671 ms 35156 KB Output is correct
89 Correct 1680 ms 34012 KB Output is correct
90 Correct 1680 ms 34640 KB Output is correct
91 Correct 1677 ms 34772 KB Output is correct
92 Correct 1654 ms 36676 KB Output is correct
93 Correct 1700 ms 36188 KB Output is correct