# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
84465 | inom | Birthday gift (IZhO18_treearray) | C++14 | 1516 ms | 263168 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma warning(disable : 4996)
const int N = 2 * 1e5 + 10;
int n, m, q;
int node[N];
vector<int> verr[N];
int l = 1, timer = 1;
int tin[N], tout[N];
int up[N][20];
set<int> lca[N], pos[N];
void dfs(int x, int pr = 1) {
tin[x] = timer; timer++;
up[x][0] = pr;
for (int i = 1; i <= l; i++) {
up[x][i] = up[up[x][i - 1]][i - 1];
}
for (auto i: verr[x]) {
if (i != pr) {
dfs(i, x);
}
}
tout[x] = timer; timer++;
}
bool upper(int x, int y) {
return tin[x] <= tin[y] && tout[x] >= tout[y];
}
int get_lca(int x, int y) {
if (upper(x, y)) {
return x;
}
else if (upper(y, x)) {
return y;
}
else {
for (int i = l; i >= 0; i--) {
if (!upper(up[x][i], y)) {
x = up[x][i];
}
}
return up[x][0];
}
}
int main() {
ios_base::sync_with_stdio(false);
scanf("%d %d %d", &n, &m, &q);
for (int i = 1; i <= n - 1; i++) {
int x, y;
scanf("%d %d", &x, &y);
verr[x].pb(y); verr[y].pb(x);
}
for (int i = 1; i <= n; i++) {
lca[i].insert(m + 1); pos[i].insert(m + 1);
}
while ((1<<l) <= n) {
l++;
}
dfs(1);
for (int i = 1; i <= m; i++) {
scanf("%d", &node[i]);
pos[node[i]].insert(i);
if (i > 1) {
int x = get_lca(node[i], node[i - 1]);
lca[x].insert(i - 1);
}
}
for (int i = 1; i <= q; i++) {
int t;
scanf("%d", &t);
if (t == 1) {
int x, y;
scanf("%d %d", &x, &y);
pos[node[x]].erase(x);
if (x > 1) {
int cur = get_lca(node[x], node[x - 1]);
lca[cur].erase(x - 1);
}
if (x + 1 <= n) {
int cur = get_lca(node[x], node[x + 1]);
lca[cur].erase(x);
}
node[x] = y;
pos[node[x]].insert(x);
if (x > 1) {
int cur = get_lca(node[x], node[x - 1]);
lca[cur].insert(x - 1);
}
if (x + 1 <= n) {
int cur = get_lca(node[x], node[x + 1]);
lca[cur].insert(x);
}
}
else {
int l, r, v;
scanf("%d %d %d", &l, &r, &v);
auto f = pos[v].lower_bound(l), s = lca[v].lower_bound(l);
if (f != pos[v].end() && *f <= r) {
printf("%d %d\n", *f, *f);
}
else if (s != lca[v].end() && *s + 1 <= r) {
printf("%d %d\n", *s, *s + 1);
}
else {
printf("-1 -1\n");
}
}
}
return 0;
}
컴파일 시 표준 에러 (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... |