이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
// #include "chrono"
using namespace std;
// using namespace std::chrono;
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define pb push_back
#define galen_colin {ios_base::sync_with_stdio(false);}
#define orz {cin.tie(NULL); cout.tie(NULL);}
#define fix(prec) {cout << setprecision(prec) << fixed;}
#define mp make_pair
#define f first
#define s second
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
cout << ""; for(int i = 0; i < v.size(); i++) {if (i) cout << " "; cout << v[i];} return cout << "\n";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
cin >> p.first;
return cin >> p.second;
}
template<typename A> istream& operator>>(istream& cin, vector<A> &v) {
for(auto &x:v)cin>>x;
return cin;
}
ll min(ll a, int b){return min(a, (ll) b);}
ll min(int a, ll b){return min(b, (ll) a);}
ll max(ll a, int b){return max(a, (ll) b);}
ll max(int a, ll b){return max(b, (ll) a);}
void usaco(string filename) {
// #pragma message("be careful, freopen may be wrong")
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
const ld pi = 3.14159265358979323846;
const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;
const ll INF = 1e9+7;
ll n, m, k, q, l, r, x, y, z;
const ll sz = 2e5 + 1;
string s, t;
const int maxk = 20;
// int up[maxk][sz];
// int timer = 0;
// int tin[sz], tout[sz];
// vi adj[sz];
// void pre(int u, int v){
// tin[u] = timer++;
// up[0][u] = v;
// for(int i=1;i<maxk;i++){
// up[i][u] = up[i-1][up[i-1][u]];
// }
// for(int i:adj[u]){
// if(i!=v){
// pre(i, u);
// }
// }
// tout[u] = timer++;
// }
// bool isancestor(int x, int y){//ask x is ancestor of y ?
// if(tin[y] > tin[x] && tout[y] < tout[x]) return true;
// return false;
// }
// int lca(int u, int v){
// if(u == -1)return v;
// if(v == -1)return u;
// if(isancestor(u, v))return u;
// if(isancestor(v, u))return v;
// for(int i = maxk-1;i >= 0;i--){
// if(isancestor(up[u][i], y))continue;
// u = up[u][i];
// }
// return up[u][0];
// }
vvi up(sz, vi(maxk, -1));
vi adj[sz];
int timer = 0;
vi tin(sz), tout(sz);
void pre(int node, int par){ tin[node] = timer++; up[node][0] = par; for(int i=1;i<maxk;i++){ int p = up[node][i-1]; up[node][i] = up[p][i-1]; } for(int i:adj[node]){ if(i != par){ pre(i, node); } } tout[node] = timer++;}bool isancestor(int u,int v){ return tin[u] <= tin[v] && tout[u] >= tout[v];}int lca(int u, int v){ if(isancestor(u, v))return u; if(isancestor(v, u))return v; for(int i = maxk-1;i >= 0; i--){ if(!isancestor(up[u][i], v)){ u = up[u][i]; } } return up[u][0];}
set<pair<int,int>> ans [sz];
void solve(int tc = 0) {
cin>>n>>m>>q;
for(int i=0;i<n-1;i++){
int u, v;
cin>>u>>v;
u--, v--;
adj[u].pb(v);
adj[v].pb(u);
}
pre(0,0);
vi a(m);
for(int i=0;i<m;i++){
cin>>a[i];
a[i]--;
}
for(int i=0;i<m;i++){
ans[a[i]].insert({0,i});
if(i!=m-1)ans[lca(a[i], a[i+1])].insert({1, i});
}
for(int i=0;i<q;i++){
cin>>x;
if(x == 1){
cin>>x>>y;
x--;
if(x!=m-1){
int o = lca(a[x], a[x+1]);
ans[o].erase(ans[o].find({1, x}));
}
if(x!=0){
int o = lca(a[x], a[x-1]);
ans[o].erase(ans[o].find({1, x-1}));
}
ans[a[x]].erase(ans[a[x]].find({0,x}));
a[x] = y-1;
if(x!=m-1)
ans[lca(a[x], a[x+1])].insert({1, x});
if(x!=0)
ans[lca(a[x], a[x-1])].insert({1, x-1});
ans[a[x]].insert({0,x});
} else {
int v;
cin>>x>>y>>v;
x--, y--, v--;
auto itr = ans[v].lower_bound({0,x});
if(itr != ans[v].end()){
if( (*itr).f == 0 && (*itr).s <= y){
cout << (*itr).s+1 << " " << (*itr).s+1 << "\n";
continue;
}
}
y--;
itr = ans[v].lower_bound({1, x});
if(itr != ans[v].end()){
if( (*itr).s <= y){
cout<< (*itr).s+1 << " " << (*itr).s+2 << "\n";
continue;
}
}
cout<<"-1 -1\n";
}
}
}
int main() {
#ifdef HACKX
// auto begin = std::chrono::high_resolution_clock::now();
#endif
galen_colin orz
// usaco("cowland");
int tc = 1;
// cin >> tc;
for (int t = 0; t < tc; t++) solve(t);
#ifdef HACKX
// auto end = std::chrono::high_resolution_clock::now();
// cout << setprecision(4) << fixed;
// cout << "Execution time: " << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() << " seconds" << endl;
#endif
}
컴파일 시 표준 에러 (stderr) 메시지
treearray.cpp: In function 'void solve(int)':
treearray.cpp:167:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
167 | if(x!=0)
| ^~
treearray.cpp:170:17: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
170 | ans[a[x]].insert({0,x});
| ^~~
treearray.cpp: In function 'void usaco(std::string)':
treearray.cpp:56:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
56 | freopen((filename + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:57:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
57 | freopen((filename + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |