Submission #1077418

# Submission time Handle Problem Language Result Execution time Memory
1077418 2024-08-27T07:01:48 Z vjudge1 Reconstruction Project (JOI22_reconstruction) C++14
31 / 100
156 ms 18304 KB
#include <bits/stdc++.h>
#define all(v) v.begin(),v.end()
#define F first
#define S second
using namespace std;
typedef int ll;
typedef pair<ll,ll>pll;
const ll oo=20000+9;
const ll inf=1e9+9;
struct node
{
    ll a,b,c;
} a[oo];
bool cmp(const node&A,const node&B)
{
    return A.c < B.c;
}
ll n,m,p[509],q;
bool vis[oo];
vector<ll>lst;
vector<pll>v;
ll gp(ll z)
{
    if(p[z]<0)
        return z;
    return p[z]=gp(p[z]);
}
bool mrg(ll x,ll y)
{
    x=gp(x),y=gp(y);
    if(x==y)
        return 0;
    if(p[x]>p[y])
        swap(x,y);
    p[x]+=p[y];
    p[y]=x;
    return 1;
}
void solve()
{
    cin>>n>>m;
    for(ll i=0; i<m; i++)
        cin>>a[i].a>>a[i].b>>a[i].c;
    sort(a,a+m,cmp);
    for(ll i=0; i<m; i++)
    {
        for(ll j=1; j<=n; j++)
            p[j]=-1;
        lst.push_back(i);
        ll id=-1;
        for(ll j=(ll)lst.size()-1; j>=0; j--)
        {
            ll x=lst[j];
            if(!mrg(a[x].a,a[x].b))
            {
                id=j;
                break;
            }
        }
        if(id!=-1)
        {
            ll x=lst[id];
            vis[x]=1;
            v.push_back({(a[x].c+a[i].c)/2+1,x});
            v.push_back({(a[x].c+a[i].c)/2+1,i});
            lst.erase(lst.begin()+id);
        }
        else
        v.push_back({0,i});
    }
    for(auto&z:lst)
    v.push_back({inf,z});
    sort(all(v));
    memset(vis,0,sizeof vis);
    cin>>q;
    ll le=0,cl=0,cr=0;
    long long suml=0,sumr=0;
    multiset<ll>s;
    while(q--)
    {
        ll x;
        cin>>x;
        while(le<v.size()&&v[le].F<=x)
        {
            ll o=v[le].S;
            if(vis[o])
            {
                if(s.find(a[o].c)!=s.end())
                {
                    cl--,suml-=a[o].c;
                    s.erase(s.find(a[o].c));
                }
                else
                {
                    cr--,sumr-=a[o].c;
                }
            }
            else
            {
                vis[o]=1;
                cl++,suml+=a[o].c;
                s.insert(a[o].c);
            }
            le++;
        }
        while(!s.empty()&&*s.begin()<x)
        {
            cl--,suml-=*s.begin();
            cr++,sumr+=*s.begin();
            s.erase(s.begin());
        }
        cout<<suml-sumr-1ll*cl*x+1ll*cr*x<<"\n";
    }
}
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    ll tt=1;
//    cin>>tt;
    while(tt--)
        solve();
    return 0;
}

Compilation message

reconstruction.cpp: In function 'void solve()':
reconstruction.cpp:83:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |         while(le<v.size()&&v[le].F<=x)
      |               ~~^~~~~~~~~
# 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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Runtime error 4 ms 1372 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Runtime error 4 ms 1412 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 136 ms 17688 KB Output is correct
21 Correct 133 ms 18004 KB Output is correct
22 Correct 153 ms 18192 KB Output is correct
23 Correct 153 ms 18008 KB Output is correct
24 Correct 130 ms 17744 KB Output is correct
25 Correct 140 ms 17864 KB Output is correct
26 Correct 143 ms 17748 KB Output is correct
27 Correct 132 ms 17744 KB Output is correct
28 Correct 156 ms 17748 KB Output is correct
29 Correct 155 ms 17792 KB Output is correct
30 Correct 138 ms 18072 KB Output is correct
31 Correct 134 ms 17832 KB Output is correct
32 Correct 130 ms 18304 KB Output is correct
33 Correct 127 ms 17696 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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Runtime error 4 ms 1372 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -
# 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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Runtime error 4 ms 1372 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -