Submission #963897

#TimeUsernameProblemLanguageResultExecution timeMemory
963897becaidoVinjete (COI22_vinjete)C++17
100 / 100
259 ms27320 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include <bits/stdc++.h> using namespace std; #ifdef WAIMAI #define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE) void dout() {cout << '\n';} template<typename T, typename...U> void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);} #else #define debug(...) 7122 #endif #define ll long long #define Waimai ios::sync_with_stdio(false), cin.tie(0) #define FOR(x,a,b) for (int x = a, I = b; x <= I; x++) #define pb emplace_back #define F first #define S second #define lpos pos*2 #define rpos pos*2+1 const int SIZE = 2e5 + 5; int n, m, len; int ans[SIZE]; vector<int> lis; vector<tuple<int, int, int>> adj[SIZE]; struct Node { int mn, sum, lazy; Node operator + (const Node &o) const { Node re; re.mn = min(mn, o.mn); re.sum = (mn == re.mn ? sum : 0) + (o.mn == re.mn ? o.sum : 0); re.lazy = 0; return re; } } node[SIZE << 2]; void build(int pos, int l, int r) { if (l == r) { node[pos].sum = lis[l] - lis[l - 1]; return; } int mid = (l + r) / 2; build(lpos, l, mid); build(rpos, mid + 1, r); node[pos] = node[lpos] + node[rpos]; } void push(int pos, int l, int r) { if (node[pos].lazy == 0) return; node[pos].mn += node[pos].lazy; if (l < r) { node[lpos].lazy += node[pos].lazy; node[rpos].lazy += node[pos].lazy; } node[pos].lazy = 0; } void pull(int pos, int l, int r) { int mid = (l + r) / 2; push(lpos, l, mid); push(rpos, mid + 1, r); node[pos] = node[lpos] + node[rpos]; } void upd(int pos, int l, int r, int L, int R, int x) { if (l == L && r == R) { node[pos].lazy += x; push(pos, L, R); return; } int mid = (L + R) / 2; push(pos, L, R); if (r <= mid) upd(lpos, l, r, L, mid, x); else if (l > mid) upd(rpos, l, r, mid + 1, R, x); else { upd(lpos, l, mid, L, mid, x); upd(rpos, mid + 1, r, mid + 1, R, x); } pull(pos, L, R); } void dfs(int pos, int fa) { ans[pos] = len - (node[1].mn == 0 ? node[1].sum : 0); for (auto [np, l, r] : adj[pos]) if (np != fa) { l = lower_bound(lis.begin(), lis.end(), l) - lis.begin() + 1; r = lower_bound(lis.begin(), lis.end(), r + 1) - lis.begin(); upd(1, l, r, 1, m, 1); dfs(np, pos); upd(1, l, r, 1, m, -1); } } void solve() { cin >> n >> m; FOR (i, 2, n) { int a, b, l, r; cin >> a >> b >> l >> r; adj[a].pb(b, l, r); adj[b].pb(a, l, r); lis.pb(l), lis.pb(r + 1); } sort(lis.begin(), lis.end()); lis.erase(unique(lis.begin(), lis.end()), lis.end()); m = lis.size() - 1; len = lis.back() - lis[0]; build(1, 1, m); dfs(1, 1); FOR (i, 2, n) cout << ans[i] << '\n'; } int main() { Waimai; solve(); }
#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...