# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
89727 | mirbek01 | Birthday gift (IZhO18_treearray) | C++17 | 2375 ms | 79308 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
int n, m, q, a[N];
int p[20][N], tin[N], tout[N], timer;
vector <int> g[N];
set <int> s[N], ps[N];
set <int> :: iterator it;
void dfs(int v, int pr = 0){
tin[v] = ++ timer;
p[0][v] = pr;
for(int i = 1; i <= 19; i ++)
p[i][v] = p[i - 1][ p[i - 1][v] ];
for(int to : g[v]){
if(to == pr)
continue;
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(p[i][a] && !upper(p[i][a], b))
a = p[i][a];
}
return p[0][a];
}
int main(){
scanf("%d %d %d", &n, &m, &q);
for(int i = 1; i < n; i ++){
int u, v;
scanf("%d %d", &u, &v);
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1);
for(int i = 1; i <= m; i ++){
scanf("%d", a + i);
if(i > 1){
int lc = lca(a[i - 1], a[i]);
s[lc].insert(i - 1);
}
ps[a[i]].insert(i);
}
while(q --){
int l, r, v, type;
scanf("%d", &type);
scanf("%d %d", &l, &r);
if(type == 1){
ps[ a[l] ].erase(l);
ps[ r ].insert(l);
if(l + 1 <= m){
int lc = lca(a[l], a[l + 1]);
s[lc].erase(l);
lc = lca(r, a[l + 1]);
s[lc].insert(l);
}
if(l - 1 >= 1){
int lc = lca(a[l], a[l - 1]);
s[lc].erase(l - 1);
lc = lca(r, a[l - 1]);
s[lc].insert(l - 1);
}
a[l] = r;
} else {
scanf("%d", &v);
if(l == r){
if(a[l] == v){
cout << l << " " << l << endl;
} else {
puts("-1 -1");
}
} else {
if(!ps[v].empty()){
it = ps[v].lower_bound(l);
if(it != ps[v].end() && (*it) <= r){
cout << (*it) << " " << (*it) << endl;
continue;
}
}
if(s[v].empty()){
puts("-1 -1");
continue;
}
it = s[v].lower_bound(l);
if(it == s[v].end() || (*it) >= r){
puts("-1 -1");
continue;
}
cout << *it << " " << (*it) + 1 << endl;
}
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |