Submission #932499

#TimeUsernameProblemLanguageResultExecution timeMemory
932499andrei_boacaWorst Reporter 4 (JOI21_worst_reporter4)C++17
79 / 100
409 ms75196 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; const ll INF=1e17; map<ll,ll> nrm; ll nr; vector<ll> muchii[200005]; ll n,par[200005],v[200005],cost[200005]; set<pll> setik[200005]; void add(ll nod,ll poz,ll val) { auto it=setik[nod].lower_bound({poz,0}); if((*it).first==poz) { ll x=(*it).second+val; setik[nod].erase(it); setik[nod].insert({poz,x}); } else setik[nod].insert({poz,val}); } void dfs(ll nod) { if(muchii[nod].empty()) { add(nod,v[nod]+1,cost[nod]); return; } ll maxim=0; ll who=0; for(int i:muchii[nod]) { dfs(i); if(setik[i].size()>maxim) { maxim=setik[i].size(); who=i; } } swap(setik[nod],setik[who]); for(int i:muchii[nod]) if(i!=who) { for(auto j:setik[i]) add(nod,j.first,j.second); setik[i].clear(); } add(nod,1,cost[nod]); ll dif=cost[nod]; while(!setik[nod].empty()&&dif>0) { auto it=prev(setik[nod].upper_bound({v[nod],INF})); ll poz=(*it).first; ll x=(*it).second; ll val=min(dif,x); x-=val; dif-=val; setik[nod].erase(it); if(x!=0) setik[nod].insert({poz,x}); } add(nod,v[nod]+1,cost[nod]); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n; vector<ll> vals; for(int i=1;i<=n;i++) { cin>>par[i]>>v[i]>>cost[i]; if(i!=1) muchii[par[i]].push_back(i); vals.push_back(v[i]); } sort(vals.begin(),vals.end()); vals.erase(unique(vals.begin(),vals.end()),vals.end()); for(int i=0;i<vals.size();i++) nrm[vals[i]]=i+1; nr=vals.size(); for(int i=1;i<=n;i++) v[i]=nrm[v[i]]; dfs(1); auto it=setik[1].begin(); if((*it).first==1) cout<<(*it).second; else cout<<0; return 0; }

Compilation message (stderr)

worst_reporter2.cpp: In function 'void dfs(ll)':
worst_reporter2.cpp:36:27: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   36 |         if(setik[i].size()>maxim)
      |            ~~~~~~~~~~~~~~~^~~~~~
worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:81:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for(int i=0;i<vals.size();i++)
      |                 ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...