Submission #1312433

#TimeUsernameProblemLanguageResultExecution timeMemory
1312433_TemirhanVinjete (COI22_vinjete)C++20
0 / 100
3 ms576 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>  
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("Ofast,unroll-loops,inline-functions,no-stack-protector,03")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
#pragma clang loop vectorize(enable)
#pragma clang loop interleave(enable)

#define int long long
#define sz(x) (int)x.size()
#define F first
#define S second
#define pb push_back
#define nl '\n'
#define o_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int, int> pii;

void file( string s = "" )
{
    if( s.empty() )
        return;
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

const int N = 2e5 + 2;
const int N1 = 1e6 + 2;
const int inf = 1e9 + 2;
const int INF = 1e18 + 2;
const int mod = 1e9 + 7;
int T = 1, n, M, add[30 * N], L[30 * N], R[30 * N], ans[N], num = 1;
vector< array<int, 3> >g[N];
pii t[30 * N];

void push( int v, int tl, int tr )
{
    int m = (tl + tr) / 2;
    if( !L[v] )
    {
        L[v] = ++num;
        t[L[v]] = {m - tl + 1, 0};
    }
    if( !R[v] )
    {
        R[v] = ++num;
        t[R[v]] = {tr - m, 0};
    }
    if( add[v] )
    {
        add[L[v]] += add[v];
        t[L[v]].S += add[v];
        add[R[v]] += add[v];
        t[R[v]].S += add[v];
        add[v] = 0;
    }
}

void upd( int v, int tl, int tr, int l, int r, int x )
{
    if( r < tl || tr < l )
        return;
    if( l <= tl && tr <= r )
    {
        add[v] += x;
        t[v].S += x;
        return;
    }
    push(v, tl, tr);
    int m = (tl + tr) / 2;
    upd(L[v], tl, m, l, r, x);
    upd(R[v], m + 1, tr, l, r, x);
    t[v].S = min(t[L[v]].S, t[R[v]].S);
    t[v].F = 0;
    if( t[v].S == t[L[v]].S )
        t[v].F += t[L[v]].F;
    if( t[v].S == t[R[v]].S )
        t[v].F += t[R[v]].F; 
}

void dfs( int v, int p )
{
    ans[v] = M - (t[1].S == 0 ? t[1].F : 0);
    for( auto [to, l, r]: g[v] )
        if( to != p )
        {
            upd(1, 1, M + 1, l, r + 1, 1);
            dfs(to, v);
            upd(1, 1, M + 1, l, r + 1, -1);
        }
}

void solve()
{
    cin >>n >>M;
    for( int i = 1, u, v, l, r; i < n; ++i )
    {
        cin >>u >>v >>l >>r;
        g[u].pb({v, l, r});
        g[v].pb({u, l, r});
    }
    dfs(1, 0);
    for( int i = 2; i <= n; ++i )
        cout <<ans[i] <<nl;
}

signed main()
{
    file("");
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin >>T;
    while( T-- )
        solve();
}

Compilation message (stderr)

Main.cpp: In function 'void file(std::string)':
Main.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...