답안 #919475

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
919475 2024-01-31T22:15:28 Z OAleksa Tourism (JOI23_tourism) C++14
34 / 100
5000 ms 24640 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
const int N = 1e5 + 69;
int n, m, q, c[N], ans[N], sz[N], top[N], pos[N], fenw[N];
int node, par[N], dep[N];
vector<int> g[N];
vector<pair<int, int>> qs[N];
set<tuple<int, int, int>> range;
void modify(int v, int val) {
	for (int i = v;i < N;i += (i & -i))
		fenw[i] += val;
}
int Get(int v) {
	int r = 0;
	for (int i = v;i > 0;i -= (i & -i))
		r += fenw[i];
	return r;
}
void dfs(int v, int p) {
	sz[v] = 1;
	par[v] = p;
	dep[v] = dep[p] + 1;
	for (auto u : g[v]) {
		if (u == p)
			continue;
		dfs(u, v);
		sz[v] += sz[u];
	}
}
void hld(int v, int p, int tp) {
	pos[v] = ++node;
	top[v] = tp;
	int s = -1, mx = 0;
	for (auto u : g[v]) {
		if (u == p)
			continue;
		if (sz[u] > mx) {
			mx = sz[u];
			s = u;
		}
	}
	if (s == -1)
		return;
	hld(s, v, tp);
	for (auto u : g[v]) {
		if (u == s || u == p)
			continue;
		hld(u, v, u);
	}
}
void Modify(int l, int r, int c) {
	if (l > r)
		swap(l, r);
	while (l <= r) {
		auto u = range.upper_bound({l, N, N});
		--u;
		int levo, desno, clr;
		tie(levo, desno, clr) = *u;
		assert(l >= levo & l <= desno);
		int cnt = 0;
		range.erase(u);
		if (l > levo) 
			range.insert({levo, l - 1, clr});
		if (desno > r)
			range.insert({r + 1, desno, clr});
		cnt += min(desno, r) - l + 1;
		modify(clr, -cnt);
		modify(c, min(desno, r) - l + 1);
		range.insert({l, min(desno, r), c});
		l = desno + 1;
	}
}
void Change(int a, int b, int c) {
	while (top[a] != top[b]) {
		if (dep[top[a]] < dep[top[b]])
			swap(a, b);
		Modify(pos[top[a]], pos[a], c);
		a = par[top[a]];
	}
	Modify(pos[b], pos[a], c);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
  	cin >> n >> m >> q;
  	for (int i = 1;i <= n - 1;i++) {
  		int a, b;
  		cin >> a >> b;
  		g[a].push_back(b);
  		g[b].push_back(a);
  	}
  	for (int i = 1;i <= m;i++ )
  		cin >> c[i];
  	for (int i = 1;i <= q;i++) {
  		int l, r;
  		cin >> l >> r;
  		qs[r].push_back({l, i});
  	}
  	dfs(1, 0);
  	hld(1, 1, 1);
  	range.insert({1, n, N});
  	for (int i = 1;i <= m;i++) {
  		if (i > 1) 
  			Change(c[i], c[i - 1], i - 1);
  		for (auto u : qs[i]) {
  			int l, ind;
  			tie(l, ind) = u;
  			if (l == i)
  				ans[ind] = 1;
  			else
  				ans[ind] = Get(N - 1) - Get(l - 1);
  		}
  	}
  	for (int i = 1;i <= q;i++)
  		cout << ans[i] << '\n';
	}
  return 0;
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from tourism.cpp:1:
tourism.cpp: In function 'void Modify(long long int, long long int, long long int)':
tourism.cpp:62:12: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   62 |   assert(l >= levo & l <= desno);
      |          ~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10840 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 3 ms 10840 KB Output is correct
6 Correct 3 ms 10840 KB Output is correct
7 Correct 3 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 3 ms 10840 KB Output is correct
10 Correct 4 ms 10844 KB Output is correct
11 Correct 2 ms 10840 KB Output is correct
12 Correct 3 ms 10840 KB Output is correct
13 Correct 3 ms 10840 KB Output is correct
14 Correct 3 ms 10840 KB Output is correct
15 Correct 4 ms 10840 KB Output is correct
16 Correct 4 ms 10844 KB Output is correct
17 Correct 4 ms 10844 KB Output is correct
18 Correct 4 ms 10840 KB Output is correct
19 Correct 4 ms 10840 KB Output is correct
20 Correct 4 ms 10840 KB Output is correct
21 Correct 3 ms 10840 KB Output is correct
22 Correct 3 ms 10840 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 3 ms 10840 KB Output is correct
25 Correct 3 ms 10840 KB Output is correct
26 Correct 3 ms 10840 KB Output is correct
27 Correct 2 ms 10840 KB Output is correct
28 Correct 2 ms 10840 KB Output is correct
29 Correct 3 ms 10860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10840 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 3 ms 10840 KB Output is correct
6 Correct 3 ms 10840 KB Output is correct
7 Correct 3 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 3 ms 10840 KB Output is correct
10 Correct 4 ms 10844 KB Output is correct
11 Correct 2 ms 10840 KB Output is correct
12 Correct 3 ms 10840 KB Output is correct
13 Correct 3 ms 10840 KB Output is correct
14 Correct 3 ms 10840 KB Output is correct
15 Correct 4 ms 10840 KB Output is correct
16 Correct 4 ms 10844 KB Output is correct
17 Correct 4 ms 10844 KB Output is correct
18 Correct 4 ms 10840 KB Output is correct
19 Correct 4 ms 10840 KB Output is correct
20 Correct 4 ms 10840 KB Output is correct
21 Correct 3 ms 10840 KB Output is correct
22 Correct 3 ms 10840 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 3 ms 10840 KB Output is correct
25 Correct 3 ms 10840 KB Output is correct
26 Correct 3 ms 10840 KB Output is correct
27 Correct 2 ms 10840 KB Output is correct
28 Correct 2 ms 10840 KB Output is correct
29 Correct 3 ms 10860 KB Output is correct
30 Correct 6 ms 10840 KB Output is correct
31 Correct 6 ms 10840 KB Output is correct
32 Correct 8 ms 11096 KB Output is correct
33 Correct 8 ms 11096 KB Output is correct
34 Correct 7 ms 11096 KB Output is correct
35 Correct 9 ms 11096 KB Output is correct
36 Correct 8 ms 11352 KB Output is correct
37 Correct 7 ms 10936 KB Output is correct
38 Correct 74 ms 11136 KB Output is correct
39 Correct 84 ms 11164 KB Output is correct
40 Correct 74 ms 11096 KB Output is correct
41 Correct 75 ms 11176 KB Output is correct
42 Correct 73 ms 11096 KB Output is correct
43 Correct 74 ms 11096 KB Output is correct
44 Correct 41 ms 11108 KB Output is correct
45 Correct 32 ms 11108 KB Output is correct
46 Correct 37 ms 11096 KB Output is correct
47 Correct 32 ms 11100 KB Output is correct
48 Correct 28 ms 11100 KB Output is correct
49 Correct 38 ms 11096 KB Output is correct
50 Correct 6 ms 11096 KB Output is correct
51 Correct 5 ms 11096 KB Output is correct
52 Correct 5 ms 11096 KB Output is correct
53 Correct 5 ms 11352 KB Output is correct
54 Correct 4 ms 11096 KB Output is correct
55 Correct 4 ms 11100 KB Output is correct
56 Correct 3 ms 10844 KB Output is correct
57 Correct 3 ms 10840 KB Output is correct
58 Correct 7 ms 11352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 4 ms 10840 KB Output is correct
4 Execution timed out 5010 ms 19456 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 267 ms 15884 KB Output is correct
3 Correct 417 ms 16960 KB Output is correct
4 Correct 325 ms 17296 KB Output is correct
5 Correct 516 ms 20560 KB Output is correct
6 Correct 502 ms 20560 KB Output is correct
7 Correct 521 ms 20240 KB Output is correct
8 Correct 496 ms 20304 KB Output is correct
9 Correct 565 ms 20520 KB Output is correct
10 Correct 530 ms 20564 KB Output is correct
11 Correct 517 ms 20644 KB Output is correct
12 Correct 553 ms 20640 KB Output is correct
13 Correct 524 ms 20560 KB Output is correct
14 Correct 517 ms 21416 KB Output is correct
15 Correct 547 ms 23632 KB Output is correct
16 Correct 530 ms 20572 KB Output is correct
17 Correct 526 ms 20788 KB Output is correct
18 Correct 516 ms 20816 KB Output is correct
19 Execution timed out 5038 ms 18728 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 3 ms 10844 KB Output is correct
3 Correct 3 ms 10840 KB Output is correct
4 Correct 610 ms 20192 KB Output is correct
5 Correct 619 ms 20304 KB Output is correct
6 Correct 733 ms 23096 KB Output is correct
7 Correct 766 ms 24188 KB Output is correct
8 Correct 771 ms 24244 KB Output is correct
9 Correct 764 ms 24144 KB Output is correct
10 Correct 731 ms 24252 KB Output is correct
11 Correct 778 ms 24584 KB Output is correct
12 Correct 808 ms 24144 KB Output is correct
13 Correct 771 ms 24640 KB Output is correct
14 Correct 39 ms 14168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10840 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 3 ms 10840 KB Output is correct
6 Correct 3 ms 10840 KB Output is correct
7 Correct 3 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 3 ms 10840 KB Output is correct
10 Correct 4 ms 10844 KB Output is correct
11 Correct 2 ms 10840 KB Output is correct
12 Correct 3 ms 10840 KB Output is correct
13 Correct 3 ms 10840 KB Output is correct
14 Correct 3 ms 10840 KB Output is correct
15 Correct 4 ms 10840 KB Output is correct
16 Correct 4 ms 10844 KB Output is correct
17 Correct 4 ms 10844 KB Output is correct
18 Correct 4 ms 10840 KB Output is correct
19 Correct 4 ms 10840 KB Output is correct
20 Correct 4 ms 10840 KB Output is correct
21 Correct 3 ms 10840 KB Output is correct
22 Correct 3 ms 10840 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 3 ms 10840 KB Output is correct
25 Correct 3 ms 10840 KB Output is correct
26 Correct 3 ms 10840 KB Output is correct
27 Correct 2 ms 10840 KB Output is correct
28 Correct 2 ms 10840 KB Output is correct
29 Correct 3 ms 10860 KB Output is correct
30 Correct 6 ms 10840 KB Output is correct
31 Correct 6 ms 10840 KB Output is correct
32 Correct 8 ms 11096 KB Output is correct
33 Correct 8 ms 11096 KB Output is correct
34 Correct 7 ms 11096 KB Output is correct
35 Correct 9 ms 11096 KB Output is correct
36 Correct 8 ms 11352 KB Output is correct
37 Correct 7 ms 10936 KB Output is correct
38 Correct 74 ms 11136 KB Output is correct
39 Correct 84 ms 11164 KB Output is correct
40 Correct 74 ms 11096 KB Output is correct
41 Correct 75 ms 11176 KB Output is correct
42 Correct 73 ms 11096 KB Output is correct
43 Correct 74 ms 11096 KB Output is correct
44 Correct 41 ms 11108 KB Output is correct
45 Correct 32 ms 11108 KB Output is correct
46 Correct 37 ms 11096 KB Output is correct
47 Correct 32 ms 11100 KB Output is correct
48 Correct 28 ms 11100 KB Output is correct
49 Correct 38 ms 11096 KB Output is correct
50 Correct 6 ms 11096 KB Output is correct
51 Correct 5 ms 11096 KB Output is correct
52 Correct 5 ms 11096 KB Output is correct
53 Correct 5 ms 11352 KB Output is correct
54 Correct 4 ms 11096 KB Output is correct
55 Correct 4 ms 11100 KB Output is correct
56 Correct 3 ms 10844 KB Output is correct
57 Correct 3 ms 10840 KB Output is correct
58 Correct 7 ms 11352 KB Output is correct
59 Correct 2 ms 10844 KB Output is correct
60 Correct 2 ms 10844 KB Output is correct
61 Correct 4 ms 10840 KB Output is correct
62 Execution timed out 5010 ms 19456 KB Time limit exceeded
63 Halted 0 ms 0 KB -