이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* LES GREATEABLES BRO TEAM
**/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define sz(x) (int)x.size()
const bool FLAG = false;
void setIO(const string &f = "");
string to_string(const string s) {
return '"' + s + '"';
}
string to_string(const char c) {
return char(39) + string(1, c) + char(39);
}
string to_string(const char* s) {
return to_string(string(s));
}
string to_string(bool f) {
return (f ? "true" : "false");
}
template<class A, class B>
string to_string(const pair<A, B> x) {
return "(" + to_string(x.first) + ", " + to_string(x.second) + ")";
}
template<class A, class B, class C>
string to_string(const tuple<A, B, C> x) {
return "(" + to_string(get<0>(x)) + ", " + to_string(get<1>(x)) + ", " + to_string(get<2>(x)) + ")";
}
template<class A, class B, class C, class D>
string to_string(const tuple<A, B, C, D> x) {
return "(" + to_string(get<0>(x)) + ", " + to_string(get<1>(x)) + ", " + to_string(get<2>(x)) + ", " + to_string(get<3>(x)) + ")";
}
template<class T>
string to_string(const T v) {
string res = "{"; bool f = true;
for (auto x: v)
res += (f ? to_string(x) : ", " + to_string(x)), f = false;
return res + "}";
}
void debug_args() { cerr << "]\n"; }
template<class H, class... T>
void debug_args(H x, T... y) {
cerr << to_string(x);
if (sizeof... (y))
cerr << ", ";
debug_args(y...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: [", debug_args(__VA_ARGS__);
#else
#define debug(...) 47
#endif
const int N = 3e3 + 14;
struct New {
int v, l, r, i;
};
int n, m, q, level[N], up[15][N];
vector<vector<int>> g(N);
void dfs(int v, int pr) {
level[v] = level[pr] + 1;
up[0][v] = pr;
for (int i = 1; i <= 12; i++)
up[i][v] = up[i - 1][up[i - 1][v]];
for (int to: g[v]) {
if (to == pr)
continue;
dfs(to, v);
}
}
int lca(int x, int y) {
if (level[x] > level[y])
swap(x, y);
for (int i = 12; i >= 0; i--) {
if (level[up[i][y]] >= level[x])
y = up[i][y];
}
if (x == y)
return x;
for (int i = 12; i >= 0; i--) {
if (up[i][x] != up[i][y])
x = up[i][x], y = up[i][y];
}
return up[0][x];
}
int not_lca(int x, int y) {
if (level[x] > level[y])
swap(x, y);
for (int i = 12; i >= 0; i--) {
if (level[up[i][y]] > level[x])
y = up[i][y];
}
if (up[0][y] == x)
return y;
return -1;
}
void solve() {
cin >> n >> m >> q;
for (int i = 1, x, y; i < n; i++) {
cin >> x >> y;
g[x].push_back(y), g[y].push_back(x);
}
dfs(1, 0);
debug(n, m, q);
vector<int> a(m + 1), l(m + 1), r(m + 1);
for (int i = 1; i <= m; i++)
cin >> a[i];
for (int i = 1; i <= m; i++) {
l[i] = r[i] = i;
for (int j = 1; i - j >= 1; j++) {
if (level[a[i]] < level[a[i - j]] && up[0][not_lca(a[i], a[i - j])] == a[i])
l[i]--;
else
break;
}
for (int j = 1; j + i <= m; j++) {
if (level[a[i]] < level[a[i + j]] && up[0][not_lca(a[i], a[i + j])] == a[i])
r[i]++;
else
break;
}
}
debug(a);
while (q--) {
int type;
cin >> type;
if (type == 1) {
int pos, v;
cin >> pos >> v;
a[pos] = v;
l[pos] = r[pos] = 1;
for (int j = 1; pos - j >= 1; j++) {
if (level[a[pos]] < level[a[pos - j]] && up[0][not_lca(a[pos], a[pos - j])] == a[pos])
l[pos]--;
else
break;
}
for (int j = 1; pos + j <= m; j++) {
if (level[a[pos]] < level[a[pos + j]] && up[0][not_lca(a[pos], a[pos + j])] == a[pos])
r[pos]++;
else
break;
}
} else {
int left, right, v;
cin >> left >> right >> v;
bool cont = false;
vector<New> kerek;
for (int i = left; i <= right; i++) {
if (a[i] == v) {
cout << i << ' ' << i << '\n';
cont = true;
break;
}
if (level[v] < level[a[i]] && up[0][not_lca(v, a[i])] == v) {
kerek.push_back({not_lca(v, a[i]), l[i], r[i], i});
}
}
if (cont)
continue;
for (int i = 0; i < sz(kerek) - 1; i++) {
if (kerek[i].v != kerek[i + 1].v && kerek[i].r + 1 <= kerek[i + 1].l) {
cout << kerek[i].i << ' ' << kerek[i + 1].i << '\n';
cont = true;
break;
}
}
if (cont)
continue;
cout << "-1 -1\n";
}
}
}
signed main() {
setIO();
int tt = 1;
if (FLAG) {
cin >> tt;
}
while (tt--) {
solve();
}
return 0;
}
void setIO(const string &f) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen((f + ".in").c_str(), "r")) {
freopen((f + ".in").c_str(), "r", stdin);
freopen((f + ".out").c_str(), "w", stdout);
}
}
컴파일 시 표준 에러 (stderr) 메시지
treearray.cpp: In function 'void solve()':
treearray.cpp:57:20: warning: statement has no effect [-Wunused-value]
57 | #define debug(...) 47
| ^~
treearray.cpp:114:2: note: in expansion of macro 'debug'
114 | debug(n, m, q);
| ^~~~~
treearray.cpp:57:20: warning: statement has no effect [-Wunused-value]
57 | #define debug(...) 47
| ^~
treearray.cpp:134:5: note: in expansion of macro 'debug'
134 | debug(a);
| ^~~~~
treearray.cpp: In function 'void setIO(const string&)':
treearray.cpp:207:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
207 | freopen((f + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:208:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
208 | freopen((f + ".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... |