답안 #863984

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
863984 2023-10-21T15:53:27 Z serifefedartar Vinjete (COI22_vinjete) C++17
0 / 100
4 ms 14428 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll LOGN = 20; 
const ll MAXN = 1e5 + 5;

struct Edge {
	int to, l, r;
	Edge(int _to, int _l, int _r) : to(_to), l(_l), r(_r) { }
};

struct Node {
	int val, len;
	int mn, mn_cnt;
	Node() : val(-1), len(0), mn(1e9), mn_cnt(0) { }
};

vector<vector<Edge>> graph;
vector<int> cc;
Node sg[8*MAXN];
int lazy[8*MAXN], ans[MAXN];

int n, M;
Node merge(Node a, Node b) {
	Node temp;
	temp.len = a.len + b.len;
	temp.mn = min(a.mn, b.mn);
	temp.mn_cnt = (temp.mn == a.mn ? a.mn_cnt : 0) + (temp.mn == b.mn ? b.mn_cnt : 0);
	return temp;
}

void push(int k, int a, int b) {
	if (lazy[k]) {
		sg[k].mn += lazy[k];
		if (a != b) {
			lazy[2*k] += lazy[k];
			lazy[2*k+1] += lazy[k];
		}
		lazy[k] = 0;
	}
}

void init(int k, int a, int b) {
	if (a == b) {
		sg[k].mn_cnt = sg[k].len = (a == n ? 0 : cc[a] - cc[a-1]);
		sg[k].mn = sg[k].val = 0;
		return ;
	}
	init(2*k, a, (a+b)/2);
	init(2*k+1, (a+b)/2+1, b);
	sg[k] = merge(sg[2*k], sg[2*k+1]);
}

void update(int k, int a, int b, int q_l, int q_r, int val) {
	push(k, a, b);
	if (b < q_l || a > q_r)
		return ;
	if (q_l <= a && b <= q_r) {
		lazy[k] += val;
		push(k, a, b);
		return ;
	}
	update(2*k, a, (a+b)/2, q_l, q_r, val);
	update(2*k+1, (a+b)/2+1, b, q_l, q_r, val);
	sg[k] = merge(sg[2*k], sg[2*k+1]);
}
	
Node emp;
Node query(int k, int a, int b, int q_l, int q_r) {
	push(k, a, b);
	if (b < q_l || a > q_r)
		return emp;
	if (q_l <= a && b <= q_r)
		return sg[k];

	return merge(query(2*k, a, (a+b)/2, q_l, q_r), query(2*k+1, (a+b)/2+1, b, q_l, q_r));
}

int index(int k) {
	return upper_bound(cc.begin(), cc.end(), k) - cc.begin();
}

void dfs(int node, int parent) {
	Node Q = query(1, 1, n, 1, n);
	if (Q.mn == 0)
		ans[node] = M - Q.mn_cnt;

	for (auto u : graph[node]) {
		if (u.to == parent)
			continue;
		int left = index(u.l); 
		int right = index(u.r);
		update(1, 1, n, left, right, 1);
		dfs(u.to, node);
		update(1, 1, n, left, right, -1);
	}
}

int main() {
	fast
	int N, a, b, l, r;
	cin >> N >> M;

	graph = vector<vector<Edge>>(N+1, vector<Edge>());
	for (int i = 1; i < N; i++) {
		cin >> a >> b >> l >> r;
		graph[a].push_back(Edge(b, l, r));
		graph[b].push_back(Edge(a, l, r));
		cc.push_back(l);
		cc.push_back(r);
		cc.push_back(l+1);
		cc.push_back(r+1);
	}
	sort(cc.begin(), cc.end());
	cc.erase(unique(cc.begin(), cc.end()), cc.end());
	n = cc.size();
	init(1, 1, n);
	dfs(1, 1);

	for (int i = 2; i <= N; i++)
		cout << ans[i] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14424 KB Output is correct
2 Correct 4 ms 14428 KB Output is correct
3 Correct 4 ms 14428 KB Output is correct
4 Incorrect 4 ms 14428 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14424 KB Output is correct
2 Correct 4 ms 14428 KB Output is correct
3 Correct 4 ms 14428 KB Output is correct
4 Incorrect 4 ms 14428 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14424 KB Output is correct
2 Correct 4 ms 14428 KB Output is correct
3 Correct 4 ms 14428 KB Output is correct
4 Incorrect 4 ms 14428 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14424 KB Output is correct
2 Correct 4 ms 14428 KB Output is correct
3 Correct 4 ms 14428 KB Output is correct
4 Incorrect 4 ms 14428 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14424 KB Output is correct
2 Correct 4 ms 14428 KB Output is correct
3 Correct 4 ms 14428 KB Output is correct
4 Incorrect 4 ms 14428 KB Output isn't correct
5 Halted 0 ms 0 KB -