답안 #704791

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704791 2023-03-03T03:15:48 Z Chal1shkan Birthday gift (IZhO18_treearray) C++14
100 / 100
1126 ms 104452 KB
# include <bits/stdc++.h>
 
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define deb(x) cerr << #x  << " = " << x << endl; 
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const ll maxn = 2e5 + 25;
const ll inf = 1e18 + 0;
const ll mod = 1e9 + 123;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
 
using namespace std;

ll n, m, q, timer;
vector <ll> g[maxn];
ll up[maxn][21];
ll tin[maxn];
ll tout[maxn];
ll a[maxn];
set <ll> st[maxn];
set <ll> qq[maxn];

void dfs (ll v = 1, ll pa = 1)
{
	tin[v] = ++timer;
	up[v][0] = pa;
	for (ll j = 1; j <= 19; ++j)
	{
		up[v][j] = up[up[v][j - 1]][j - 1];
	}
	for (ll to : g[v])
	{
		if (to == pa) continue;
		dfs(to, v);
	}
	tout[v] = timer;
}

bool anc (ll u, ll v)
{
	return (tin[u] <= tin[v] && tout[v] <= tout[u]);
}

ll lca (ll u, ll v)
{
	if (anc(u, v)) return u;
	if (anc(v, u)) return v;
	for (ll j = 19; j >= 0; --j)
	{
		if (!anc(up[u][j], v))
		{
			u = up[u][j];
		}
	}
	return up[u][0];
}

void ma1n (/* SABR */)
{
	cin >> n >> m >> q;
	for (ll i = 2, u, v; i <= n; ++i)
	{
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs ();
	for (ll i = 1; i <= m; ++i)
	{
		cin >> a[i];
		if (i > 1)
		{
			st[lca(a[i], a[i - 1])].insert(i);
		}
		qq[a[i]].insert(i);
	}
	while (q--)
	{
		ll type;
		cin >> type;
		if (type == 1)
		{
			ll pos, val;
			cin >> pos >> val;
			qq[a[pos]].erase(pos);
			qq[val].insert(pos);
			if (pos > 1)
			{
				st[lca(a[pos], a[pos - 1])].erase(pos);
				st[lca(val, a[pos - 1])].insert(pos);
			}
			if (pos < m)
			{
				st[lca(a[pos], a[pos + 1])].erase(pos + 1);
				st[lca(val, a[pos + 1])].insert(pos + 1);
			}
			a[pos] = val;
		}
		if (type == 2)
		{
			ll l, r, v;
			cin >> l >> r >> v;
			auto it = qq[v].lower_bound(l);
			if (it != qq[v].end() && *it <= r)
			{
				cout << *it << ' ' << *it << nl;
			}
			else
			{
				auto it = st[v].upper_bound(l);
				if (it != st[v].end() && *it <= r)
				{
					cout << *it - 1 << ' ' << *it << nl;
				}
				else
				{
					cout << -1 << ' ' << -1 << nl;
				}
			}
		}
	}
}
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("file.in", "r", stdin);
//  freopen("file.out", "w", stdout);
    int ttt = 1;
//  cin >> ttt;
    for (int test = 1; test <= ttt; ++test)
    {
//      cout << "Case " << test << ":" << ' ';
        ma1n();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB n=5
2 Correct 11 ms 23872 KB n=100
3 Correct 12 ms 23820 KB n=100
4 Correct 11 ms 23764 KB n=100
5 Correct 12 ms 23768 KB n=100
6 Correct 12 ms 23760 KB n=100
7 Correct 11 ms 23764 KB n=100
8 Correct 11 ms 23864 KB n=100
9 Correct 12 ms 23764 KB n=100
10 Correct 14 ms 23764 KB n=100
11 Correct 12 ms 23820 KB n=100
12 Correct 11 ms 23764 KB n=100
13 Correct 14 ms 23764 KB n=100
14 Correct 12 ms 23824 KB n=100
15 Correct 11 ms 23820 KB n=100
16 Correct 11 ms 23852 KB n=100
17 Correct 12 ms 23764 KB n=100
18 Correct 14 ms 23768 KB n=100
19 Correct 12 ms 23764 KB n=100
20 Correct 12 ms 23824 KB n=100
21 Correct 12 ms 23764 KB n=100
22 Correct 11 ms 23796 KB n=100
23 Correct 12 ms 23840 KB n=100
24 Correct 12 ms 23820 KB n=100
25 Correct 12 ms 23764 KB n=100
26 Correct 14 ms 23764 KB n=12
27 Correct 14 ms 23812 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB n=5
2 Correct 11 ms 23872 KB n=100
3 Correct 12 ms 23820 KB n=100
4 Correct 11 ms 23764 KB n=100
5 Correct 12 ms 23768 KB n=100
6 Correct 12 ms 23760 KB n=100
7 Correct 11 ms 23764 KB n=100
8 Correct 11 ms 23864 KB n=100
9 Correct 12 ms 23764 KB n=100
10 Correct 14 ms 23764 KB n=100
11 Correct 12 ms 23820 KB n=100
12 Correct 11 ms 23764 KB n=100
13 Correct 14 ms 23764 KB n=100
14 Correct 12 ms 23824 KB n=100
15 Correct 11 ms 23820 KB n=100
16 Correct 11 ms 23852 KB n=100
17 Correct 12 ms 23764 KB n=100
18 Correct 14 ms 23768 KB n=100
19 Correct 12 ms 23764 KB n=100
20 Correct 12 ms 23824 KB n=100
21 Correct 12 ms 23764 KB n=100
22 Correct 11 ms 23796 KB n=100
23 Correct 12 ms 23840 KB n=100
24 Correct 12 ms 23820 KB n=100
25 Correct 12 ms 23764 KB n=100
26 Correct 14 ms 23764 KB n=12
27 Correct 14 ms 23812 KB n=100
28 Correct 12 ms 23892 KB n=500
29 Correct 12 ms 24020 KB n=500
30 Correct 12 ms 23964 KB n=500
31 Correct 12 ms 24020 KB n=500
32 Correct 12 ms 23956 KB n=500
33 Correct 13 ms 23892 KB n=500
34 Correct 13 ms 23892 KB n=500
35 Correct 13 ms 24020 KB n=500
36 Correct 14 ms 23952 KB n=500
37 Correct 12 ms 23892 KB n=500
38 Correct 12 ms 23936 KB n=500
39 Correct 12 ms 24012 KB n=500
40 Correct 14 ms 23956 KB n=500
41 Correct 13 ms 23892 KB n=500
42 Correct 13 ms 23892 KB n=500
43 Correct 13 ms 23960 KB n=500
44 Correct 16 ms 23892 KB n=500
45 Correct 12 ms 23892 KB n=500
46 Correct 12 ms 24020 KB n=500
47 Correct 12 ms 24032 KB n=500
48 Correct 13 ms 24004 KB n=500
49 Correct 13 ms 24020 KB n=500
50 Correct 13 ms 23892 KB n=500
51 Correct 12 ms 24020 KB n=500
52 Correct 12 ms 24020 KB n=500
53 Correct 13 ms 24020 KB n=500
54 Correct 13 ms 23968 KB n=500
55 Correct 12 ms 23832 KB n=278
56 Correct 13 ms 24020 KB n=500
57 Correct 14 ms 23952 KB n=500
58 Correct 12 ms 23904 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB n=5
2 Correct 11 ms 23872 KB n=100
3 Correct 12 ms 23820 KB n=100
4 Correct 11 ms 23764 KB n=100
5 Correct 12 ms 23768 KB n=100
6 Correct 12 ms 23760 KB n=100
7 Correct 11 ms 23764 KB n=100
8 Correct 11 ms 23864 KB n=100
9 Correct 12 ms 23764 KB n=100
10 Correct 14 ms 23764 KB n=100
11 Correct 12 ms 23820 KB n=100
12 Correct 11 ms 23764 KB n=100
13 Correct 14 ms 23764 KB n=100
14 Correct 12 ms 23824 KB n=100
15 Correct 11 ms 23820 KB n=100
16 Correct 11 ms 23852 KB n=100
17 Correct 12 ms 23764 KB n=100
18 Correct 14 ms 23768 KB n=100
19 Correct 12 ms 23764 KB n=100
20 Correct 12 ms 23824 KB n=100
21 Correct 12 ms 23764 KB n=100
22 Correct 11 ms 23796 KB n=100
23 Correct 12 ms 23840 KB n=100
24 Correct 12 ms 23820 KB n=100
25 Correct 12 ms 23764 KB n=100
26 Correct 14 ms 23764 KB n=12
27 Correct 14 ms 23812 KB n=100
28 Correct 12 ms 23892 KB n=500
29 Correct 12 ms 24020 KB n=500
30 Correct 12 ms 23964 KB n=500
31 Correct 12 ms 24020 KB n=500
32 Correct 12 ms 23956 KB n=500
33 Correct 13 ms 23892 KB n=500
34 Correct 13 ms 23892 KB n=500
35 Correct 13 ms 24020 KB n=500
36 Correct 14 ms 23952 KB n=500
37 Correct 12 ms 23892 KB n=500
38 Correct 12 ms 23936 KB n=500
39 Correct 12 ms 24012 KB n=500
40 Correct 14 ms 23956 KB n=500
41 Correct 13 ms 23892 KB n=500
42 Correct 13 ms 23892 KB n=500
43 Correct 13 ms 23960 KB n=500
44 Correct 16 ms 23892 KB n=500
45 Correct 12 ms 23892 KB n=500
46 Correct 12 ms 24020 KB n=500
47 Correct 12 ms 24032 KB n=500
48 Correct 13 ms 24004 KB n=500
49 Correct 13 ms 24020 KB n=500
50 Correct 13 ms 23892 KB n=500
51 Correct 12 ms 24020 KB n=500
52 Correct 12 ms 24020 KB n=500
53 Correct 13 ms 24020 KB n=500
54 Correct 13 ms 23968 KB n=500
55 Correct 12 ms 23832 KB n=278
56 Correct 13 ms 24020 KB n=500
57 Correct 14 ms 23952 KB n=500
58 Correct 12 ms 23904 KB n=500
59 Correct 15 ms 24544 KB n=2000
60 Correct 17 ms 24532 KB n=2000
61 Correct 14 ms 24532 KB n=2000
62 Correct 15 ms 24448 KB n=2000
63 Correct 15 ms 24532 KB n=2000
64 Correct 15 ms 24568 KB n=2000
65 Correct 16 ms 24472 KB n=2000
66 Correct 16 ms 24596 KB n=2000
67 Correct 17 ms 24476 KB n=2000
68 Correct 18 ms 24532 KB n=2000
69 Correct 17 ms 24468 KB n=2000
70 Correct 17 ms 24468 KB n=2000
71 Correct 16 ms 24436 KB n=2000
72 Correct 16 ms 24552 KB n=2000
73 Correct 20 ms 24484 KB n=2000
74 Correct 16 ms 24492 KB n=1844
75 Correct 14 ms 24464 KB n=2000
76 Correct 16 ms 24532 KB n=2000
77 Correct 15 ms 24536 KB n=2000
78 Correct 15 ms 24532 KB n=2000
79 Correct 15 ms 24572 KB n=2000
80 Correct 15 ms 24484 KB n=2000
81 Correct 14 ms 24520 KB n=2000
82 Correct 15 ms 24548 KB n=2000
83 Correct 15 ms 24556 KB n=2000
84 Correct 15 ms 24544 KB n=2000
85 Correct 15 ms 24548 KB n=2000
86 Correct 18 ms 24556 KB n=2000
87 Correct 16 ms 24456 KB n=2000
88 Correct 15 ms 24532 KB n=2000
89 Correct 18 ms 24556 KB n=2000
90 Correct 15 ms 24540 KB n=2000
91 Correct 15 ms 24472 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB n=5
2 Correct 11 ms 23872 KB n=100
3 Correct 12 ms 23820 KB n=100
4 Correct 11 ms 23764 KB n=100
5 Correct 12 ms 23768 KB n=100
6 Correct 12 ms 23760 KB n=100
7 Correct 11 ms 23764 KB n=100
8 Correct 11 ms 23864 KB n=100
9 Correct 12 ms 23764 KB n=100
10 Correct 14 ms 23764 KB n=100
11 Correct 12 ms 23820 KB n=100
12 Correct 11 ms 23764 KB n=100
13 Correct 14 ms 23764 KB n=100
14 Correct 12 ms 23824 KB n=100
15 Correct 11 ms 23820 KB n=100
16 Correct 11 ms 23852 KB n=100
17 Correct 12 ms 23764 KB n=100
18 Correct 14 ms 23768 KB n=100
19 Correct 12 ms 23764 KB n=100
20 Correct 12 ms 23824 KB n=100
21 Correct 12 ms 23764 KB n=100
22 Correct 11 ms 23796 KB n=100
23 Correct 12 ms 23840 KB n=100
24 Correct 12 ms 23820 KB n=100
25 Correct 12 ms 23764 KB n=100
26 Correct 14 ms 23764 KB n=12
27 Correct 14 ms 23812 KB n=100
28 Correct 12 ms 23892 KB n=500
29 Correct 12 ms 24020 KB n=500
30 Correct 12 ms 23964 KB n=500
31 Correct 12 ms 24020 KB n=500
32 Correct 12 ms 23956 KB n=500
33 Correct 13 ms 23892 KB n=500
34 Correct 13 ms 23892 KB n=500
35 Correct 13 ms 24020 KB n=500
36 Correct 14 ms 23952 KB n=500
37 Correct 12 ms 23892 KB n=500
38 Correct 12 ms 23936 KB n=500
39 Correct 12 ms 24012 KB n=500
40 Correct 14 ms 23956 KB n=500
41 Correct 13 ms 23892 KB n=500
42 Correct 13 ms 23892 KB n=500
43 Correct 13 ms 23960 KB n=500
44 Correct 16 ms 23892 KB n=500
45 Correct 12 ms 23892 KB n=500
46 Correct 12 ms 24020 KB n=500
47 Correct 12 ms 24032 KB n=500
48 Correct 13 ms 24004 KB n=500
49 Correct 13 ms 24020 KB n=500
50 Correct 13 ms 23892 KB n=500
51 Correct 12 ms 24020 KB n=500
52 Correct 12 ms 24020 KB n=500
53 Correct 13 ms 24020 KB n=500
54 Correct 13 ms 23968 KB n=500
55 Correct 12 ms 23832 KB n=278
56 Correct 13 ms 24020 KB n=500
57 Correct 14 ms 23952 KB n=500
58 Correct 12 ms 23904 KB n=500
59 Correct 15 ms 24544 KB n=2000
60 Correct 17 ms 24532 KB n=2000
61 Correct 14 ms 24532 KB n=2000
62 Correct 15 ms 24448 KB n=2000
63 Correct 15 ms 24532 KB n=2000
64 Correct 15 ms 24568 KB n=2000
65 Correct 16 ms 24472 KB n=2000
66 Correct 16 ms 24596 KB n=2000
67 Correct 17 ms 24476 KB n=2000
68 Correct 18 ms 24532 KB n=2000
69 Correct 17 ms 24468 KB n=2000
70 Correct 17 ms 24468 KB n=2000
71 Correct 16 ms 24436 KB n=2000
72 Correct 16 ms 24552 KB n=2000
73 Correct 20 ms 24484 KB n=2000
74 Correct 16 ms 24492 KB n=1844
75 Correct 14 ms 24464 KB n=2000
76 Correct 16 ms 24532 KB n=2000
77 Correct 15 ms 24536 KB n=2000
78 Correct 15 ms 24532 KB n=2000
79 Correct 15 ms 24572 KB n=2000
80 Correct 15 ms 24484 KB n=2000
81 Correct 14 ms 24520 KB n=2000
82 Correct 15 ms 24548 KB n=2000
83 Correct 15 ms 24556 KB n=2000
84 Correct 15 ms 24544 KB n=2000
85 Correct 15 ms 24548 KB n=2000
86 Correct 18 ms 24556 KB n=2000
87 Correct 16 ms 24456 KB n=2000
88 Correct 15 ms 24532 KB n=2000
89 Correct 18 ms 24556 KB n=2000
90 Correct 15 ms 24540 KB n=2000
91 Correct 15 ms 24472 KB n=2000
92 Correct 742 ms 95744 KB n=200000
93 Correct 811 ms 100540 KB n=200000
94 Correct 567 ms 103512 KB n=200000
95 Correct 671 ms 95424 KB n=200000
96 Correct 637 ms 95544 KB n=200000
97 Correct 906 ms 99696 KB n=200000
98 Correct 673 ms 95424 KB n=200000
99 Correct 861 ms 96036 KB n=200000
100 Correct 701 ms 95608 KB n=200000
101 Correct 489 ms 104452 KB n=200000
102 Correct 425 ms 97028 KB n=200000
103 Correct 419 ms 96944 KB n=200000
104 Correct 421 ms 96844 KB n=200000
105 Correct 418 ms 97344 KB n=200000
106 Correct 445 ms 97404 KB n=200000
107 Correct 433 ms 97380 KB n=200000
108 Correct 805 ms 95660 KB n=200000
109 Correct 821 ms 95832 KB n=200000
110 Correct 806 ms 95812 KB n=200000
111 Correct 820 ms 94992 KB n=200000
112 Correct 650 ms 103848 KB n=200000
113 Correct 946 ms 99844 KB n=200000
114 Correct 705 ms 94972 KB n=200000
115 Correct 1126 ms 97648 KB n=200000
116 Correct 676 ms 95764 KB n=200000
117 Correct 554 ms 103904 KB n=200000
118 Correct 988 ms 98560 KB n=200000
119 Correct 659 ms 95624 KB n=200000
120 Correct 471 ms 103392 KB n=200000
121 Correct 454 ms 103376 KB n=200000
122 Correct 454 ms 103628 KB n=200000
123 Correct 476 ms 97056 KB n=200000
124 Correct 158 ms 41492 KB n=25264