이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define ft first
#define sc second
using namespace std;
const int mod=1e9+7,INF=1e17;
vector<int> v[200005];
int tin[200005],tout[200005],a[200005],cnt=1,up[200005][20];
set<pair<int,int>> s[200005];
void dfs(int x,int p){
tin[x]=cnt++;
up[x][0]=p;
for(int i=1;i<20;i++){
up[x][i]=up[up[x][i-1]][i-1];
}
for(auto w : v[x]){
if(w==p){
continue;
}
else{
dfs(w,x);
}
}
tout[x]=cnt++;
}
bool is_up(int x,int y){
return tin[x]<=tin[y] && tout[x]>=tout[y];
}
int lca(int x,int y){
if(is_up(x,y)){
return x;
}
if(is_up(y,x)){
return y;
}
for(int i=19;i>=0;i--){
if(!is_up(up[x][i],y)){
x=up[x][i];
}
}
return up[x][0];
}
main(){
int n,m,q,x1,y1;
cin >> n >> m >> q;
for(int i=1;i<n;i++){
cin >> x1 >> y1;
v[x1].push_back(y1);
v[y1].push_back(x1);
}
dfs(1,1);
for(int i=1;i<=m;i++){
cin >> a[i];
if(i>1){
int lc=lca(a[i],a[i-1]);
s[lc].insert({i-1,i});
}
s[a[i]].insert({i,i});
}
while(q--){
int type;
cin >> type;
if(type==2){
int l,r,ver;
cin >> l >> r >> ver;
auto it=s[ver].lower_bound({l,0});
if(it == s[ver].end() || it->sc > r){
cout << "-1 -1" << endl;
}
else{
cout << it->ft << " " << it->sc << endl;
}
}
else{
int pos,val;
cin >> pos >> val;
s[a[pos]].erase({pos,pos});
if (pos > 1){
int lc = lca(a[pos],a[pos-1]);
s[lc].erase({pos-1,pos});
}
if (pos < m){
int lc = lca(a[pos],a[pos+1]);
s[lc].erase({pos,pos+1});
}
a[pos] = val;
s[a[pos]].insert({pos,pos});
if (pos > 1){
int lc = lca(a[pos],a[pos-1]);
s[lc].insert({pos-1,pos});
}
if (pos < m){
int lc = lca(a[pos],a[pos+1]);
s[lc].insert({pos,pos+1});
}
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
treearray.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
49 | main(){
| ^~~~
# | 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... |