Submission #750898

#TimeUsernameProblemLanguageResultExecution timeMemory
750898edogawa_somethingVinjete (COI22_vinjete)C++17
100 / 100
671 ms339464 KiB
#include<bits/stdc++.h> #include<chrono> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef string str; typedef bool bl; typedef vector<ll> vii; typedef pair<ll,ll> pii; typedef vector<pii> vpi; #define ordered_set tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> #define fast ios_base::sync_with_stdio(0);cin.tie(); #define test ll qqqqq;cin>>qqqqq;while(qqqqq--) #define test1 ll qqqqq=1;while(qqqqq--) #define F first #define S second #define forn(i,n) for(int i=0;i<n;i++) #define forx(i,j,n) for(int i=j;i<n;i++) #define pb push_back #define eb emplace_back #define pob pop_back #define all(v) v.begin(),v.end() #define lb lower_bound #define ub upper_bound #define pow powww #define prtll(x) printf("%lld",x) #define prtld(x) printf("%Lf",x) #define prtst(x) printf("%s",x) #define prtch(x) printf("%c",x) #define measure chrono::high_resolution_clock::now() #define duration chrono::duration_cast<chrono::milliseconds>(end-start) #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") const ll dx[]{1,0,-1,0,1,-1,1,-1}; const ll dy[]{0,-1,0,1,1,-1,-1,1}; const ll inf=1e18; const ll mod=1e9+7; const ll LM=1e8+1; const ll M=6e6+10; const ll MM=4002; const ll MMM=501; const ld pi=acos(-1); //const ll mod=998244353; ll pow(ll r,ll to,ll m=mod){ ll res=1; r%=m; while(to){ if((to&1)){ res*=r,res%=m; } r*=r,r%=m; to=(to>>1); } return res; } ll le[M],ri[M],val[M],cnt[M],has[M],t=1; ll n,m,a[M]; struct seg{ void update(ll l,ll r,ll v,ll x,ll lx,ll rx){ if(rx<=l||r<=lx) return; if(rx-lx==1){ val[x]+=v; cnt[x]=1; return; } if(rx<=r&&lx>=l){ has[x]+=v; return; } else{ ll mid=((lx+rx)>>1); if(le[x]==0){ le[x]=t++; cnt[le[x]]=mid-lx; } if(ri[x]==0){ ri[x]=t++; cnt[ri[x]]=rx-mid; } update(l,r,v,le[x],lx,mid); update(l,r,v,ri[x],mid,rx); if(val[ri[x]]+has[ri[x]]==val[le[x]]+has[le[x]]) cnt[x]=cnt[ri[x]]+cnt[le[x]]; else if(val[ri[x]]+has[ri[x]]<val[le[x]]+has[le[x]]) cnt[x]=cnt[ri[x]]; else cnt[x]=cnt[le[x]]; val[x]=min(val[le[x]]+has[le[x]],val[ri[x]]+has[ri[x]]); } } void update(ll l,ll r,ll v){ update(l,r,v,0,0,(1<<30)); } ll query(){ return (1<<30)-cnt[0]; } }s; vector<pair<ll,pii>>v[M]; ll ans[M]; void dfs(ll r,ll pa){ ans[r]=s.query(); for(auto it:v[r]){ if(it.F==pa) continue; s.update(it.S.F,it.S.S,1); dfs(it.F,r); s.update(it.S.F,it.S.S,-1); } } int main(){ fast //freopen("gen.txt","r",stdin); auto start=measure; test1{ cin>>n>>m; forn(i,n-1){ ll x,y,l,r; cin>>x>>y>>l>>r; v[x].pb({y,{l-1,r}}); v[y].pb({x,{l-1,r}}); } dfs(1,-1); forx(i,2,n+1){ cout<<ans[i]<<'\n'; } } auto end=measure; auto dur=duration; //cout<<fixed<<dur.count()<<'\n'; return 0; } /* */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...