답안 #523398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
523398 2022-02-07T15:20:01 Z Kalashnikov Birthday gift (IZhO18_treearray) C++17
100 / 100
950 ms 83536 KB
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
 
using namespace std;
using ll = long long;
 
const int N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7 , P = 6547;

int a[N];
vector<int> g[N];
int tin[N] , tout[N] , timer;
int up[N][20];

void dfs(int v = 1, int p = 0) {
	up[v][0] = p;
	for(int i = 1; i < 20; i ++) {
		up[v][i] = up[up[v][i-1]][i-1];
	}
	tin[v] = ++timer;
	
	for(auto to: g[v]) {
		if(to != p) {
			dfs(to , v);
		}
	}
	tout[v] = ++timer;
}

bool upper(int a , int b) {
	return tin[a] <= tin[b] && tout[a] >= tout[b];
}

int lca(int a , int b) {
	if(upper(a , b)) return a;
	if(upper(b , a)) return b;
	
	for(int i = 19; i >= 0; i --) {
		if(up[a][i] && !upper(up[a][i] , b)) {
			a = up[a][i];
		}
	}
	
	return up[a][0];
}
set<int> st1[N];
set<int> st2[N];

void solve(int tc) {
	int n , m , q;
	cin >> n >> m >> q;
	for(int i = 1; i < n; i ++) {
		int a , b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs();
	
	for(int i = 1; i <= m; i ++) {
		cin >> a[i];
		st1[a[i]].insert(i);
	}
	for(int i = 1; i < m; i ++) {
		st2[lca(a[i] , a[i+1])].insert(i);
	}
	
	while(q --) {
		int t;
		cin >> t;
		if(t == 2) {
			int l , r , v;
			cin >> l >> r >> v;
			int fnd = 0;	
			auto it = st1[v].lower_bound(l);
			if(it != st1[v].end() && *it <= r) {
				fnd = 1;
				cout << *it << ' ' << *it << '\n';
			}
			if(fnd == 0) {
				auto it = st2[v].lower_bound(l);
				if(it != st2[v].end() && *it < r) {
					fnd = 1;
					cout << *it << ' ' << *it+1 << '\n';
				}
				else {
					cout << "-1 -1\n";
				}
			}
		}
		else {
			int pos , val;
			cin >> pos >> val;
			st1[a[pos]].erase(pos);
			if(pos != 1)
				st2[lca(a[pos-1] , a[pos])].erase(pos-1);
			if(pos != m)
				st2[lca(a[pos+1] , a[pos])].erase(pos);

			a[pos] = val;
			st1[a[pos]].insert(pos);
			if(pos != 1)
				st2[lca(a[pos-1] , a[pos])].insert(pos-1);
			if(pos != m)
				st2[lca(a[pos+1] , a[pos])].insert(pos);

		}
	}
}
/*
*/
main() {
    ios;
    int tt = 1 , tc = 0;
    // cin >> tt;
    while(tt --) {
        solve(++tc);
    }
    return 0;
}

Compilation message

treearray.cpp:117:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  117 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23800 KB n=5
2 Correct 12 ms 23764 KB n=100
3 Correct 12 ms 23756 KB n=100
4 Correct 13 ms 23872 KB n=100
5 Correct 12 ms 23724 KB n=100
6 Correct 12 ms 23756 KB n=100
7 Correct 12 ms 23756 KB n=100
8 Correct 16 ms 23756 KB n=100
9 Correct 13 ms 23756 KB n=100
10 Correct 13 ms 23756 KB n=100
11 Correct 12 ms 23756 KB n=100
12 Correct 12 ms 23756 KB n=100
13 Correct 13 ms 23808 KB n=100
14 Correct 12 ms 23764 KB n=100
15 Correct 12 ms 23884 KB n=100
16 Correct 13 ms 23756 KB n=100
17 Correct 12 ms 23756 KB n=100
18 Correct 12 ms 23756 KB n=100
19 Correct 12 ms 23812 KB n=100
20 Correct 12 ms 23808 KB n=100
21 Correct 12 ms 23756 KB n=100
22 Correct 12 ms 23848 KB n=100
23 Correct 12 ms 23796 KB n=100
24 Correct 12 ms 23756 KB n=100
25 Correct 12 ms 23756 KB n=100
26 Correct 13 ms 23724 KB n=12
27 Correct 15 ms 23816 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23800 KB n=5
2 Correct 12 ms 23764 KB n=100
3 Correct 12 ms 23756 KB n=100
4 Correct 13 ms 23872 KB n=100
5 Correct 12 ms 23724 KB n=100
6 Correct 12 ms 23756 KB n=100
7 Correct 12 ms 23756 KB n=100
8 Correct 16 ms 23756 KB n=100
9 Correct 13 ms 23756 KB n=100
10 Correct 13 ms 23756 KB n=100
11 Correct 12 ms 23756 KB n=100
12 Correct 12 ms 23756 KB n=100
13 Correct 13 ms 23808 KB n=100
14 Correct 12 ms 23764 KB n=100
15 Correct 12 ms 23884 KB n=100
16 Correct 13 ms 23756 KB n=100
17 Correct 12 ms 23756 KB n=100
18 Correct 12 ms 23756 KB n=100
19 Correct 12 ms 23812 KB n=100
20 Correct 12 ms 23808 KB n=100
21 Correct 12 ms 23756 KB n=100
22 Correct 12 ms 23848 KB n=100
23 Correct 12 ms 23796 KB n=100
24 Correct 12 ms 23756 KB n=100
25 Correct 12 ms 23756 KB n=100
26 Correct 13 ms 23724 KB n=12
27 Correct 15 ms 23816 KB n=100
28 Correct 16 ms 23884 KB n=500
29 Correct 13 ms 23884 KB n=500
30 Correct 13 ms 23884 KB n=500
31 Correct 13 ms 23852 KB n=500
32 Correct 13 ms 23884 KB n=500
33 Correct 14 ms 23884 KB n=500
34 Correct 13 ms 23948 KB n=500
35 Correct 14 ms 24012 KB n=500
36 Correct 14 ms 23884 KB n=500
37 Correct 13 ms 24056 KB n=500
38 Correct 13 ms 23908 KB n=500
39 Correct 12 ms 23952 KB n=500
40 Correct 12 ms 23948 KB n=500
41 Correct 12 ms 23884 KB n=500
42 Correct 12 ms 23928 KB n=500
43 Correct 13 ms 23952 KB n=500
44 Correct 13 ms 23856 KB n=500
45 Correct 13 ms 23884 KB n=500
46 Correct 13 ms 23884 KB n=500
47 Correct 13 ms 23968 KB n=500
48 Correct 14 ms 23884 KB n=500
49 Correct 13 ms 23948 KB n=500
50 Correct 12 ms 23932 KB n=500
51 Correct 13 ms 23884 KB n=500
52 Correct 13 ms 23856 KB n=500
53 Correct 13 ms 23884 KB n=500
54 Correct 13 ms 24012 KB n=500
55 Correct 16 ms 23812 KB n=278
56 Correct 14 ms 23840 KB n=500
57 Correct 13 ms 23860 KB n=500
58 Correct 13 ms 23884 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23800 KB n=5
2 Correct 12 ms 23764 KB n=100
3 Correct 12 ms 23756 KB n=100
4 Correct 13 ms 23872 KB n=100
5 Correct 12 ms 23724 KB n=100
6 Correct 12 ms 23756 KB n=100
7 Correct 12 ms 23756 KB n=100
8 Correct 16 ms 23756 KB n=100
9 Correct 13 ms 23756 KB n=100
10 Correct 13 ms 23756 KB n=100
11 Correct 12 ms 23756 KB n=100
12 Correct 12 ms 23756 KB n=100
13 Correct 13 ms 23808 KB n=100
14 Correct 12 ms 23764 KB n=100
15 Correct 12 ms 23884 KB n=100
16 Correct 13 ms 23756 KB n=100
17 Correct 12 ms 23756 KB n=100
18 Correct 12 ms 23756 KB n=100
19 Correct 12 ms 23812 KB n=100
20 Correct 12 ms 23808 KB n=100
21 Correct 12 ms 23756 KB n=100
22 Correct 12 ms 23848 KB n=100
23 Correct 12 ms 23796 KB n=100
24 Correct 12 ms 23756 KB n=100
25 Correct 12 ms 23756 KB n=100
26 Correct 13 ms 23724 KB n=12
27 Correct 15 ms 23816 KB n=100
28 Correct 16 ms 23884 KB n=500
29 Correct 13 ms 23884 KB n=500
30 Correct 13 ms 23884 KB n=500
31 Correct 13 ms 23852 KB n=500
32 Correct 13 ms 23884 KB n=500
33 Correct 14 ms 23884 KB n=500
34 Correct 13 ms 23948 KB n=500
35 Correct 14 ms 24012 KB n=500
36 Correct 14 ms 23884 KB n=500
37 Correct 13 ms 24056 KB n=500
38 Correct 13 ms 23908 KB n=500
39 Correct 12 ms 23952 KB n=500
40 Correct 12 ms 23948 KB n=500
41 Correct 12 ms 23884 KB n=500
42 Correct 12 ms 23928 KB n=500
43 Correct 13 ms 23952 KB n=500
44 Correct 13 ms 23856 KB n=500
45 Correct 13 ms 23884 KB n=500
46 Correct 13 ms 23884 KB n=500
47 Correct 13 ms 23968 KB n=500
48 Correct 14 ms 23884 KB n=500
49 Correct 13 ms 23948 KB n=500
50 Correct 12 ms 23932 KB n=500
51 Correct 13 ms 23884 KB n=500
52 Correct 13 ms 23856 KB n=500
53 Correct 13 ms 23884 KB n=500
54 Correct 13 ms 24012 KB n=500
55 Correct 16 ms 23812 KB n=278
56 Correct 14 ms 23840 KB n=500
57 Correct 13 ms 23860 KB n=500
58 Correct 13 ms 23884 KB n=500
59 Correct 16 ms 24324 KB n=2000
60 Correct 15 ms 24396 KB n=2000
61 Correct 14 ms 24332 KB n=2000
62 Correct 15 ms 24272 KB n=2000
63 Correct 20 ms 24268 KB n=2000
64 Correct 16 ms 24328 KB n=2000
65 Correct 15 ms 24268 KB n=2000
66 Correct 15 ms 24284 KB n=2000
67 Correct 16 ms 24268 KB n=2000
68 Correct 15 ms 24268 KB n=2000
69 Correct 15 ms 24312 KB n=2000
70 Correct 15 ms 24252 KB n=2000
71 Correct 15 ms 24300 KB n=2000
72 Correct 14 ms 24268 KB n=2000
73 Correct 15 ms 24256 KB n=2000
74 Correct 15 ms 24268 KB n=1844
75 Correct 14 ms 24268 KB n=2000
76 Correct 17 ms 24204 KB n=2000
77 Correct 17 ms 24268 KB n=2000
78 Correct 16 ms 24268 KB n=2000
79 Correct 16 ms 24328 KB n=2000
80 Correct 16 ms 24336 KB n=2000
81 Correct 15 ms 24320 KB n=2000
82 Correct 15 ms 24208 KB n=2000
83 Correct 18 ms 24328 KB n=2000
84 Correct 17 ms 24268 KB n=2000
85 Correct 15 ms 24336 KB n=2000
86 Correct 16 ms 24348 KB n=2000
87 Correct 15 ms 24296 KB n=2000
88 Correct 15 ms 24352 KB n=2000
89 Correct 15 ms 24336 KB n=2000
90 Correct 14 ms 24396 KB n=2000
91 Correct 15 ms 24268 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23800 KB n=5
2 Correct 12 ms 23764 KB n=100
3 Correct 12 ms 23756 KB n=100
4 Correct 13 ms 23872 KB n=100
5 Correct 12 ms 23724 KB n=100
6 Correct 12 ms 23756 KB n=100
7 Correct 12 ms 23756 KB n=100
8 Correct 16 ms 23756 KB n=100
9 Correct 13 ms 23756 KB n=100
10 Correct 13 ms 23756 KB n=100
11 Correct 12 ms 23756 KB n=100
12 Correct 12 ms 23756 KB n=100
13 Correct 13 ms 23808 KB n=100
14 Correct 12 ms 23764 KB n=100
15 Correct 12 ms 23884 KB n=100
16 Correct 13 ms 23756 KB n=100
17 Correct 12 ms 23756 KB n=100
18 Correct 12 ms 23756 KB n=100
19 Correct 12 ms 23812 KB n=100
20 Correct 12 ms 23808 KB n=100
21 Correct 12 ms 23756 KB n=100
22 Correct 12 ms 23848 KB n=100
23 Correct 12 ms 23796 KB n=100
24 Correct 12 ms 23756 KB n=100
25 Correct 12 ms 23756 KB n=100
26 Correct 13 ms 23724 KB n=12
27 Correct 15 ms 23816 KB n=100
28 Correct 16 ms 23884 KB n=500
29 Correct 13 ms 23884 KB n=500
30 Correct 13 ms 23884 KB n=500
31 Correct 13 ms 23852 KB n=500
32 Correct 13 ms 23884 KB n=500
33 Correct 14 ms 23884 KB n=500
34 Correct 13 ms 23948 KB n=500
35 Correct 14 ms 24012 KB n=500
36 Correct 14 ms 23884 KB n=500
37 Correct 13 ms 24056 KB n=500
38 Correct 13 ms 23908 KB n=500
39 Correct 12 ms 23952 KB n=500
40 Correct 12 ms 23948 KB n=500
41 Correct 12 ms 23884 KB n=500
42 Correct 12 ms 23928 KB n=500
43 Correct 13 ms 23952 KB n=500
44 Correct 13 ms 23856 KB n=500
45 Correct 13 ms 23884 KB n=500
46 Correct 13 ms 23884 KB n=500
47 Correct 13 ms 23968 KB n=500
48 Correct 14 ms 23884 KB n=500
49 Correct 13 ms 23948 KB n=500
50 Correct 12 ms 23932 KB n=500
51 Correct 13 ms 23884 KB n=500
52 Correct 13 ms 23856 KB n=500
53 Correct 13 ms 23884 KB n=500
54 Correct 13 ms 24012 KB n=500
55 Correct 16 ms 23812 KB n=278
56 Correct 14 ms 23840 KB n=500
57 Correct 13 ms 23860 KB n=500
58 Correct 13 ms 23884 KB n=500
59 Correct 16 ms 24324 KB n=2000
60 Correct 15 ms 24396 KB n=2000
61 Correct 14 ms 24332 KB n=2000
62 Correct 15 ms 24272 KB n=2000
63 Correct 20 ms 24268 KB n=2000
64 Correct 16 ms 24328 KB n=2000
65 Correct 15 ms 24268 KB n=2000
66 Correct 15 ms 24284 KB n=2000
67 Correct 16 ms 24268 KB n=2000
68 Correct 15 ms 24268 KB n=2000
69 Correct 15 ms 24312 KB n=2000
70 Correct 15 ms 24252 KB n=2000
71 Correct 15 ms 24300 KB n=2000
72 Correct 14 ms 24268 KB n=2000
73 Correct 15 ms 24256 KB n=2000
74 Correct 15 ms 24268 KB n=1844
75 Correct 14 ms 24268 KB n=2000
76 Correct 17 ms 24204 KB n=2000
77 Correct 17 ms 24268 KB n=2000
78 Correct 16 ms 24268 KB n=2000
79 Correct 16 ms 24328 KB n=2000
80 Correct 16 ms 24336 KB n=2000
81 Correct 15 ms 24320 KB n=2000
82 Correct 15 ms 24208 KB n=2000
83 Correct 18 ms 24328 KB n=2000
84 Correct 17 ms 24268 KB n=2000
85 Correct 15 ms 24336 KB n=2000
86 Correct 16 ms 24348 KB n=2000
87 Correct 15 ms 24296 KB n=2000
88 Correct 15 ms 24352 KB n=2000
89 Correct 15 ms 24336 KB n=2000
90 Correct 14 ms 24396 KB n=2000
91 Correct 15 ms 24268 KB n=2000
92 Correct 637 ms 69724 KB n=200000
93 Correct 753 ms 77552 KB n=200000
94 Correct 556 ms 83276 KB n=200000
95 Correct 649 ms 75068 KB n=200000
96 Correct 544 ms 75116 KB n=200000
97 Correct 825 ms 79044 KB n=200000
98 Correct 630 ms 75092 KB n=200000
99 Correct 676 ms 75536 KB n=200000
100 Correct 585 ms 75328 KB n=200000
101 Correct 500 ms 83536 KB n=200000
102 Correct 392 ms 76084 KB n=200000
103 Correct 412 ms 75704 KB n=200000
104 Correct 405 ms 75332 KB n=200000
105 Correct 380 ms 74768 KB n=200000
106 Correct 374 ms 74528 KB n=200000
107 Correct 387 ms 74196 KB n=200000
108 Correct 624 ms 73004 KB n=200000
109 Correct 647 ms 72716 KB n=200000
110 Correct 656 ms 72524 KB n=200000
111 Correct 569 ms 72380 KB n=200000
112 Correct 512 ms 79084 KB n=200000
113 Correct 783 ms 74732 KB n=200000
114 Correct 553 ms 71672 KB n=200000
115 Correct 950 ms 72268 KB n=200000
116 Correct 572 ms 71040 KB n=200000
117 Correct 527 ms 78376 KB n=200000
118 Correct 843 ms 72528 KB n=200000
119 Correct 563 ms 70756 KB n=200000
120 Correct 467 ms 78176 KB n=200000
121 Correct 523 ms 78148 KB n=200000
122 Correct 447 ms 78404 KB n=200000
123 Correct 409 ms 70128 KB n=200000
124 Correct 152 ms 38068 KB n=25264